Unit tests to verify value returned by DirectoryInfo.Parent.ToString, both in CoreFX...
authorCarlos Sanchez Lopez <1175054+carlossanlop@users.noreply.github.com>
Tue, 22 Oct 2019 18:44:29 +0000 (11:44 -0700)
committerStephen Toub <stoub@microsoft.com>
Tue, 22 Oct 2019 18:44:29 +0000 (14:44 -0400)
Commit migrated from https://github.com/dotnet/corefx/commit/f7081cf3bac10352f4a3ac57aa4b5c0963d33e77

src/libraries/System.IO.FileSystem/tests/DirectoryInfo/ToString.cs

index 454f58b..b8d2565 100644 (file)
@@ -45,5 +45,34 @@ namespace System.IO.Tests
             var info = new DirectoryInfo(path);
             Assert.Equal(path, info.ToString());
         }
+
+        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsFullFramework))]
+        public void ParentToString_Framework()
+        {
+            ParentToString(false);
+        }
+
+        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNetCore))]
+        public void ParentToString_Core()
+        {
+            ParentToString(true);
+        }
+
+        private void ParentToString(bool compareFullName)
+        {
+            string filePath = GetTestFilePath();
+
+            string dirPath = Path.GetDirectoryName(filePath);
+            DirectoryInfo dirInfo = new DirectoryInfo(dirPath);
+
+            string parentDirPath = Path.GetDirectoryName(dirPath);
+            DirectoryInfo parentDirInfo = new DirectoryInfo(parentDirPath);
+
+            string dirInfoParentString = compareFullName ? dirInfo.Parent.FullName : dirInfo.Parent.Name;
+            string parentDirInfoString = compareFullName ? parentDirInfo.FullName : parentDirInfo.Name;
+
+            Assert.Equal(dirInfo.Parent.ToString(), dirInfoParentString);
+            Assert.Equal(dirInfo.Parent.ToString(), parentDirInfoString);
+        }
     }
 }