Exemple #1
0
        public async Task RunASecondCommandWhileFirstCommandIsRunning()
        {
            // Create a command stub which sleeps for some time
            var commandStub2 = new ICommandStub2
                                    {
                                        Args = "arg1 arg2 arg3",
                                        Name = "stubcmd2",
                                        Help = "sample help!"
                                    };
            var commandHandler2 = new ICommandHandlerStub2
                                      {
                                          ExpectedCommandArgs = commandStub2.Args,
                                          ExpectedCommandName = commandStub2.Name,
                                          ExpectedCommandHelp = commandStub2.Help,
                                          ExpectedExecuteResult = () =>
                                              {
                                                  Thread.Sleep(5 * 1000);
                                                  return false;
                                              }
                                      };

            var cmdsvc = new CommandService(
                new List<ICommand> { this.commandStub, commandStub2 },
                new List<object> { this.commandHandlerStubReturnsTrue, commandHandler2 });
            var result2 = cmdsvc.Run(commandStub2.Name + " " + commandStub2.Args);

            // Trigger a second command meanwhile, validate that it shouldn't block
            var result = await cmdsvc.Run(this.commandStub.Name + " " + this.commandStub.Args);
            result.Should().BeTrue();

            result2.Wait();
            result2.Result.Should().BeFalse();
        }
Exemple #2
0
        public async Task RunASingleCommandWhichReturnsFalse()
        {
            var cmdsvc = new CommandService(new List<ICommand> { this.commandStub }, new List<object> { this.commandHandlerStubReturnsFalse });
            var result = await cmdsvc.Run(this.commandStub.Name + " " + this.commandStub.Args);

            result.Should().BeFalse();
        }
Exemple #3
0
 public SourceCommandTests()
 {
     this.commandStub = new ICommandStub
                             {
                                 Args = "arg1 arg2 arg3",
                                 Name = "stubcmd",
                                 Help = "sample help!"
                             };
     this.commandHandlerStubReturnsTrue = new ICommandHandlerStub
                                               {
                                                   ExpectedCommandArgs = this.commandStub.Args,
                                                   ExpectedCommandName = this.commandStub.Name,
                                                   ExpectedCommandHelp = this.commandStub.Help,
                                                   ExpectedExecuteResult = () => true
                                               };
     var failCommandStub = new ICommandStub2
                             {
                                 Args = "arg1 arg2 arg3",
                                 Name = "stubcmd2",
                                 Help = "sample help!"
                             };
     var commandHandlerStubReturnsFalse = new ICommandHandlerStub2
                                               {
                                                   ExpectedCommandArgs = failCommandStub.Args,
                                                   ExpectedCommandName = failCommandStub.Name,
                                                   ExpectedCommandHelp = failCommandStub.Help,
                                                   ExpectedExecuteResult = () => false
                                               };
     this.commandService = new CommandService(
         new List<ICommand> { this.commandStub, failCommandStub }, new List<object> { this.commandHandlerStubReturnsTrue, commandHandlerStubReturnsFalse });
     this.sourceCommandHandler = new SourceCommandHandler(this.commandService);
 }
        public DefinekeyCommandTests()
        {
            this.platformFacade = Substitute.For<IPlatformFacade>();
            this.keyMapService = new KeyMapService(this.platformFacade);

            var commandStub = new ICommandStub
                                    {
                                        Args = "arg1",
                                        Name = "testCommand",
                                        Help = "sample help!"
                                    };
            var commandHandlerStub = new ICommandHandlerStub
                       {
                           ExpectedCommandArgs = commandStub.Args,
                           ExpectedCommandName = commandStub.Name,
                           ExpectedCommandHelp = commandStub.Help,
                           ExpectedExecuteResult = () => true
                       };
            this.commandService = new CommandService(
                new List<ICommand> { commandStub }, new List<object> { commandHandlerStub });
        }
Exemple #5
0
 public void EmptyCommandSpecThrowsArgumentException()
 {
     var cmdsvc = new CommandService(new List<ICommand> { this.commandStub }, new List<object> { this.commandHandlerStubReturnsFalse });
     Func<Task> run = async () => await cmdsvc.Run(string.Empty);
     run.ShouldThrow<ArgumentException>();
 }
Exemple #6
0
 public void MalformedCommandSpecThrowsInvalidCommandException()
 {
     var cmdsvc = new CommandService(new List<ICommand> { this.commandStub }, new List<object> { this.commandHandlerStubReturnsFalse });
     const string InputCmd = " ";
     Func<Task> run = async () => await cmdsvc.Run(InputCmd);
     run.ShouldThrow<InvalidCommandException>().And.Data["InputCommand"].Should().Be(InputCmd);
 }