예제 #1
0
 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");
        }
예제 #3
0
        public void WHEN_MethodHasNullableArg_AND_ArgIsNotProvided_THEN_MethodIsNotExecuted()
        {
            var args = new[] { "nullable" };

            CmdLine <TestClassStatic> .Execute(args).Should().Be(-1);

            TestClassStatic.GetMethodInvokedAndReset().Should().BeNull();
        }
예제 #4
0
        public void WHEN_ClassHasStaticMethod_THEN_MethodIsExecuted()
        {
            var args = new[] { "test1", "/arg=str" };

            CmdLine <TestClassStatic> .Execute(args).Should().Be(0);

            TestClassStatic.GetMethodInvokedAndReset().Should().Be("test1");
        }
예제 #5
0
        public void WHEN_MethodHasNullableArgWithDefault_AND_ArgIsNotProvided_THEN_MethodIsExecuted()
        {
            var args = new[] { "nullablewithdefault" };

            CmdLine <TestClassStatic> .Execute(args).Should().Be(0);

            TestClassStatic.GetMethodInvokedAndReset().Should().Be("nullablewithdefault");
        }
예제 #6
0
        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");
        }
예제 #7
0
        public void WHEN_CallingNonpublicMethod_THEN_MethodIsNotExecuted()
        {
            var args = new[] { "nonpublicmethod" };

            CmdLine <TestClassStatic> .Execute(args).Should().Be(-1);

            TestClassStatic.GetMethodInvokedAndReset().Should().BeNull();
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #12
0
        protected void Test_AllMethods_StaticCall <T>() where T : class
        {
            var args = new[] { "mystaticmethod" };

            CmdLine <T> .Execute(args);

            Assert.IsTrue(WasStaticMethodCalled);
            Assert.IsFalse(WasNonStaticMethodCalled);
        }
예제 #13
0
        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);
        }
예제 #14
0
        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();
        }
예제 #15
0
        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");
        }
예제 #16
0
        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();
        }
예제 #17
0
        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();
        }
예제 #18
0
        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");
        }
예제 #19
0
        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");
        }
예제 #20
0
        public void WHEN_CallingInheritedMethod_THEN_MethodIsNotExecuted()
        {
            var args = new[] { "gethashcode" };

            CmdLine <TestClassStatic> .Execute(args).Should().Be(-1);
        }
예제 #21
0
        public void WHEN_ArgHasInvalidDefaultType_THEN_CmdLineExceptionIsThrown()
        {
            var args = new[] { "withinvaliddefault" };

            this.Invoking(self => CmdLine <TestClassWithInvalidArg> .Execute(args)).ShouldThrow <CmdLineException>().And.Message.Should().Contain("parameterWithInvalidDefaultValueType");
        }