public void DoFilePathBindFileDoesNotExistTest()
        {
            // 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}.txt\"" // <-.txt to exe makes it not exist.
            };

            // Act
            int exitCode = CakeFrostingRunner.TryRunCake(arguments);

            // Check
            Assert.NotZero(exitCode);
            Assert.NotNull(foundException);
            Assert.IsTrue(foundException is AggregateException);

            AggregateException ex = (AggregateException)foundException;

            Assert.AreEqual(1, ex.InnerExceptions.Count);
            Assert.IsTrue(ex.InnerExceptions[0] is FileNotFoundException);
        }
        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);
        }
示例#5
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 DoBooleanBindBindRequiredArgMissingTest()
        {
            // Setup
            string[] arguments = new string[]
            {
                $"--target={nameof( BooleanEnvironmentVariableBindTask )}",
            };

            // Act
            int exitCode = CakeFrostingRunner.TryRunCake(arguments);

            // Check
            Assert.NotZero(exitCode);
            Assert.NotNull(foundException);
            Assert.IsTrue(foundException is AggregateException);

            AggregateException ex = (AggregateException)foundException;

            Assert.AreEqual(1, ex.InnerExceptions.Count);
            Assert.IsTrue(ex.InnerExceptions[0] is MissingRequiredArgumentException);
        }
        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 DoIntegerBindRequiredAboveMaxTest()
        {
            // Setup
            string[] arguments = new string[]
            {
                $"--target={nameof( IntegerBindTest )}",
                $"--{IntegerBind.RequiredArgName}={IntegerBind.RequiredArgMaxValue + 1}",
            };

            // Act
            int exitCode = CakeFrostingRunner.TryRunCake(arguments);

            // Check
            Assert.NotZero(exitCode);
            Assert.NotNull(foundException);
            Assert.IsTrue(foundException is AggregateException);

            AggregateException ex = (AggregateException)foundException;

            Assert.AreEqual(1, ex.InnerExceptions.Count);
            Assert.IsTrue(ex.InnerExceptions[0] is ArgumentTooLargeException);
        }
        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());
        }
        public void DoFilePathBindRequiredArgMissingTest()
        {
            // Setup
            string[] arguments = new string[]
            {
                $"--target={nameof( FilePathBindTask )}",
            };

            // Act
            int exitCode = CakeFrostingRunner.TryRunCake(arguments);

            // Check
            Assert.NotZero(exitCode);
            Assert.NotNull(foundException);
            Assert.IsTrue(foundException is AggregateException);

            AggregateException ex = (AggregateException)foundException;

            // 2 Missing arguments should result in 2 exceptions.
            Assert.AreEqual(2, ex.InnerExceptions.Count);
            Assert.IsTrue(ex.InnerExceptions[0] is MissingRequiredArgumentException);
            Assert.IsTrue(ex.InnerExceptions[1] is MissingRequiredArgumentException);
        }