Mock for Program. This mock inhibits both Program.EmitFiles and Program.PrepareFiles.
Inheritance: MockedProgramBase
Exemplo n.º 1
0
        public void FileParameterAndUnnamedParameterCauseConflict()
        {
            var program = new MockedProgram(new string[]
            {
                ParameterUtils.FileArgumentParameter,
                "file1",
                "file2"
            });
            program.Execute();

            program.AssertMainProgramRoutineNotRun();

            Assert.IsNotNull(program.ThrownOptionException, "Expecting an option exception");
            Assert.IsNotNull(program.ThrownOptionException.InnerException);
            Assert.IsInstanceOfType(program.ThrownOptionException.InnerException,
                typeof(ConflictingOptionsException));
            Assert.AreEqual(2,
                (program.ThrownOptionException.InnerException as ConflictingOptionsException).Options.Count(),
                "Expecting 2 conflicting options!");
            Assert.AreEqual(Program.UnnamedArgumentName,
                (program.ThrownOptionException.InnerException as ConflictingOptionsException).Options.ElementAt(0),
                "Conflicting option does not match expected!");
            Assert.AreEqual(Program.FileArgumentName,
                (program.ThrownOptionException.InnerException as ConflictingOptionsException).Options.ElementAt(1),
                "Conflicting option does not match expected!");
        }
Exemplo n.º 2
0
        public void AbsoluteOutputPath()
        {
            string absoluteOutputPath = testContext.GetTestDeploymentFolder();

            var program = new MockedProgram(new string[]
            {
                ParameterUtils.FileArgumentParameter,
                "file1",
                ParameterUtils.OutputArgumentParameter,
                absoluteOutputPath
            });
            program.Execute();

            Assert.AreEqual(false, program.ErrorHandled, "No error expected!");
            Assert.AreEqual(absoluteOutputPath, program.OutputFolder, "Wrong acquired output path!");
        }
Exemplo n.º 3
0
        public void AssemblyParameterValueIsStored()
        {
            var value = "fileAssembly1";

            var program = new MockedProgram(new string[]
            {
                ParameterUtils.FileArgumentParameter,
                "file1",
                ParameterUtils.AssemblyArgumentParameter,
                value,
                ParameterUtils.OutputArgumentParameter,
                value
            });
            program.Execute();

            Assert.IsNotNull(program.AssemblyPath, "Expecting assembly path!");
            Assert.AreEqual(value, program.AssemblyPath, "Not matching output folder path!");
        }
Exemplo n.º 4
0
        public void WhenHelpShortParameterSpecifiedThenHelpIsShown()
        {
            var program = new MockedProgram(new string[]
            {
                ParameterUtils.HelpArgumentShortParameter
            });
            program.Execute();

            Assert.AreEqual(true, program.HelpContentDisplayed, "Help content should have been displayed!");
            program.AssertProgramNotRun();
        }
Exemplo n.º 5
0
        public void WhenHelpParameterSpecifiedWithOtherParametersThenHelpIsShown()
        {
            var parameters = new string[][]
            {
                new string[]
                {
                    ParameterUtils.HelpArgumentParameter,
                    ParameterUtils.FileArgumentParameter,
                    "file"
                },
                new string[]
                {
                    ParameterUtils.HelpArgumentParameter,
                    ParameterUtils.ProjectArgumentParameter,
                    "project"
                },
                new string[]
                {
                    ParameterUtils.HelpArgumentParameter,
                    ParameterUtils.VerboseArgumentParameter
                },
                new string[]
                {
                    ParameterUtils.HelpArgumentParameter,
                    ParameterUtils.ProjectArgumentParameter,
                    "project",
                    ParameterUtils.FileArgumentParameter,
                    "file"
                }
            };

            foreach (var input in parameters)
            {
                var program = new MockedProgram(input);
                program.Execute();

                Assert.AreEqual(true, program.HelpContentDisplayed, "Help content should have been displayed!");
                program.AssertProgramNotRun();
            }
        }
Exemplo n.º 6
0
        public void WhenFileShortParameterSpecifiedThenFileRoutineIsExecuted()
        {
            var program = new MockedProgram(new string[]
            {
                ParameterUtils.ProjectArgumentShortParameter,
                "file"
            });
            program.Execute();

            program.AssertMainProgramRoutineRun();
            Assert.AreEqual(true, program.FileConversionRoutineRun, "File conversion routine was expected to be run!");
        }
Exemplo n.º 7
0
        public void WhenCalledWithNoParameterThenMainRoutineIsNotRun()
        {
            var program = new MockedProgram(new string[] { });
            program.Execute();

            Assert.AreEqual(false, program.MainRunRoutineRun, "User should be notified about not feasible execution!");
            Assert.AreEqual(true, program.HelpContentDisplayed, "Help content should have been displayed!");
            program.AssertProgramNotRun();
        }
Exemplo n.º 8
0
        public void WhenCalledWithNoParameterThenHelpIsShown()
        {
            var program = new MockedProgram(new string[]{ });
            program.Execute();

            Assert.AreEqual(true, program.HelpContentDisplayed, "Help content should have been displayed!");
            program.AssertProgramNotRun();
        }
Exemplo n.º 9
0
        public void WhenNoOutputPathIsSpecifiedFilePathIsUsedWhenAbsolute()
        {
            // In the end we get an absolute path we can pass to runner!
            var value = testContext.GetTestDeploymentFolder();

            var program = new MockedProgram(new string[]
            {
                ParameterUtils.FileArgumentParameter,
                value // Absolute path
            });
            program.Execute();

            Assert.IsNotNull(program.FileConversionRunnerOutputFolder, "Expecting a file path!");

            // We build the folder path from scratch by design
            var path = new FileInfo(value).DirectoryName;
            Assert.AreEqual(path, program.FileConversionRunnerOutputFolder);
        }
Exemplo n.º 10
0
        public void MoreUnnamedParametersCauseError()
        {
            var value1 = "file1";
            var value2 = "file2";

            var program = new MockedProgram(new string[]
            {
                value1,
                value2
            });
            program.Execute();

            program.AssertMainProgramRoutineNotRun();

            Assert.IsNotNull(program.ThrownOptionException, "Expecting an option exception");
            Assert.IsNotNull(program.ThrownOptionException.InnerException);
            Assert.IsInstanceOfType(program.ThrownOptionException.InnerException,
                typeof(DefaultOptionException));
            Assert.AreEqual(2,
                (program.ThrownOptionException.InnerException as DefaultOptionException).OptionsValues.Count(),
                "Expecting 2 conflicting options!");
            Assert.AreEqual(value1,
                (program.ThrownOptionException.InnerException as DefaultOptionException).OptionsValues.ElementAt(0),
                "Conflicting option does not match expected!");
            Assert.AreEqual(value2,
                (program.ThrownOptionException.InnerException as DefaultOptionException).OptionsValues.ElementAt(1),
                "Conflicting option does not match expected!");
        }
Exemplo n.º 11
0
        public void WhenConstructedProgramIsNotRun()
        {
            var program = new MockedProgram(new string[] { });

            Assert.AreEqual(false, program.MainRunRoutineRun, "User should be notified about not feasible execution!");
        }
Exemplo n.º 12
0
        public void CurrentDirectoryWildcardAsOutputPath()
        {
            var program = new MockedProgram(new string[]
            {
                ParameterUtils.FileArgumentParameter,
                "file1",
                ParameterUtils.OutputArgumentParameter,
                PathUtils.CurrentDirectoryWildcard
            });
            program.Execute();

            Assert.AreEqual(false, program.ErrorHandled, "Error should not have been handled!");
            Assert.AreEqual(PathUtils.ApplicationExecutingPath, program.FileConversionRunnerOutputFolder,
                "Not matching output path!");
        }
Exemplo n.º 13
0
        public void WrongOutputPath()
        {
            var program = new MockedProgram(new string[]
            {
                ParameterUtils.FileArgumentParameter,
                "file1",
                ParameterUtils.OutputArgumentParameter,
                "wrongFolder1"
            });
            program.Execute();

            Assert.AreEqual(true, program.ErrorHandled, "Error should have been handled!");
        }
Exemplo n.º 14
0
        public void WhenNoOutputPathIsSpecifiedFilePathIsUsedWhenRelative()
        {
            var value = "file1";

            var program = new MockedProgram(new string[]
            {
                ParameterUtils.FileArgumentParameter,
                value // Relative path
            });
            program.Execute();

            Assert.IsNotNull(program.FileConversionRunnerOutputFolder, "Expecting a file path!");

            var path = new FileInfo(value).DirectoryName;
            Assert.AreEqual(path, program.FileConversionRunnerOutputFolder);
        }
Exemplo n.º 15
0
        public void OutputShortParameterValueIsStored()
        {
            var value = testContext.GetTestDeploymentFolder();

            var program = new MockedProgram(new string[]
            {
                ParameterUtils.FileArgumentParameter,
                "file1",
                ParameterUtils.OutputArgumentShortParameter,
                value
            });
            program.Execute();

            Assert.IsNotNull(program.OutputFolder, "Expecting output folder path!");
            Assert.AreEqual(value, program.OutputFolder, "Not matching output folder path!");
        }
Exemplo n.º 16
0
        public void FileParameterValueIsStored()
        {
            var value = "file";

            var program = new MockedProgram(new string[]
            {
                ParameterUtils.FileArgumentParameter,
                value
            });
            program.Execute();

            Assert.AreEqual(PathUtils.GetAbsolutePath(value), program.FileConversionRunnerFilePath,
                "File conversion routine was expected to be run!");
        }
Exemplo n.º 17
0
        public void RelativeOutputPath()
        {
            // The execution path is different from the deployment path
            // thus we need to retrieve the relative path to deployment folder from execution path
            string relativePathToDeploymentFolder =
                testContext.GetTestDeploymentFolderRelativeToExecutionFolder();

            var program = new MockedProgram(new string[]
            {
                ParameterUtils.FileArgumentParameter,
                "file1",
                ParameterUtils.OutputArgumentParameter,
                relativePathToDeploymentFolder
            });
            program.Execute();

            Assert.AreEqual(false, program.ErrorHandled, "No error expected!");
            Assert.AreEqual(testContext.GetTestDeploymentFolder(),
                program.FileConversionRunnerOutputFolder.StripLastFolderSeparatorFromPath(),
                "Wrong acquired output path!");
        }