public void Test_Action_With_DateTimeParameter_ExplicitDefaultValue_Default() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_DateTimeParameter_ExplicitDefaultValue"), this); var res1 = action.ParseParameters(""); Assert.AreEqual(new DateTime(2020, 01, 01), res1.value); var res2 = action.ParseParameters("-x something"); Assert.AreEqual(new DateTime(2020, 01, 01), res2.value); }
public void Test_Action_With_StringParameter_ExplicitDefaultValue_Default() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_StringParameter_ExplicitDefaultValue"), this); var res1 = action.ParseParameters(""); Assert.AreEqual("test", res1.file); var res2 = action.ParseParameters("-x something"); Assert.AreEqual("test", res2.file); }
public void Test_Action_With_DecimalParameter_Default() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_DecimalParameter"), this); var res1 = action.ParseParameters(""); Assert.AreEqual(default(decimal), res1.value); var res2 = action.ParseParameters("-x something"); Assert.AreEqual(default(decimal), res2.value); }
public void Test_Action_For_NegativeTests_ParameterConvertError_ShouldFail() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_MultipleParameters"), this); var inputString = ""; inputString = "-f \"file1.txt --k notbool"; Assert.ThrowsException <ArgumentException>(() => action.ParseParameters(inputString)); inputString = "-f \"file1.txt --r notint"; Assert.ThrowsException <ArgumentException>(() => action.ParseParameters(inputString)); inputString = "-f \"file1.txt --m nodouble"; Assert.ThrowsException <ArgumentException>(() => action.ParseParameters(inputString)); }
public void Test_Action_With_DateTimeParameter_ExplicitVariants_ShouldFail_With_DefaultVariant(params string[] parameters) { var inputString = string.Join(" ", parameters); var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_DateTimeParameter_ExplicitVariants"), this); var res = action.ParseParameters(inputString); Assert.AreEqual(default(DateTime), res.value); }
public void Test_Action_For_NegativeTests_NotEndingQuotes_ShouldFail() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_MultipleParameters"), this); var inputString = ""; inputString = "-f \"file1.txt --k false"; Assert.ThrowsException <ArgumentException>(() => action.ParseParameters(inputString)); }
public void Test_Action_With_DateTimeParameter(params string[] parameters) { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_DateTimeParameter"), this); var inputString = string.Join(" ", parameters); var res = action.ParseParameters(inputString); Assert.AreEqual(DateTime.Parse(parameters[1].Trim('"')), res.value); Assert.AreEqual(typeof(DateTime), res.value.GetType()); }
public void Test_Action_With_StringParameter_ExplicitType_ExplicitDefaultValue(params string[] parameters) { var inputString = string.Join(" ", parameters); var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_StringParameter_ExplicitType"), this); var res = action.ParseParameters(inputString); Assert.AreEqual(typeof(string), res.file.GetType()); }
public void Test_Action_With_DateTimeParameter_ExplicitVariants(params string[] parameters) { var inputString = string.Join(" ", parameters); var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_DateTimeParameter_ExplicitVariants"), this); var res = action.ParseParameters(inputString); Assert.ThrowsException <RuntimeBinderException>(() => res.x); Assert.AreEqual(DateTime.Parse(parameters[1].Trim('"')), res.value); Assert.AreEqual(typeof(DateTime), res.value.GetType()); }
public void Test_Action_With_MultipleParameters_MoreCases() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_MultipleParameters"), this); dynamic res = null; var inputString = ""; inputString = "-f file1.txt -k false -r 2000 -m 2.4"; res = action.ParseParameters(inputString); Assert.AreEqual(typeof(string), res.file.GetType()); Assert.AreEqual(typeof(bool), res.keepOpen.GetType()); Assert.AreEqual(typeof(int), res.recordsToRead.GetType()); Assert.AreEqual(typeof(double), res.maxMemory.GetType()); Assert.AreEqual("file1.txt", res.file); Assert.AreEqual(false, res.keepOpen); Assert.AreEqual(2000, res.recordsToRead); Assert.AreEqual(2.4, res.maxMemory); inputString = "--file file1.txt"; res = action.ParseParameters(inputString); Assert.AreEqual(typeof(string), res.file.GetType()); Assert.AreEqual(typeof(bool), res.keepOpen.GetType()); Assert.AreEqual(typeof(int), res.recordsToRead.GetType()); Assert.AreEqual(typeof(double), res.maxMemory.GetType()); Assert.AreEqual("file1.txt", res.file); Assert.AreEqual(true, res.keepOpen); Assert.AreEqual(1000, res.recordsToRead); Assert.AreEqual(1.5, res.maxMemory); inputString = "-f \"file1 with space.txt\" -k false -r 2000 -m 2.4"; res = action.ParseParameters(inputString); Assert.AreEqual(typeof(string), res.file.GetType()); Assert.AreEqual(typeof(bool), res.keepOpen.GetType()); Assert.AreEqual(typeof(int), res.recordsToRead.GetType()); Assert.AreEqual(typeof(double), res.maxMemory.GetType()); Assert.AreEqual("file1 with space.txt", res.file); Assert.AreEqual(false, res.keepOpen); Assert.AreEqual(2000, res.recordsToRead); Assert.AreEqual(2.4, res.maxMemory); }
public void Test_Action_For_NegativeTests_MultipleSameParameter_ShouldFail() { var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_MultipleParameters"), this); var inputString = ""; inputString = "-f file1.txt --file anotherfile.txt"; Assert.ThrowsException <ArgumentException>(() => action.ParseParameters(inputString)); //TODO - shouldn't be able to send -f twice. Current code picks up first one. Should be a bug.... but is it???? //inputString = "-f file1.txt -f anotherfile.txt"; //Assert.ThrowsException<ArgumentException>(() => action.ParseParameters(inputString)); }
public void Test_Action_With_MultipleParameters(params string[] parameters) { var inputString = string.Join(" ", parameters); var action = new ConsoleAction(typeof(ActionParameterTests).GetMethod("Action_With_MultipleParameters"), this); var res = action.ParseParameters(inputString); Assert.AreEqual(parameters[1].Trim('"'), res.file); Assert.AreEqual(typeof(string), res.file.GetType()); Assert.AreEqual(bool.Parse(parameters[3].Trim('"')), res.keepOpen); Assert.AreEqual(typeof(bool), res.keepOpen.GetType()); Assert.AreEqual(int.Parse(parameters[5].Trim('"')), res.recordsToRead); Assert.AreEqual(typeof(int), res.recordsToRead.GetType()); Assert.AreEqual(double.Parse(parameters[7].Trim('"')), res.maxMemory); Assert.AreEqual(typeof(double), res.maxMemory.GetType()); }