static void Main(string[] args) { AppGuard.Invoke(() => CmdLine <Program> .Execute(args, new CmdLineConfig { ArgStartsWith = '-' })); AppGuard.DebugReadLine(); }
protected void Test_Call <T>(string[] args, bool expectedNonStatic, bool expectedStatic) where T : class { CmdLine <T> .Execute(args); Assert.AreEqual(expectedNonStatic, WasNonStaticMethodCalled, expectedNonStatic ? "Expected non-static method to be called but NO call was made" : "Expected non-static method NOT to be called but the call was made"); Assert.AreEqual(expectedStatic, WasStaticMethodCalled, expectedStatic ? "Expected static method to be called but NO call was made" : "Expected static method NOT to be called but the call was made"); }
public void WHEN_MethodHasNullableArg_AND_ArgIsNotProvided_THEN_MethodIsNotExecuted() { var args = new[] { "nullable" }; CmdLine <TestClassStatic> .Execute(args).Should().Be(-1); TestClassStatic.GetMethodInvokedAndReset().Should().BeNull(); }
public void WHEN_ClassHasStaticMethod_THEN_MethodIsExecuted() { var args = new[] { "test1", "/arg=str" }; CmdLine <TestClassStatic> .Execute(args).Should().Be(0); TestClassStatic.GetMethodInvokedAndReset().Should().Be("test1"); }
public void WHEN_MethodHasNullableArgWithDefault_AND_ArgIsNotProvided_THEN_MethodIsExecuted() { var args = new[] { "nullablewithdefault" }; CmdLine <TestClassStatic> .Execute(args).Should().Be(0); TestClassStatic.GetMethodInvokedAndReset().Should().Be("nullablewithdefault"); }
public void WHEN_MethodHasNullableArg_AND_ArgIsProvided_THEN_MethodIsExecuted() { var args = new[] { "nullable", "/value=3" }; CmdLine <TestClassStatic> .Execute(args).Should().Be(0); TestClassStatic.GetMethodInvokedAndReset().Should().Be("nullable"); }
public void WHEN_CallingNonpublicMethod_THEN_MethodIsNotExecuted() { var args = new[] { "nonpublicmethod" }; CmdLine <TestClassStatic> .Execute(args).Should().Be(-1); TestClassStatic.GetMethodInvokedAndReset().Should().BeNull(); }
public void WHEN_MethodHasDefaultEnumParameter_AND_NoArgIsPassed_THEN_MethodIsExecuted() { var args = new[] { "EnumTestWithDefault" }; var instance = new EnumTestClass(); CmdLine <EnumTestClass> .Execute(args, instance).Should().Be(0); instance.Actual.Should().Be(TestEnumType.Value3); }
public void WHEN_TypeIsEnum_AND_FlagsArgIsPassed_THEN_MethodIsNotExecuted() { var args = new[] { "EnumTest", "/value=Value1,Value2" }; var instance = new EnumTestClass(); CmdLine <EnumTestClass> .Execute(args, instance).Should().Be(-1); instance.Actual.Should().Be(TestEnumType.NeverSetValue); }
public void WHEN_InvalidFlagsArgIsPassed_THEN_MethodIsNotExecuted() { var args = new[] { "EnumTest", "/value=Flag4" }; var instance = new FlagTestClass(); CmdLine <FlagTestClass> .Execute(args, instance).Should().Be(-1); instance.Actual.Should().Be(FlagType.NoFlag); }
public void WHEN_EnumArgIsPassed_THEN_MethodIsExecuted() { var args = new[] { "EnumTest", "/value=Value2" }; var instance = new EnumTestClass(); CmdLine <EnumTestClass> .Execute(args, instance).Should().Be(0); instance.Actual.Should().Be(TestEnumType.Value2); }
protected void Test_AllMethods_StaticCall <T>() where T : class { var args = new[] { "mystaticmethod" }; CmdLine <T> .Execute(args); Assert.IsTrue(WasStaticMethodCalled); Assert.IsFalse(WasNonStaticMethodCalled); }
public void WHEN_FlagArgIsPassed_AND_ArgHasMultipleFlags_THEN_MethodIsExecuted() { var args = new[] { "EnumTest", "/value=FlagA,FlagB" }; var instance = new FlagTestClass(); CmdLine <FlagTestClass> .Execute(args, instance).Should().Be(0); instance.Actual.Should().Be(FlagType.FlagA | FlagType.FlagB); }
public void WHEN_UsingCustomArgSeparator_AND_ArgIsInvalid_THEN_MethodIsNotExecuted() // AND_ErrorMessageIsDisplayed { var config = new CmdLineConfig { ArgSeparator = ':' }; var args = new[] { "test3", "/count=2", "/list=1,2" }; CmdLine <TestClassStatic> .Execute(args, config); TestClassStatic.GetMethodInvokedAndReset().Should().BeNull(); }
public void WHEN_ArgIsValueTypeArray_THEN_MethodIsExecuted() { var args = new[] { "test3", "/count=1", "/list=1" }; CmdLine <TestClassStatic> .Execute(args).Should().Be(0); TestClassStatic.GetMethodInvokedAndReset().Should().Be("test3"); args = new[] { "test3", "/count=2", "/list=1,2" }; CmdLine <TestClassStatic> .Execute(args).Should().Be(0); TestClassStatic.GetMethodInvokedAndReset().Should().Be("test3"); }
public void WHEN_InheritedMembersAreNotIncluded_THEN_MethodIsNotExecuted() { var args = new string[] { "method", "/Property=7" }; var instance = new DerivedClass(); instance.Property = 0; CmdLine <DerivedClass> .Execute(args, instance).Should().Be(-1); instance.Property.Should().Be(0); WasNonStaticMethodCalled.Should().BeFalse(); WasStaticMethodCalled.Should().BeFalse(); }
public void WHEN_ArgIsForField_THEN_FieldIsSet_AND_MethodIsExecuted() { var args = new string[] { "method", "/Field=7" }; var instance = new DerivedAllIncludedClass(); instance.Field = 0; CmdLine <DerivedAllIncludedClass> .Execute(args, instance).Should().Be(0); instance.Field.Should().Be(7); WasNonStaticMethodCalled.Should().BeTrue(); WasStaticMethodCalled.Should().BeFalse(); }
public void WHEN_ArgLetterCasingIsDifferent_THEN_MethodIsExecuted() { var args = new[] { "test3", "/Count=1", "/lIst=1" }; CmdLine <TestClassStatic> .Execute(args).Should().Be(0); TestClassStatic.GetMethodInvokedAndReset().Should().Be("test3"); args = new[] { "TEST3", "/COUNT=2", "/list=1,2" }; CmdLine <TestClassStatic> .Execute(args).Should().Be(0); TestClassStatic.GetMethodInvokedAndReset().Should().Be("test3"); }
public void WHEN_UsingCustomArgSeparator_THEN_MethodIsExecuted() { var config = new CmdLineConfig { ArgSeparator = ':' }; var args = new[] { "test3", "/count:1", "/list:1" }; CmdLine <TestClassStatic> .Execute(args, config).Should().Be(0); TestClassStatic.GetMethodInvokedAndReset().Should().Be("test3"); args = new[] { "test3", "/count:2", "/list:1,2" }; CmdLine <TestClassStatic> .Execute(args, config).Should().Be(0); TestClassStatic.GetMethodInvokedAndReset().Should().Be("test3"); }
public void WHEN_CallingInheritedMethod_THEN_MethodIsNotExecuted() { var args = new[] { "gethashcode" }; CmdLine <TestClassStatic> .Execute(args).Should().Be(-1); }
public void WHEN_ArgHasInvalidDefaultType_THEN_CmdLineExceptionIsThrown() { var args = new[] { "withinvaliddefault" }; this.Invoking(self => CmdLine <TestClassWithInvalidArg> .Execute(args)).ShouldThrow <CmdLineException>().And.Message.Should().Contain("parameterWithInvalidDefaultValueType"); }