Repository: dotnet/runtime
File: src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/Directory/EnumerableTests.cs (C#)

Code before:
                // Create a subdirectory directly in the root
                DirectoryInfo subDirectory = rootDirectory.CreateSubdirectory(testFolderName);

                // Verify it was created
                Assert.True(subDirectory.Exists);
                Assert.Equal(Path.Combine(rootDrive, testFolderName), subDirectory.FullName);
            }
            finally
            {
                // Cleanup
                string testFolderPath = Path.Combine(rootDrive, testFolderName);
                if (Directory.Exists(testFolderPath))
                {
                    Directory.Delete(testFolderPath, recursive: true);
                }
            }
        }

        [Fact]
        [PlatformSpecific(TestPlatforms.Linux)]
        public void CreateSubdirectory_RootDriveSubfolder_ThrowsUnauthorizedAccessException_Linux()
        {
            string rootDrive = "/";

            DirectoryInfo rootDirectory = new DirectoryInfo(rootDrive);
            string testFolderName = $"TestFolder_{Guid.NewGuid():N}";

            // Expect permission failure when trying to create directly under "/", in test envs access to / is denied,
            //but at least we know directory craeting attempt was done
            Assert.Throws<UnauthorizedAccessException>(() =>
            {
                rootDirectory.CreateSubdirectory(testFolderName);
            });
        }

        [Fact]
        public void EnumerateDirectories_NonBreakingSpace()
        {
            DirectoryInfo rootDirectory = Directory.CreateDirectory(GetTestFilePath());
            DirectoryInfo subDirectory1 = rootDirectory.CreateSubdirectory("\u00A0");
            DirectoryInfo subDirectory2 = subDirectory1.CreateSubdirectory(GetTestFileName());

            FSAssert.EqualWhenOrdered(new string[] { subDirectory1.FullName, subDirectory2.FullName }, Directory.EnumerateDirectories(rootDirectory.FullName, string.Empty, SearchOption.AllDirectories));
        }

         [Fact]
         [PlatformSpecific(TestPlatforms.Windows)]
         public void EnumerateDirectories_TrailingDot()
         {
             string prefix = @"\\?\";
             string tempPath = GetTestFilePath();

Review comment (suggestion):
```suggestion
            string testFolderName = GetTestFileName();
```

Code after:
             string tempPath = GetTestFilePath();
             string fileName = "Test.txt";

             string[] dirPaths = {
                 Path.Join(prefix, tempPath, "Test"),
                 Path.Join(prefix, tempPath, "TestDot."),
                 Path.Join(prefix, tempPath, "TestDotDot..")
             };

             // Create directories and their files using "\\?\C:\" paths
             foreach (string dirPath in dirPaths)
             {
                 if (Directory.Exists(dirPath))
                 {
                     Directory.Delete(dirPath, recursive: true);
                 }

                 Directory.CreateDirectory(dirPath);

                 // Directory.Exists should work with directories containing trailing dots and prefixed with \\?\
                 Assert.True(Directory.Exists(dirPath));

                 string filePath = Path.Join(dirPath, fileName);
                 using FileStream fs = File.Create(filePath);

                 // File.Exists should work with directories containing trailing dots and prefixed with \\?\
                 Assert.True(File.Exists(filePath));
             }

             try
             {
                 // Enumerate directories and their files using "C:\" paths
                 DirectoryInfo sourceInfo = new DirectoryInfo(tempPath);
                 foreach (DirectoryInfo dirInfo in sourceInfo.EnumerateDirectories("*", SearchOption.AllDirectories))
                 {
                     // DirectoryInfo.Exists should work with or without \\?\ for folders with trailing dots
                     Assert.True(dirInfo.Exists);

                     if (dirInfo.FullName.EndsWith("."))
                     {
                         // Directory.Exists is not expected to work with directories containing trailing dots and not prefixed with \\?\
                         Assert.False(Directory.Exists(dirInfo.FullName));
                     }

                     foreach (FileInfo fileInfo in dirInfo.EnumerateFiles("*.*", SearchOption.TopDirectoryOnly))
                     {
                         // FileInfo.Exists should work with or without \\?\ for folders with trailing dots
                         Assert.True(fileInfo.Exists);

                         if (fileInfo.Directory.FullName.EndsWith("."))
                         {