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!");
        }
        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!");
        }
        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!");
        }
        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!");
        }
        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();
        }
        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();
            }
        }
        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!");
        }
        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();
        }
        public void WhenCalledWithNoParameterThenHelpIsShown()
        {
            var program = new MockedProgram(new string[]{ });
            program.Execute();

            Assert.AreEqual(true, program.HelpContentDisplayed, "Help content should have been displayed!");
            program.AssertProgramNotRun();
        }
        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!");
        }
        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!");
        }
        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!");
        }
        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!");
        }
        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);
        }
        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);
        }
        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!");
        }