ProcessFiles_UnitTests.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using NSubstitute;
  2. using ProcessFiles.Interfaces;
  3. using Xunit;
  4. using Xunit.Sdk;
  5. namespace ProcessFilesTests
  6. {
  7. public class ProcessFiles_UnitTests
  8. {
  9. [Fact]
  10. public void ProcessFileNotExistTest()
  11. {
  12. var result = string.Empty;
  13. void TestAction(string value)
  14. {
  15. result = value;
  16. }
  17. var fakeFileSystem = Substitute.For<IFileSystem>();
  18. fakeFileSystem.File.Exists(Arg.Any<string>()).Returns(false);
  19. var test = new ProcessFiles.ProcessFiles(fakeFileSystem);
  20. var errors = test.Process(["./imaginaryFolder/imaginaryTest.txt"], "txt", TestAction);
  21. Assert.NotEmpty(errors);
  22. Assert.Empty(result);
  23. fakeFileSystem.File.Received().Exists(Arg.Any<string>());
  24. }
  25. [Fact]
  26. public void ProcessFileNotMatchExtensionTest()
  27. {
  28. var result = string.Empty;
  29. void TestAction(string value)
  30. {
  31. result = value;
  32. }
  33. var fakeFileSystem = Substitute.For<IFileSystem>();
  34. fakeFileSystem.File.Exists(Arg.Any<string>()).Returns(true);
  35. fakeFileSystem.Path.GetExtension(Arg.Any<string>()).Returns(string.Empty);
  36. var test = new ProcessFiles.ProcessFiles(fakeFileSystem);
  37. var errors = test.Process(["imaginaryNoExtension"], "abc", TestAction);
  38. Assert.NotEmpty(errors);
  39. Assert.Empty(result);
  40. fakeFileSystem.File.Received().Exists(Arg.Any<string>());
  41. fakeFileSystem.Path.Received().GetExtension(Arg.Any<string>());
  42. }
  43. }
  44. }