123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using NSubstitute;
- using ProcessFiles;
- using ProcessFiles.Interfaces;
- using Xunit;
- namespace ProcessFilesTests;
- public class ProcessFilesUnitTests
- {
- [Fact]
- public void ProcessFileNotExistTest()
- {
- var result = string.Empty;
- var fakeFileSystem = Substitute.For<IFileSystem>();
- fakeFileSystem.File.Exists(Arg.Any<string>()).Returns(false);
- var test = new FileProcessing(fakeFileSystem);
- var errors = test.Process(["./imaginaryFolder/imaginaryTest.txt"], "txt", TestAction);
- Assert.NotEmpty(errors);
- Assert.Empty(result);
- fakeFileSystem.File.Received().Exists(Arg.Any<string>());
- return;
- void TestAction(string value)
- {
- result = value;
- }
- }
- [Fact]
- public void ProcessFileNoExtensionTest()
- {
- var result = string.Empty;
- var fakeFileSystem = Substitute.For<IFileSystem>();
- fakeFileSystem.File.Exists(Arg.Any<string>()).Returns(true);
- fakeFileSystem.Path.GetExtension(Arg.Any<string>()).Returns(string.Empty);
- var test = new FileProcessing(fakeFileSystem);
- var errors = test.Process(["imaginaryNoExtension"], "abc", TestAction);
- Assert.NotEmpty(errors);
- Assert.Empty(result);
- fakeFileSystem.File.Received().Exists(Arg.Any<string>());
- fakeFileSystem.Path.Received().GetExtension(Arg.Any<string>());
- return;
- void TestAction(string value)
- {
- result = value;
- }
- }
- [Fact]
- public void ProcessFileNotMatchExtensionTest()
- {
- var result = string.Empty;
- var fakeFileSystem = Substitute.For<IFileSystem>();
- fakeFileSystem.File.Exists(Arg.Any<string>()).Returns(true);
- fakeFileSystem.Path.GetExtension(Arg.Any<string>()).Returns("def");
- var test = new FileProcessing(fakeFileSystem);
- var errors = test.Process(["imaginaryFile"], "abc", TestAction);
- Assert.NotEmpty(errors);
- Assert.Empty(result);
- fakeFileSystem.File.Received().Exists(Arg.Any<string>());
- fakeFileSystem.Path.Received().GetExtension(Arg.Any<string>());
- return;
- void TestAction(string value)
- {
- result = value;
- }
- }
- [Fact]
- public void ProcessFileTest()
- {
- var result = string.Empty;
- var fakeFileSystem = Substitute.For<IFileSystem>();
- fakeFileSystem.File.Exists(Arg.Any<string>()).Returns(true);
- fakeFileSystem.Path.GetExtension(Arg.Any<string>()).Returns("txt");
- const string expectedValue = "imaginary.txt";
- var test = new FileProcessing(fakeFileSystem);
- var errors = test.Process([expectedValue], "txt", TestAction);
- Assert.Empty(errors);
- Assert.Equal(expectedValue, result);
- fakeFileSystem.File.Received().Exists(Arg.Any<string>());
- fakeFileSystem.Path.Received().GetExtension(Arg.Any<string>());
- return;
- void TestAction(string value)
- {
- result = value;
- }
- }
- }
|