Ejemplo n.º 1
0
        public void ReadsFiles(TestFileData testFileData)
        {
            using var testEnvironmentProvider = CreateTestEnvironmentProvider();
            var getTestFilePath = SetupTestEnvironment(testEnvironmentProvider.RootDirectory);

            AssertThatFileContains(getTestFilePath(testFileData.Name), testFileData.Content);
        }
        public void WritingOnExistingFileOverwritesContents(TestFileData testFileData)
        {
            var builder = new FileOpeningBuilder()
                          .Write(true);

            AssertThatFileContainsWrittenContent(builder, testFileData, ContentToWrite);
        }
 public void ReadsFiles(TestFileData testFileData)
 {
     var(testEnvironmentDisposable, getTestFilePath) = SetupTestEnvironment();
     using (testEnvironmentDisposable)
     {
         AssertThatFileContains(getTestFilePath(testFileData.Name), testFileData.Content);
     }
 }
        public void WritingToFileWithCreateAndWriteOverwritesFile(TestFileData testFileData)
        {
            var builder = new FileOpeningBuilder()
                          .Write(true)
                          .Create(true);

            AssertThatFileContainsWrittenContent(builder, testFileData, ContentToWrite);
        }
Ejemplo n.º 5
0
        public void ReadsWritableFiles(TestFileData testFileData)
        {
            using var testEnvironmentProvider = CreateTestEnvironmentProvider();
            var getTestFilePath = SetupTestEnvironment(testEnvironmentProvider.RootDirectory);
            var builder         = new FileOpeningBuilder()
                                  .Read(true)
                                  .Write(true);

            AssertThatFileContains(builder, getTestFilePath(testFileData.Name), testFileData.Content);
        }
 public void ReadsWritableFiles(TestFileData testFileData)
 {
     var(testEnvironmentDisposable, getTestFilePath) = SetupTestEnvironment();
     using (testEnvironmentDisposable)
     {
         var builder = new FileOpeningBuilder()
                       .Read(true)
                       .Write(true);
         AssertThatFileContains(builder, getTestFilePath(testFileData.Name), testFileData.Content);
     }
 }
Ejemplo n.º 7
0
        public void ReadsTruncatedFileDirectly(TestFileData testFileData)
        {
            using var testEnvironmentProvider = CreateTestEnvironmentProvider();
            var getTestFilePath = SetupTestEnvironment(testEnvironmentProvider.RootDirectory);
            var builder         = new FileOpeningBuilder()
                                  .Write(true)
                                  .Read(true)
                                  .Truncate(true);

            AssertThatFileContains(builder, getTestFilePath(testFileData.Name), string.Empty);
        }
 public void ReadsTruncatedFileDirectly(TestFileData testFileData)
 {
     var(testEnvironmentDisposable, getTestFilePath) = SetupTestEnvironment();
     using (testEnvironmentDisposable)
     {
         var builder = new FileOpeningBuilder()
                       .Write(true)
                       .Read(true)
                       .Truncate(true);
         AssertThatFileContains(builder, getTestFilePath(testFileData.Name), string.Empty);
     }
 }
Ejemplo n.º 9
0
        public void OpeningFileWithWriteAccessWithoutWritingDoesNotOverwriteContents(TestFileData testFileData)
        {
            using var testEnvironmentProvider = CreateTestEnvironmentProvider();
            var getTestFilePath = SetupTestEnvironment(testEnvironmentProvider.RootDirectory);

            using (new FileOpeningBuilder()
                   .Write(true)
                   .Open(getTestFilePath(testFileData.Name)))
            {
            }

            AssertThatFileContains(getTestFilePath(testFileData.Name), testFileData.Content);
        }
        public void OpeningFileWithWriteAccessWithoutWritingDoesNotOverwriteContents(TestFileData testFileData)
        {
            var(testEnvironmentDisposable, getTestFilePath) = SetupTestEnvironment();
            using (testEnvironmentDisposable)
            {
                using (new FileOpeningBuilder()
                       .Write(true)
                       .Open(getTestFilePath(testFileData.Name)))
                {
                }

                AssertThatFileContains(getTestFilePath(testFileData.Name), testFileData.Content);
            }
        }
Ejemplo n.º 11
0
        public void TruncatingFileWithoutWritingMakesItEmpty(TestFileData testFileData)
        {
            using var testEnvironmentProvider = CreateTestEnvironmentProvider();
            var getTestFilePath = SetupTestEnvironment(testEnvironmentProvider.RootDirectory);

            using (new FileOpeningBuilder()
                   .Write(true)
                   .Truncate(true)
                   .Open(getTestFilePath(testFileData.Name)))
            {
            }

            AssertThatFileContains(getTestFilePath(testFileData.Name), string.Empty);
        }
Ejemplo n.º 12
0
        public void ThrowsWhenForceCreatingExistingFile(TestFileData testFileData)
        {
            using var testEnvironmentProvider = CreateTestEnvironmentProvider();
            var getTestFilePath = SetupTestEnvironment(testEnvironmentProvider.RootDirectory);

            Assert.Throws <IOException>(() =>
            {
                using (new FileOpeningBuilder()
                       .CreateNew(true)
                       .Write(true)
                       .Open(getTestFilePath(testFileData.Name)))
                {
                }
            });
        }
        public void TruncatingFileWithoutWritingMakesItEmpty(TestFileData testFileData)
        {
            var(testEnvironmentDisposable, getTestFilePath) = SetupTestEnvironment();
            using (testEnvironmentDisposable)
            {
                using (new FileOpeningBuilder()
                       .Write(true)
                       .Truncate(true)
                       .Open(getTestFilePath(testFileData.Name)))
                {
                }

                AssertThatFileContains(getTestFilePath(testFileData.Name), string.Empty);
            }
        }
Ejemplo n.º 14
0
        public void ThrowsWhenTruncatingWithOnlyReadAccess(TestFileData testFileData)
        {
            using var testEnvironmentProvider = CreateTestEnvironmentProvider();
            var getTestFilePath = SetupTestEnvironment(testEnvironmentProvider.RootDirectory);

            Assert.Throws <InvalidOperationException>(() =>
            {
                using (new FileOpeningBuilder()
                       .Truncate(true)
                       .Read(true)
                       .Open(getTestFilePath(testFileData.Name)))
                {
                }
            });
        }
 public void ThrowsWhenTruncatingWithOnlyReadAccess(TestFileData testFileData)
 {
     var(testEnvironmentDisposable, getTestFilePath) = SetupTestEnvironment();
     using (testEnvironmentDisposable)
     {
         Assert.Throws <InvalidOperationException>(() =>
         {
             using (new FileOpeningBuilder()
                    .Truncate(true)
                    .Read(true)
                    .Open(getTestFilePath(testFileData.Name)))
             {
             }
         });
     }
 }
 public void ThrowsWhenForceCreatingExistingFile(TestFileData testFileData)
 {
     var(testEnvironmentDisposable, getTestFilePath) = SetupTestEnvironment();
     using (testEnvironmentDisposable)
     {
         Assert.Throws <IOException>(() =>
         {
             using (new FileOpeningBuilder()
                    .CreateNew(true)
                    .Write(true)
                    .Open(getTestFilePath(testFileData.Name)))
             {
             }
         });
     }
 }
        public void AppendsToExistingFile(TestFileData testFileData)
        {
            var(testEnvironmentDisposable, getTestFilePath) = SetupTestEnvironment();
            using (testEnvironmentDisposable)
            {
                using (var stream = new FileOpeningBuilder()
                                    .Append(true)
                                    .Open(getTestFilePath(testFileData.Name)))
                {
                    var bytes = System.Text.Encoding.UTF8.GetBytes(ContentToWrite);
                    stream.Write(bytes);
                }

                var expectedContent = testFileData.Content + ContentToWrite;
                AssertThatFileContains(getTestFilePath(testFileData.Name), expectedContent);
            }
        }
Ejemplo n.º 18
0
        private static void AssertThatFileContainsWrittenContent(
            IFileOpeningBuilder fileOpeningBuilder,
            TestFileData testFileData,
            string contentToWrite)
        {
            using var testEnvironementProvider = CreateTestEnvironmentProvider();
            var getTestFilePath = SetupTestEnvironment(testEnvironementProvider.RootDirectory);

            using (var stream = fileOpeningBuilder
                                .Open(getTestFilePath(testFileData.Name)))
            {
                var bytes = System.Text.Encoding.UTF8.GetBytes(contentToWrite);
                stream.Write(bytes);
            }

            AssertThatFileContains(getTestFilePath(testFileData.Name), contentToWrite);
        }
Ejemplo n.º 19
0
        public void ReadingOverwrittenFileReturnsEmptyContent(TestFileData testFileData)
        {
            using var testEnvironmentProvider = CreateTestEnvironmentProvider();
            var getTestFilePath = SetupTestEnvironment(testEnvironmentProvider.RootDirectory);

            using var stream = new FileOpeningBuilder()
                               .Read(true)
                               .Write(true)
                               .Open(getTestFilePath(testFileData.Name));
            var bytes = System.Text.Encoding.UTF8.GetBytes(ContentToWrite);

            stream.Write(bytes);

            var content = ReadStream(stream);

            Assert.Empty(content);
        }
        public void ReadingOverwrittenFileReturnsEmptyContent(TestFileData testFileData)
        {
            var(testEnvironmentDisposable, getTestFilePath) = SetupTestEnvironment();
            using (testEnvironmentDisposable)
            {
                using (var stream = new FileOpeningBuilder()
                                    .Read(true)
                                    .Write(true)
                                    .Open(getTestFilePath(testFileData.Name)))
                {
                    var bytes = System.Text.Encoding.UTF8.GetBytes(ContentToWrite);
                    stream.Write(bytes);

                    var content = ReadStream(stream);
                    Assert.Empty(content);
                }
            }
        }
        private static void AssertThatFileContainsWrittenContent(
            IFileOpeningBuilder fileOpeningBuilder,
            TestFileData testFileData,
            string contentToWrite
            )
        {
            var(testEnvironmentDisposable, getTestFilePath) = SetupTestEnvironment();
            using (testEnvironmentDisposable)
            {
                using (var stream = fileOpeningBuilder
                                    .Open(getTestFilePath(testFileData.Name)))
                {
                    var bytes = System.Text.Encoding.UTF8.GetBytes(contentToWrite);
                    stream.Write(bytes);
                }

                AssertThatFileContains(getTestFilePath(testFileData.Name), contentToWrite);
            }
        }