public void DoFilePathBindTest()
        {
            // Setup
            const string requiredArgValue = "somewhere.txt";
            const string optionalArgValue = "someplace.txt";
            const string nullArgValue     = "a thing.txt";

            string[] arguments = new string[]
            {
                $"--target={nameof( FilePathBindTask )}",
                $"--{FilePathBind.RequiredArgName}=\"{requiredArgValue}\"",
                $"--{FilePathBind.OptionalArgName}=\"{optionalArgValue}\"",
                $"--{FilePathBind.NullArgName}={nullArgValue}",
                $"--{FilePathBind.MustExistArgName}=\"{exePath}\""
            };

            // Act
            CakeFrostingRunner.RunCake(arguments);

            // Check
            Assert.NotNull(actualBind);
            Assert.Null(foundException);
            Assert.AreEqual(requiredArgValue, actualBind.RequiredArg.ToString());
            Assert.AreEqual(optionalArgValue, actualBind.OptionalArg.ToString());
            Assert.AreEqual(nullArgValue, actualBind.NullDefaultArg.ToString());
            Assert.AreEqual(exePath.ToString(), actualBind.FileMustExistArg.ToString());
        }
        public void DoStringBindTest()
        {
            // Setup
            const string arg1 = "Hello World";
            const string arg2 = "SomeOtherArg";
            const string arg3 = ":)";

            string[] arguments = new string[]
            {
                $"--target={nameof( StringBindTask )}",
                $"--{StringBind.RequiredArgName}=\"{arg1}\"",
                $"--{StringBind.OptionalArgName}=\"{arg2}\"",
                $"--{StringBind.NullArgName}={arg3}"
            };

            // Act
            CakeFrostingRunner.RunCake(arguments);

            // Check
            Assert.NotNull(actualBind);
            Assert.Null(foundException);
            Assert.AreEqual(arg1, actualBind.RequiredArg);
            Assert.AreEqual(arg2, actualBind.OptionalArg);
            Assert.AreEqual(arg3, actualBind.NullDefaultArg);
        }
        public void DoBooleanBindNoOptionalValuesTest()
        {
            // Setup
            Environment.SetEnvironmentVariable(BooleanBind.RequiredArgName, false.ToString());
            string[] arguments = new string[]
            {
                $"--target={nameof( BooleanEnvironmentVariableBindTask )}"
            };

            // Act
            CakeFrostingRunner.RunCake(arguments);

            // Check
            Assert.NotNull(actualBind);
            Assert.IsFalse(actualBind.RequiredArg);
            Assert.AreEqual(BooleanBind.DefaultValue, actualBind.OptionalArg);
        }
Ejemplo n.º 4
0
        public void DoBooleanBindNoOptionalValuesTest()
        {
            // Setup
            string[] arguments = new string[]
            {
                $"--target={nameof( BooleanArgumentBindTask )}",
                $"--{BooleanBind.RequiredArgName}={false}"
            };

            // Act
            CakeFrostingRunner.RunCake(arguments);

            // Check
            Assert.NotNull(actualBind);
            Assert.IsFalse(actualBind.RequiredArg);
            Assert.AreEqual(BooleanBind.DefaultValue, actualBind.OptionalArg);
        }
        public void DoArgumentBackupTest()
        {
            // Setup
            string[] arguments = new string[]
            {
                $"--target={nameof( BooleanEnvironmentVariableThenArgumentBindTask )}",
                $"--{BooleanBind.RequiredArgName}={true}",
                $"--{BooleanBind.OptionalArgName}={true}"
            };

            // Act
            CakeFrostingRunner.RunCake(arguments);

            // Check
            Assert.NotNull(actualBind);
            Assert.IsTrue(actualBind.RequiredArg);
            Assert.IsTrue(actualBind.OptionalArg);
        }
        public void DoIntegerBindNoOptionalValuesTest()
        {
            const int requiredArgValue = IntegerBind.RequiredArgMinValue;

            // Setup
            string[] arguments = new string[]
            {
                $"--target={nameof( IntegerBindTest )}",
                $"--{IntegerBind.RequiredArgName}={requiredArgValue}",
            };

            // Act
            CakeFrostingRunner.RunCake(arguments);

            // Check
            Assert.NotNull(actualBind);
            Assert.AreEqual(requiredArgValue, actualBind.RequiredArg);
            Assert.AreEqual(IntegerBind.DefaultValue, actualBind.OptionalArg);
        }
        public void DoEnvironmentVariableBackupTest()
        {
            // Setup
            string[] arguments = new string[]
            {
                $"--target={nameof( BooleanArgumentThenEnvironmentVariableBindTask )}",
            };

            Environment.SetEnvironmentVariable(BooleanBind.RequiredArgName, true.ToString());
            Environment.SetEnvironmentVariable(BooleanBind.OptionalArgName, true.ToString());

            // Act
            CakeFrostingRunner.RunCake(arguments);

            // Check
            Assert.NotNull(actualBind);
            Assert.IsTrue(actualBind.RequiredArg);
            Assert.IsTrue(actualBind.OptionalArg);
        }
        public void DoEnumBindWithMissingOptionalTest()
        {
            const TestEnum requiredArgValue = TestEnum.Value2;
            const TestEnum optionalArgValue = default;

            // Setup
            string[] arguments = new string[]
            {
                $"--target={nameof( EnumBindTest )}",
                $"--{EnumBind.RequiredArgName}={requiredArgValue.ToString().ToLower()}"
            };

            // Act
            CakeFrostingRunner.RunCake(arguments);

            // Check
            Assert.NotNull(actualBind);
            Assert.AreEqual(requiredArgValue, actualBind.RequiredArg);
            Assert.AreEqual(optionalArgValue, actualBind.OptionalArg);
        }
        public void DoEnvVarOverridesCommandLineBindTest()
        {
            // Setup
            string[] arguments = new string[]
            {
                $"--target={nameof( BooleanEnvironmentVariableThenArgumentBindTask )}",
                $"--{BooleanBind.RequiredArgName}={false}",
                $"--{BooleanBind.OptionalArgName}={false}"
            };

            Environment.SetEnvironmentVariable(BooleanBind.RequiredArgName, true.ToString());
            Environment.SetEnvironmentVariable(BooleanBind.OptionalArgName, true.ToString());

            // Act
            CakeFrostingRunner.RunCake(arguments);

            // Check
            Assert.NotNull(actualBind);
            Assert.IsTrue(actualBind.RequiredArg);
            Assert.IsTrue(actualBind.OptionalArg);
        }
        public void DoStringBindNoOptionalValuesTest()
        {
            // Setup
            const string arg1 = "HelloWorld";

            string[] arguments = new string[]
            {
                $"--target={nameof( StringBindTask )}",
                $"--{StringBind.RequiredArgName}={arg1}",
            };

            // Act
            CakeFrostingRunner.RunCake(arguments);

            // Check
            Assert.NotNull(actualBind);
            Assert.Null(foundException);
            Assert.AreEqual(arg1, actualBind.RequiredArg);
            Assert.AreEqual(StringBind.DefaultValue, actualBind.OptionalArg);
            Assert.AreEqual(StringBind.NullDefaultValue, actualBind.NullDefaultArg);
        }
        public void DoFilePathBindNoOptionalValuesTest()
        {
            // Setup
            const string requiredArgValue = "HelloWorld.txt";

            string[] arguments = new string[]
            {
                $"--target={nameof( FilePathBindTask )}",
                $"--{FilePathBind.RequiredArgName}={requiredArgValue}",
                $"--{FilePathBind.MustExistArgName}=\"{exePath}\""
            };

            // Act
            CakeFrostingRunner.RunCake(arguments);

            // Check
            Assert.NotNull(actualBind);
            Assert.Null(foundException);
            Assert.AreEqual(requiredArgValue, actualBind.RequiredArg.ToString());
            Assert.AreEqual(FilePathBind.DefaultValue.ToString(), actualBind.OptionalArg.ToString());
            Assert.AreEqual(FilePathBind.NullDefaultValue, actualBind.NullDefaultArg);
            Assert.AreEqual(exePath.ToString(), actualBind.FileMustExistArg.ToString());
        }