Esempio n. 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");
        }
Esempio n. 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();
        }
Esempio n. 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");
        }
Esempio n. 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");
        }
Esempio n. 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");
        }
Esempio n. 7
0
        public void WHEN_CallingNonpublicMethod_THEN_MethodIsNotExecuted()
        {
            var args = new[] { "nonpublicmethod" };

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

            TestClassStatic.GetMethodInvokedAndReset().Should().BeNull();
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
        protected void Test_AllMethods_StaticCall <T>() where T : class
        {
            var args = new[] { "mystaticmethod" };

            CmdLine <T> .Execute(args);

            Assert.IsTrue(WasStaticMethodCalled);
            Assert.IsFalse(WasNonStaticMethodCalled);
        }
Esempio n. 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);
        }
Esempio n. 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();
        }
Esempio n. 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");
        }
Esempio n. 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();
        }
Esempio n. 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();
        }
Esempio n. 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");
        }
Esempio n. 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");
        }
Esempio n. 20
0
        public void WHEN_CallingInheritedMethod_THEN_MethodIsNotExecuted()
        {
            var args = new[] { "gethashcode" };

            CmdLine <TestClassStatic> .Execute(args).Should().Be(-1);
        }
Esempio n. 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");
        }