Example #1
0
 public void CreateStreamsWithDifficultNames(string fileName)
 {
     using (var cleaner = new TestFileCleaner())
     {
         FileService fileService = new FileService();
         string filePath = Paths.Combine(cleaner.TempFolder, fileName);
         using (Stream fileStream = fileService.CreateFileStream(filePath, FileMode.CreateNew))
         {
             fileStream.Should().NotBeNull();
             fileService.FileExists(filePath).Should().BeTrue();
         }
     }
 }
Example #2
0
 public void CreateStream()
 {
     using (var cleaner = new TestFileCleaner())
     {
         FileService fileService = new FileService();
         string filePath = Paths.Combine(cleaner.TempFolder, Path.GetRandomFileName());
         using (Stream fileStream = fileService.CreateFileStream(filePath, FileMode.CreateNew))
         {
             fileStream.Should().NotBeNull();
         }
     }
 }
Example #3
0
 public void OpenNonExistantStream(string appendix)
 {
     using (var cleaner = new TestFileCleaner())
     {
         FileService fileService = new FileService();
         string filePath = Paths.Combine(cleaner.TempFolder, Path.GetRandomFileName() + appendix);
         Action action = () => fileService.CreateFileStream(filePath, FileMode.Open);
         action.ShouldThrow<FileNotFoundException>();
     }
 }
Example #4
0
 public void WriteAndReadLongPathStream()
 {
     using (var cleaner = new TestFileCleaner(false))
     {
         string longPath = PathGenerator.CreatePathOfLength(cleaner.TempFolder, 300);
         FileService fileService = new FileService();
         fileService.CreateDirectory(longPath);
         string filePath = Paths.Combine(longPath, Path.GetRandomFileName());
         using (Stream fileStream = fileService.CreateFileStream(filePath, FileMode.CreateNew, FileAccess.ReadWrite))
         {
             fileStream.Should().NotBeNull();
             StreamWriter writer = new StreamWriter(fileStream);
             writer.WriteLine("This is a test string.");
             writer.Flush();
             fileStream.Position = 0;
             StreamReader reader = new StreamReader(fileStream);
             string readLine = reader.ReadLine();
             readLine.Should().Be("This is a test string.");
         }
     }
 }
Example #5
0
 public void WriteAndReadtStream(string appendix)
 {
     using (var cleaner = new TestFileCleaner())
     {
         FileService fileService = new FileService();
         string filePath = Paths.Combine(cleaner.TempFolder, Path.GetRandomFileName() + appendix);
         using (Stream fileStream = fileService.CreateFileStream(filePath, FileMode.CreateNew, FileAccess.ReadWrite))
         {
             fileStream.Should().NotBeNull();
             StreamWriter writer = new StreamWriter(fileStream);
             writer.WriteLine("This is a test string.");
             writer.Flush();
             fileStream.Position = 0;
             StreamReader reader = new StreamReader(fileStream);
             string readLine = reader.ReadLine();
             readLine.Should().Be("This is a test string.");
         }
     }
 }
Example #6
0
        public void WriteAndReadAlternateStreams()
        {
            using (var cleaner = new TestFileCleaner())
            {
                string directoryPath = Paths.Combine(cleaner.TempFolder, Path.GetRandomFileName());
                Directory.CreateDirectory(directoryPath);

                FileService fileService = new FileService();
                string filePath = Paths.Combine(directoryPath, Path.GetRandomFileName());
                using (Stream fileStream = fileService.CreateFileStream(filePath, FileMode.CreateNew, FileAccess.ReadWrite)) { }

                for (int i = 0; i < 3; i++)
                {
                    string streamPath = $"{filePath}:Stream{i}:$DATA";
                    using (Stream fileStream = fileService.CreateFileStream(streamPath, FileMode.CreateNew, FileAccess.ReadWrite))
                    {
                        string testString = $"This is test string {i}.";
                        fileStream.Should().NotBeNull();
                        StreamWriter writer = new StreamWriter(fileStream);
                        writer.WriteLine(testString);
                        writer.Flush();
                        fileStream.Position = 0;
                        StreamReader reader = new StreamReader(fileStream);
                        string readLine = reader.ReadLine();
                        readLine.Should().Be(testString);
                    }
                }

                var directoryInfo = fileService.GetPathInfo(directoryPath) as IDirectoryInformation;
                directoryInfo.Should().NotBeNull();
                directoryInfo.EnumerateChildren().Should().HaveCount(1);
            }
        }
Example #7
0
 public void CreateLongPathStream()
 {
     using (var cleaner = new TestFileCleaner(false))
     {
         string longPath = PathGenerator.CreatePathOfLength(cleaner.TempFolder, 300);
         FileService fileService = new FileService();
         fileService.CreateDirectory(longPath);
         string filePath = Paths.Combine(longPath, Path.GetRandomFileName());
         using (Stream fileStream = fileService.CreateFileStream(filePath, FileMode.CreateNew))
         {
             fileStream.Should().NotBeNull();
         }
     }
 }