|
@@ -1,151 +1,156 @@
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.IO;
|
|
|
|
+using System.Linq;
|
|
using Xunit;
|
|
using Xunit;
|
|
|
|
+using ProcessFiles;
|
|
|
|
|
|
-namespace ProcessFilesTests
|
|
|
|
|
|
+namespace ProcessFilesTests;
|
|
|
|
+
|
|
|
|
+public class ProcessFilesTests
|
|
{
|
|
{
|
|
- public class ProcessFilesTests
|
|
|
|
- {
|
|
|
|
- private readonly string testFolder = "./testFiles";
|
|
|
|
- private readonly string testFile = "./testFiles/test1.txt";
|
|
|
|
|
|
+ private const string TestFolder = "./testFiles";
|
|
|
|
+ private const string TestFile = "./testFiles/test1.txt";
|
|
|
|
|
|
- private static readonly string expectedInFolder = "test1.txt";
|
|
|
|
|
|
+ private const string ExpectedInFolder = "test1.txt";
|
|
|
|
|
|
- private readonly List<string> expectedInSubFolder =
|
|
|
|
- [
|
|
|
|
- expectedInFolder,
|
|
|
|
- "test2.txt",
|
|
|
|
- "test3.txt"
|
|
|
|
- ];
|
|
|
|
|
|
+ private readonly List<string> expectedInSubFolder =
|
|
|
|
+ [
|
|
|
|
+ ExpectedInFolder,
|
|
|
|
+ "test2.txt",
|
|
|
|
+ "test3.txt"
|
|
|
|
+ ];
|
|
|
|
|
|
- private readonly List<string> expectedInSubFolderMultipleExtensions =
|
|
|
|
- [
|
|
|
|
- "test.json"
|
|
|
|
- ];
|
|
|
|
|
|
+ private readonly List<string> expectedInSubFolderMultipleExtensions =
|
|
|
|
+ [
|
|
|
|
+ "test.json"
|
|
|
|
+ ];
|
|
|
|
|
|
|
|
+ public ProcessFilesTests()
|
|
|
|
+ {
|
|
|
|
+ expectedInSubFolderMultipleExtensions.AddRange(expectedInSubFolder);
|
|
|
|
+ }
|
|
|
|
|
|
- public ProcessFilesTests()
|
|
|
|
- {
|
|
|
|
- expectedInSubFolderMultipleExtensions.AddRange(expectedInSubFolder);
|
|
|
|
- }
|
|
|
|
|
|
+ [Fact]
|
|
|
|
+ public void ProcessFolderTest()
|
|
|
|
+ {
|
|
|
|
+ var result = string.Empty;
|
|
|
|
|
|
- [Fact]
|
|
|
|
- public void ProcessFolderTest()
|
|
|
|
|
|
+ var test = new FileProcessing();
|
|
|
|
+ var errors = test.Process([TestFolder], "txt", TestAction);
|
|
|
|
+ Assert.Empty(errors);
|
|
|
|
+ Assert.Equal(ExpectedInFolder, result);
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ void TestAction(string value)
|
|
{
|
|
{
|
|
- var result = string.Empty;
|
|
|
|
- void TestAction(string value)
|
|
|
|
- {
|
|
|
|
- result = Path.GetFileName(value);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var test = new ProcessFiles.ProcessFiles();
|
|
|
|
- var errors = test.Process([testFolder], "txt", TestAction);
|
|
|
|
- Assert.Empty(errors);
|
|
|
|
- Assert.Equal(expectedInFolder, result);
|
|
|
|
|
|
+ result = Path.GetFileName(value);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- private static bool CheckResult(List<string> result, List<string> expected)
|
|
|
|
- {
|
|
|
|
- if (!result.Count.Equals(expected.Count))
|
|
|
|
- return false;
|
|
|
|
|
|
+ private static bool CheckResult(List<string> result, List<string> expected)
|
|
|
|
+ {
|
|
|
|
+ return result.Count.Equals(expected.Count) && result.All(expected.Contains);
|
|
|
|
+ }
|
|
|
|
|
|
- foreach (var item in result)
|
|
|
|
- {
|
|
|
|
- if (!expected.Contains(item))
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
|
|
+ [Fact]
|
|
|
|
+ public void ProcessFolderRecursiveTest()
|
|
|
|
+ {
|
|
|
|
+ var result = new List<string>();
|
|
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
|
|
+ var test = new FileProcessing();
|
|
|
|
+ var errors = test.Process([TestFolder], "txt", TestAction, true);
|
|
|
|
+ Assert.Empty(errors);
|
|
|
|
+ Assert.True(CheckResult(result, expectedInSubFolder));
|
|
|
|
+ return;
|
|
|
|
|
|
- [Fact]
|
|
|
|
- public void ProcessFolderRecursiveTest()
|
|
|
|
|
|
+ void TestAction(string value)
|
|
{
|
|
{
|
|
- var result = new List<string>();
|
|
|
|
- void TestAction(string value)
|
|
|
|
- {
|
|
|
|
- result.Add(Path.GetFileName(value));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var test = new ProcessFiles.ProcessFiles();
|
|
|
|
- var errors = test.Process([testFolder], "txt", TestAction, true);
|
|
|
|
- Assert.Empty(errors);
|
|
|
|
- Assert.True(CheckResult(result, expectedInSubFolder));
|
|
|
|
|
|
+ result.Add(Path.GetFileName(value));
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [Fact]
|
|
|
|
+ public void ProcessFolderAndFileTest()
|
|
|
|
+ {
|
|
|
|
+ var result = new List<string>();
|
|
|
|
+
|
|
|
|
+ var test = new FileProcessing();
|
|
|
|
+ var errors = test.Process(["./testFiles/subFolder", TestFile], "txt", TestAction);
|
|
|
|
+ Assert.Empty(errors);
|
|
|
|
+ Assert.True(CheckResult(result, expectedInSubFolder));
|
|
|
|
+ return;
|
|
|
|
|
|
- [Fact]
|
|
|
|
- public void ProcessFolderAndFileTest()
|
|
|
|
- {
|
|
|
|
- var result = new List<string>();
|
|
|
|
- void TestAction(string value)
|
|
|
|
- {
|
|
|
|
- result.Add(Path.GetFileName(value));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var test = new ProcessFiles.ProcessFiles();
|
|
|
|
- var errors = test.Process(["./testFiles/subFolder", testFile], "txt", TestAction);
|
|
|
|
- Assert.Empty(errors);
|
|
|
|
- Assert.True(CheckResult(result, expectedInSubFolder));
|
|
|
|
|
|
+ void TestAction(string value)
|
|
|
|
+ {
|
|
|
|
+ result.Add(Path.GetFileName(value));
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [Fact]
|
|
|
|
+ public void ProcessFileTest()
|
|
|
|
+ {
|
|
|
|
+ var result = string.Empty;
|
|
|
|
+
|
|
|
|
+ var test = new FileProcessing();
|
|
|
|
+ var errors = test.Process([TestFile], "txt", TestAction);
|
|
|
|
+ Assert.Empty(errors);
|
|
|
|
+ Assert.Equal(ExpectedInFolder, result);
|
|
|
|
+ return;
|
|
|
|
|
|
- [Fact]
|
|
|
|
- public void ProcessFileTest()
|
|
|
|
|
|
+ void TestAction(string value)
|
|
{
|
|
{
|
|
- var result = string.Empty;
|
|
|
|
- void TestAction(string value)
|
|
|
|
- {
|
|
|
|
- result = Path.GetFileName(value);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var test = new ProcessFiles.ProcessFiles();
|
|
|
|
- var errors = test.Process([testFile], "txt", TestAction);
|
|
|
|
- Assert.Empty(errors);
|
|
|
|
- Assert.Equal(expectedInFolder, result);
|
|
|
|
|
|
+ result = Path.GetFileName(value);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [Fact]
|
|
|
|
+ public void ProcessFileNotExistTest()
|
|
|
|
+ {
|
|
|
|
+ var result = string.Empty;
|
|
|
|
+
|
|
|
|
+ var test = new FileProcessing();
|
|
|
|
+ var errors = test.Process(["./testFiles/test.txt"], "txt", TestAction);
|
|
|
|
+ Assert.NotEmpty(errors);
|
|
|
|
+ Assert.Empty(result);
|
|
|
|
+ return;
|
|
|
|
|
|
- [Fact]
|
|
|
|
- public void ProcessFileNotExistTest()
|
|
|
|
|
|
+ void TestAction(string value)
|
|
{
|
|
{
|
|
- var result = string.Empty;
|
|
|
|
- void TestAction(string value)
|
|
|
|
- {
|
|
|
|
- result = value;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var test = new ProcessFiles.ProcessFiles();
|
|
|
|
- var errors = test.Process(["./testFiles/test.txt"], "txt", TestAction);
|
|
|
|
- Assert.NotEmpty(errors);
|
|
|
|
- Assert.Empty(result);
|
|
|
|
|
|
+ result = value;
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [Fact]
|
|
|
|
+ public void ProcessFileNotMatchExtensionTest()
|
|
|
|
+ {
|
|
|
|
+ var result = string.Empty;
|
|
|
|
+
|
|
|
|
+ var test = new FileProcessing();
|
|
|
|
+ var errors = test.Process([TestFile], "abc", TestAction);
|
|
|
|
+ Assert.NotEmpty(errors);
|
|
|
|
+ Assert.Empty(result);
|
|
|
|
+ return;
|
|
|
|
|
|
- [Fact]
|
|
|
|
- public void ProcessFileNotMatchExtensionTest()
|
|
|
|
|
|
+ void TestAction(string value)
|
|
{
|
|
{
|
|
- var result = string.Empty;
|
|
|
|
- void TestAction(string value)
|
|
|
|
- {
|
|
|
|
- result = value;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var test = new ProcessFiles.ProcessFiles();
|
|
|
|
- var errors = test.Process([testFile], "abc", TestAction);
|
|
|
|
- Assert.NotEmpty(errors);
|
|
|
|
- Assert.Empty(result);
|
|
|
|
|
|
+ result = value;
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [Fact]
|
|
|
|
+ public void ProcessFolderRecursiveMultipleExtensionsTest()
|
|
|
|
+ {
|
|
|
|
+ var result = new List<string>();
|
|
|
|
+
|
|
|
|
+ var test = new FileProcessing();
|
|
|
|
+ var errors = test.Process([TestFolder], ["txt", "json"], TestAction, true);
|
|
|
|
+ Assert.Empty(errors);
|
|
|
|
+ Assert.True(CheckResult(result, expectedInSubFolderMultipleExtensions));
|
|
|
|
+ return;
|
|
|
|
|
|
- [Fact]
|
|
|
|
- public void ProcessFolderRecursiveMultipleExtensionsTest()
|
|
|
|
|
|
+ void TestAction(string value)
|
|
{
|
|
{
|
|
- var result = new List<string>();
|
|
|
|
- void TestAction(string value)
|
|
|
|
- {
|
|
|
|
- result.Add(Path.GetFileName(value));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var test = new ProcessFiles.ProcessFiles();
|
|
|
|
- var errors = test.Process([testFolder], ["txt", "json"], TestAction, true);
|
|
|
|
- Assert.Empty(errors);
|
|
|
|
- Assert.True(CheckResult(result, expectedInSubFolderMultipleExtensions));
|
|
|
|
|
|
+ result.Add(Path.GetFileName(value));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|