示例#1
0
 public void EnsureExceptionIsThrownWhenTwoDefaultCommandAreSpecified()
 {
     using (var testContext = new ApplicationTestContext <ArgumentsTwoDefaultCommands>())
     {
         testContext.Invoking(x => x.RunApplication()).ShouldThrow <InvalidOperationException>();
     }
 }
        public void EnsureMissingIndexedParametersWorksCorrectly()
        {
            using (var testContext = new ApplicationTestContext <AppArgs>())
            {
                testContext.RunApplication("-e -code");
                testContext.VerifyCommandExecuted <GenericCommand <CommandArgs> >();
                testContext.Application.Verify(a => a.MappedCommandLineParameter(AppArgs.ExecuteProperty), Times.Once);

                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.FirstNameProperty, "code"), Times.Never);
                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.CodeProperty, true), Times.Once);
            }
        }
        public void EnsureApplicationParameterWorksCorrectlyEvenWhenIndexedArgumentsAreUsedAndOneIsMissing()
        {
            using (var testContext = new ApplicationTestContext <AppArgs>())
            {
                testContext.RunApplication("-e rudolf -wait");
                testContext.VerifyCommandExecuted <GenericCommand <CommandArgs> >();
                testContext.Application.Verify(a => a.MappedCommandLineParameter(AppArgs.ExecuteProperty), Times.Once);

                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.FirstNameProperty, "rudolf"), Times.Once);
                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.LastNameProperty), Times.Never);
                testContext.Application.Verify(a => a.MappedCommandLineParameter(AppArgs.WaitProperty, true), Times.Once);
            }
        }
        public void EnsureCommandParametersWithNameWorksCorrectly()
        {
            using (var testContext = new ApplicationTestContext <AppArgs>())
            {
                var path = "C:\\SomeDirectory\\SomeFile.txt";
                testContext.RunApplication($"-e firstName=\"{path}\" -code");
                testContext.VerifyCommandExecuted <GenericCommand <CommandArgs> >();
                testContext.Application.Verify(a => a.MappedCommandLineParameter(AppArgs.ExecuteProperty), Times.Once);

                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.FirstNameProperty, path), Times.Once);
                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.CodeProperty, true), Times.Once);
            }
        }
        public void EnsureTwoIndexedParametersWorkInCorrectOrder()
        {
            using (var testContext = new ApplicationTestContext <AppArgs>())
            {
                testContext.RunApplication("-e hans müller -wait");
                testContext.VerifyCommandExecuted <GenericCommand <CommandArgs> >();
                testContext.Application.Verify(a => a.MappedCommandLineParameter(AppArgs.ExecuteProperty), Times.Once);

                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.FirstNameProperty, "hans"), Times.Once);
                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.LastNameProperty, "müller"), Times.Once);
                testContext.Application.Verify(a => a.MappedCommandLineParameter(AppArgs.WaitProperty, true), Times.Once);
            }
        }
        public void EnsureSingleNamedParametersWorkOnWrongIndex()
        {
            using (var testContext = new ApplicationTestContext <AppArgs>())
            {
                testContext.RunApplication("-e lastName=huber -wait");
                testContext.VerifyCommandExecuted <GenericCommand <CommandArgs> >();
                testContext.Application.Verify(a => a.MappedCommandLineParameter(AppArgs.ExecuteProperty), Times.Once);

                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.FirstNameProperty), Times.Never);
                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.LastNameProperty, "huber"), Times.Once);
                testContext.Application.Verify(a => a.MappedCommandLineParameter(AppArgs.WaitProperty, true), Times.Once);
            }
        }
示例#7
0
        public void EnsureQuotePathWorkCorrectly()
        {
            using (var testContext = new ApplicationTestContext <SimpleArgs>())
            {
                var path = "C:\\SomeDirectory\\SomeFile.txt";
                testContext.RunApplication($"\"{path}\"");

                testContext.Application.Verify(a => a.Run(), Times.Once);
                testContext.Application.Verify(a => a.RunWith(It.Is <SimpleArgs>(x => x.Path == path)), Times.Once);
                testContext.Application.Verify(a => a.RunWithCommand(It.IsAny <ICommand>()), Times.Never);

                testContext.Application.Verify(a => a.MappedCommandLineParameter("Path", path), Times.Once);
            }
        }
示例#8
0
        public void EnsureDefaultCommandWithoutParameters()
        {
            using (var testContext = new ApplicationTestContext <TestApplication <ArgumentsTwoDefaultCommands> >())
            {
                testContext.RunApplication();

                testContext.Application.Verify(a => a.Run(), Times.Once);
                testContext.Application.Verify(a => a.RunWithCommand(), Times.Once);

                testContext.Application.Verify(a => a.RunWith(), Times.Never);
                testContext.Application.Verify(a => a.RunWithoutArguments(), Times.Never);

                testContext.Commands.Verify(x => x.Execute("DefaultExecute"), Times.Once);
            }
        }
示例#9
0
        public void EnsureNotQuotePathIsTreatedAsNamedParameter()
        {
            using (var testContext = new ApplicationTestContext <SimpleArgs>())
            {
                var path = "C:\\SomeDirectory\\SomeFile.txt";
                testContext.RunApplication(path);

                testContext.Application.Verify(a => a.Run(), Times.Once);
                testContext.Application.Verify(a => a.RunWith(It.Is <SimpleArgs>(x => x.Path == null)), Times.Once);
                testContext.Application.Verify(a => a.RunWithCommand(It.IsAny <ICommand>()), Times.Never);

                testContext.Application.Verify(a => a.Argument("Path", null), Times.Once);
                testContext.Application.Verify(a => a.UnmappedCommandLineParameter("C", "\\SomeDirectory\\SomeFile.txt"), Times.Once);
            }
        }
示例#10
0
        public void EnsureGenericCommandIsCalledWhenArgumentsAreAvailable()
        {
            using (var testContext = new ApplicationTestContext <TestApplication <ArgumentsTwoDefaultCommands> >())
            {
                testContext.RunApplication("string=butHereComesAValue");

                testContext.Application.Verify(a => a.Run(), Times.Once);
                testContext.Application.Verify(a => a.RunWithCommand(), Times.Once);

                testContext.Application.Verify(a => a.RunWith(), Times.Never);
                testContext.Application.Verify(a => a.RunWithoutArguments(), Times.Never);

                testContext.Commands.Verify(x => x.Execute("GenericExecute"), Times.Once);
                testContext.Commands.Verify(x => x.Argument("string", "butHereComesAValue"), Times.Once);
            }
        }
示例#11
0
        public void EnsureApplicationRunsWithArgumentsWhenNoDefaultCommandIsSpecified()
        {
            using (var testContext = new ApplicationTestContext <TestApplication <ArgumentsWithoutDefaultCommands> >())
            {
                testContext.RunApplication("string=forTheApplication");

                testContext.Application.Verify(a => a.Run(), Times.Once);
                testContext.Application.Verify(a => a.RunWithCommand(), Times.Never);

                testContext.Application.Verify(a => a.RunWith(), Times.Once);
                testContext.Application.Verify(a => a.RunWithoutArguments(), Times.Never);
                testContext.Application.Verify(a => a.Argument("string", "forTheApplication"), Times.Once);

                testContext.Commands.Verify(x => x.Execute("DefaultExecute"), Times.Never);
                testContext.Commands.Verify(x => x.Execute("GenericExecute"), Times.Never);
            }
        }
示例#12
0
        public void EnsureDefaultCommandIsCalledWhenThereAreArgumentsButNoCommand()
        {
            using (var testContext = new ApplicationTestContext <TestApplication <ArgumentsWithGenericDefaultCommand> >())
            {
                testContext.RunApplication("string=someValue");

                testContext.Application.Verify(a => a.Run(), Times.Once);
                testContext.Application.Verify(a => a.RunWithCommand(), Times.Once);

                testContext.Application.Verify(a => a.RunWith(), Times.Never);
                testContext.Application.Verify(a => a.RunWithoutArguments(), Times.Never);

                testContext.Commands.Verify(x => x.Execute("GenericExecute"), Times.Once);
                testContext.Commands.Verify(x => x.Argument("string", "someValue"), Times.Once);
                testContext.Commands.Verify(x => x.Argument("int", It.IsAny <object>()), Times.Never);
            }
        }
示例#13
0
        public void EnsureSpecifiedCommandIsCalled()
        {
            using (var testContext = new ApplicationTestContext <TestApplication <ArgumentsWithGenericCommand> >())
            {
                testContext.RunApplication("execute", "string=someValue", "int=30");

                testContext.Application.Verify(a => a.Run(), Times.Once);
                testContext.Application.Verify(a => a.RunWithCommand(), Times.Once);

                testContext.Application.Verify(a => a.RunWith(), Times.Never);
                testContext.Application.Verify(a => a.RunWithoutArguments(), Times.Never);

                testContext.Commands.Verify(x => x.Execute("GenericExecute"), Times.Once);
                testContext.Commands.Verify(x => x.Argument("string", "someValue"), Times.Once);
                testContext.Commands.Verify(x => x.Argument("int", 30), Times.Once);
            }
        }
示例#14
0
        public void EnsureApplicationRunsWithoutArgumentsWhenNoDefaultCommandIsSpecifiedAndNoArgumentsAreGiven()
        {
            using (var testContext = new ApplicationTestContext <ArgumentsWithoutDefaultCommands>())
            {
                testContext.RunApplication(string.Empty);

                testContext.Application.Verify(a => a.Run(), Times.Once);
                testContext.Application.Verify(a => a.RunWithCommand(It.IsAny <ICommand>()), Times.Never);

                testContext.Application.Verify(a => a.RunWith(It.IsAny <ArgumentsWithoutDefaultCommands>()), Times.Once);
                testContext.Application.Verify(a => a.RunWithoutArguments(), Times.Once);
                testContext.Application.Verify(a => a.Argument("string", null), Times.Once);

                testContext.Commands.Verify(x => x.Execute("DefaultExecute"), Times.Never);
                testContext.Commands.Verify(x => x.Execute("GenericExecute"), Times.Never);
            }
        }
        public void EnsureTwoNamedParametersWorkInAnyOrder()
        {
            using (var testContext = new ApplicationTestContext <AppArgs>())
            {
                testContext.RunApplication("-e lastname=engelbert firstname=peter -code");
                testContext.VerifyCommandExecuted <GenericCommand <CommandArgs> >();
                testContext.Application.Verify(a => a.MappedCommandLineParameter(AppArgs.ExecuteProperty), Times.Once);

                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.FirstNameProperty, "peter"), Times.Once);
                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.LastNameProperty, "engelbert"), Times.Once);
                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.CodeProperty, true), Times.Once);
            }

            using (var testContext = new ApplicationTestContext <AppArgs>())
            {
                testContext.RunApplication("-e firstname=peter -code lastname=engelbert");
                testContext.VerifyCommandExecuted <GenericCommand <CommandArgs> >();
                testContext.Application.Verify(a => a.MappedCommandLineParameter(AppArgs.ExecuteProperty), Times.Once);

                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.FirstNameProperty, "peter"), Times.Once);
                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.LastNameProperty, "engelbert"), Times.Once);
                testContext.Application.Verify(a => a.MappedCommandLineParameter(CommandArgs.CodeProperty, true), Times.Once);
            }
        }
示例#16
0
 public EnderecoRepository(ApplicationTestContext context)
 {
     this.context = context;
 }