Skip to content

Commit 61b1954

Browse files
authored
Merge pull request #13 from M1nd3r/UTest
InputHandler Tests
2 parents 55557ca + c5b8d56 commit 61b1954

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

FolderSync/InputHandler.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using FolderSync.Log;
22

33
namespace FolderSync {
4-
internal static class InputHandler {
4+
public static class InputHandler {
55
private const string MSG_SYNTAX = "Syntax is: \"From\" \"To\" \"SyncIntervalSeconds\" \"logFile\"\n\nExample: C:\\sourceFolder\\ C:\\targetFolder\\ 300 C:\\logfile.txt\n\nSyncIntervalSeconds and logFile are optional arguments. It is possible to add one or both. If both optional arguments are entered, the order must be preserved.";
66
private static string? fromPath, toPath;
77
private static int intervalSeconds = -1;
@@ -15,7 +15,7 @@ public static bool HandleInput(string[] args) {
1515
if (!HandleMandatoryArguments(args))
1616
return false;
1717

18-
if(args.Length == 2)
18+
if (args.Length == 2)
1919
return true;
2020

2121
if (args.Length == 3)
@@ -89,6 +89,10 @@ private static bool HandleNewLogFile(string logFilePath) {
8989
Console.WriteLine("Log file cannot be created - Unauthorized Access.");
9090
return false;
9191
}
92+
catch (ArgumentException e) {
93+
Console.WriteLine("Log file path is invalid: {0}", e.Message);
94+
return false;
95+
}
9296
return true;
9397
}
9498
private static bool TryCreateFolder(string path) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using FolderSync;
2+
3+
namespace FolderSyncTests {
4+
[TestClass]
5+
public class InputHandlerTests {
6+
private static string baseDir = AppDomain.CurrentDomain.BaseDirectory;
7+
[TestMethod]
8+
public void InputHandlerNullArgumentsTest() {
9+
Assert.IsFalse(InputHandler.HandleInput(null!));
10+
}
11+
[TestMethod]
12+
public void InputHandlerOneArgumentTest() {
13+
Assert.IsFalse(InputHandler.HandleInput(new string[] { "one" }));
14+
}
15+
[TestMethod]
16+
public void InputHandlerInvalidMandatoryArgumentsTest() {
17+
Assert.IsFalse(InputHandler.HandleInput(new string[] { "one", "two" }));
18+
}
19+
[TestMethod]
20+
public void InputHandlerFiveArgumentsTest() {
21+
Assert.IsFalse(InputHandler.HandleInput(new string[] { "one", "two", "three", "four", "five" }));
22+
}
23+
[TestMethod]
24+
public void InputHandlerValidMandatoryArgumentsTest() {
25+
Assert.IsTrue(InputHandler.HandleInput(new string[] { baseDir, baseDir }));
26+
}
27+
[TestMethod]
28+
public void InputHandlerValidMandatoryArgumentsInvalidLogPathTest() {
29+
Assert.IsFalse(InputHandler.HandleInput(new string[] { baseDir, baseDir, "" }));
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)