ProcessFilesTests.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using Xunit;
  5. namespace ProcessFilesTests
  6. {
  7. public class ProcessFilesTests
  8. {
  9. [Fact]
  10. public void ProcessFolderTest()
  11. {
  12. const string expected = "test1.txt";
  13. var result = string.Empty;
  14. void Callback(string value)
  15. {
  16. result = Path.GetFileName(value);
  17. }
  18. var errors = ProcessFiles.ProcessFiles.Process(new [] {"./testFiles"}, "txt", Callback);
  19. Assert.Empty(errors);
  20. Assert.Equal(expected, result);
  21. }
  22. [Fact]
  23. public void ProcessFolderRecursiveTest()
  24. {
  25. var expected = new[]
  26. {
  27. "test1.txt",
  28. "test2.txt"
  29. };
  30. var result = new List<string>();
  31. void Callback(string value)
  32. {
  33. result.Add(Path.GetFileName(value));
  34. }
  35. var errors = ProcessFiles.ProcessFiles.Process(new[] { "./testFiles" }, "txt", Callback, true);
  36. Assert.Empty(errors);
  37. bool CheckResult()
  38. {
  39. foreach (var item in result)
  40. {
  41. if (!expected.Contains(item))
  42. return false;
  43. }
  44. return true;
  45. }
  46. Assert.True(CheckResult());
  47. }
  48. [Fact]
  49. public void ProcessFileTest()
  50. {
  51. var expected = @"./testFiles/test1.txt";
  52. var result = string.Empty;
  53. void Callback(string value)
  54. {
  55. result = value;
  56. }
  57. var errors = ProcessFiles.ProcessFiles.Process(new[] { "./testFiles/test1.txt" }, "txt", Callback);
  58. Assert.Empty(errors);
  59. Assert.Equal(expected, result);
  60. }
  61. [Fact]
  62. public void ProcessFileNotExistTest()
  63. {
  64. var expected = @"./testFiles/test1.txt";
  65. var result = string.Empty;
  66. void Callback(string value)
  67. {
  68. result = value;
  69. }
  70. var errors = ProcessFiles.ProcessFiles.Process(new[] { "./testFiles/test.txt" }, "txt", Callback);
  71. Assert.NotEmpty(errors);
  72. Assert.NotEqual(expected, result);
  73. }
  74. [Fact]
  75. public void ProcessFileNotMatchExtensionTest()
  76. {
  77. var expected = @"./testFiles/test1.txt";
  78. var result = string.Empty;
  79. void Callback(string value)
  80. {
  81. result = value;
  82. }
  83. var errors = ProcessFiles.ProcessFiles.Process(new[] { "./testFiles/test1.txt" }, "abc", Callback);
  84. Assert.NotEmpty(errors);
  85. Assert.NotEqual(expected, result);
  86. }
  87. }
  88. }