コード例 #1
0
        public void CreateNewCommandFromCommandSourceWithNoMutator()
        {
            var source = new EmptyCommand
            {
                Id              = Guid.NewGuid(),
                CorrelationId   = "ABC123",
                CurrentUser     = "******",
                OccurredTimeUtc = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1))
            };

            var created = source.CreateNewCommand <EmptyCommand>();

            created.Should().NotBeNull("because the created instance should exist");

            // Verify new values are populated.

            created.Id.Should().NotBe(source.Id, "because the id should be a new value");
            created.Id.Should().NotBe(default(Guid), "because the id should be populated");
            created.OccurredTimeUtc.Should().NotBe(source.OccurredTimeUtc, "because the occurred time should be a new value");
            created.OccurredTimeUtc.Should().NotBe(default(DateTime), "because the occurred time should be populated");

            // Verify copied values are copied.

            created.CorrelationId.Should().Be(source.CorrelationId, "because the correlation identifier should be copied");
            created.CurrentUser.Should().Be(source.CurrentUser, "because the current user should be copied");
        }
コード例 #2
0
 public MultiPult()
 {
     _buttons = new ICommand[2];
     for (var i = 0; i < _buttons.Length; i++)
     {
         _buttons[i] = new EmptyCommand();
     }
     _commandsHistory = new Stack <ICommand>();
 }
コード例 #3
0
 public RemoteControl()
 {
     for (var i = 0; i < 5; i++)
     {
         onSlots[i]  = new EmptyCommand();
         offSlots[i] = new EmptyCommand();
         undoCommand = new EmptyCommand();
     }
 }
コード例 #4
0
            public void should_create_message_dispatch_for_empty_message()
            {
                var command          = new EmptyCommand();
                var transportMessage = command.ToTransportMessage();

                transportMessage.Content = Stream.Null;
                var dispatch = _bus.CreateMessageDispatch(transportMessage);

                dispatch.Message.ShouldEqualDeeply(command);
            }
コード例 #5
0
 public IUndoableCommand Pop()
 {
     if (_commands.First != null)
     {
         IUndoableCommand first = _commands.First.Value;
         _commands.RemoveFirst();
         return(first);
     }
     return(EmptyCommand.GetEmptyCommand());
 }
コード例 #6
0
ファイル: CommandFixture.cs プロジェクト: rh/mix
 public void Write()
 {
     Command command = new EmptyCommand();
     var context = new Context();
     var writer = new StringWriter();
     context.Output = writer;
     command.Context = context;
     command.Execute();
     var expected = string.Format("12{0}3{0}", Environment.NewLine);
     Assert.AreEqual(expected, writer.ToString());
 }
コード例 #7
0
        protected override async Task <List <CurrencyView> > CommandExecute(EmptyCommand command)
        {
            List <CurrencyView> views = null;
            var currencies            = await _context.Currencies.ToListAsync();

            if (currencies != null)
            {
                views = _mapper.Map <List <CurrencyView> >(currencies);
            }
            return(views);
        }
コード例 #8
0
        /// <summary>
        /// Give the number of the devices to be controlled as a parameter to the constructor.
        /// </summary>
        /// <param name="numberOfDevicesToBeControlled"></param>
        public RemoteControl(int numberOfDevicesToBeControlled)
        {
            OnCommands  = new Command[numberOfDevicesToBeControlled];
            OffCommands = new Command[numberOfDevicesToBeControlled];

            Command emptyCommand = new EmptyCommand();

            // Initialize all the command slots with an empty command.
            for (int i = 0; i < numberOfDevicesToBeControlled; i++)
            {
                SetCommand(i, emptyCommand, emptyCommand);
            }
        }
コード例 #9
0
        public static int Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name        = "Geek Cafe AWS CDK DevOps CLI",
                Description = "Wrapper for AWS CDK"
            };

            var options = new Commands.Options.Common();

            options.Register(app, "");

            // register the commands
            app.RegisterCommands();

            //
            app.OnExecute(() =>
            {
                // if we get here then a registered command wasn't found
                // so we can run the default
                var cmd    = new EmptyCommand(options);
                var result = cmd.Execute();

                if (result == (int)ExitCodes.MISSING_OPTIONS)
                {
                    app.ShowHelp();
                }

                return(result);
            });

            var exitCode = 0;

            try
            {
                // attempt to execute a command based on what we registred above
                Utilities.Logger.Log($"{app.Name} starting exection.");
                exitCode = app.Execute(args);
                Utilities.Logger.Log($"{app.Name} executed successfully.");
            }
            catch (Exception ex)
            {
                // something bad happened
                Utilities.Logger.Log($"{app.Name} executed with errors.");
                Utilities.Logger.Log($"Fatel Exception {ex.Message}");
                exitCode = (int)ExitCodes.FATEL_ERROR;
            }

            return(exitCode);
        }
コード例 #10
0
            public void should_dispatch_received_empty_message()
            {
                var command       = new EmptyCommand();
                var invokerCalled = false;

                SetupDispatch(command, _ => invokerCalled = true);

                var transportMessageReceived = command.ToTransportMessage(_peerUp);

                transportMessageReceived.Content = Stream.Null;
                _transport.RaiseMessageReceived(transportMessageReceived);

                invokerCalled.ShouldBeTrue();
            }
コード例 #11
0
ファイル: BenchmarksTests.cs プロジェクト: SwicaseJia/EasyBus
        public void Command()
        {
            var command = new EmptyCommand();

            var step = Step.Create("CommandAsync", async context =>
            {
                await _commandBus.SendAsync(command);
                return(Response.Ok());
            });

            var scenario = CreateScenario("Command performance", new[] { step });

            NBomberRunner.RegisterScenarios(scenario).RunTest();
        }
コード例 #12
0
        public void Digger_name_that_doesnt_exist_is_invalid()
        {
            var command = new EmptyCommand
            {
                GameState  = gameState,
                DiggerName = MISSING_DIGGER_NAME
            };

            commandHandler.Handle(command);

            var output = ConsoleBufferHelper.GetText(proc.Output);

            output.ShouldBe($"Could not find digger named {MISSING_DIGGER_NAME}");
        }
コード例 #13
0
ファイル: BaseCommandTests.cs プロジェクト: vgrinin/gin
        public void TestInit()
        {
            _context              = new ExecutionContextMock();
            _testCommand          = new EmptyCommand();
            _testCommand.UserInfo = new UserInfoEmbedded
            {
                MessageGuid = "guid",
                MessageText = "text"
            };

            Logging.Logging log = new Logging.Logging();
            _logger = new ExecutionLoggerMock();
            log.AddLogger(_logger);
            _context.Log = log;
        }
コード例 #14
0
        protected override async Task <List <ExchangePairView> > CommandExecute(EmptyCommand command)
        {
            List <ExchangePairView> views = null;
            var entities = await _context.Pairs
                           .Include(x => x.CurrencyFrom)
                           .Include(x => x.CurrencyTo)
                           .Include(x => x.Exchange)
                           .ToListAsync();

            if (entities != null)
            {
                views = _mapper.Map <List <ExchangePairView> >(entities);
            }
            return(views);
        }
コード例 #15
0
ファイル: Input.cs プロジェクト: hc-alex/rollback
        public Input(Bank bank, ConsoleMessage message)
        {
            _currentState = new CurrentState();

            _preparedCommands = new Dictionary <string, Command>
            {
                ["accounts"] = new GetAccountsCommand(bank, _currentState, message),
                ["open"]     = new OpenAccountCommand(bank, _currentState, message),
                ["transfer"] = new TransferCommand(bank, _currentState, message),
                ["close"]    = new CloseAccountCommand(bank, _currentState, message),
                ["undo"]     = new UndoCommand(bank, _currentState, message),
                ["abort"]    = new AbortCommand(bank, _currentState, message)
            };

            _emptyCommand = new EmptyCommand(bank, _currentState, message);
        }
コード例 #16
0
        public void ClearTest()
        {
            var light    = new Light();
            var command0 = new OnCommand(light);
            var command1 = new OnCommand(light);
            var command2 = new OnCommand(light);
            var command3 = new OnCommand(light);

            _undoStack.Push(command0);
            _undoStack.Push(command1);
            _undoStack.Push(command2);
            _undoStack.Push(command3);

            _undoStack.Clear();

            var ret = _undoStack.Pop();

            Assert.AreEqual(ret, EmptyCommand.GetEmptyCommand());
        }
コード例 #17
0
    public void AbilitiesInitialized(List <Ability> abilities)
    {
        if (maxAllowedAbilityNumber < abilities.Count)
        {
            Debug.Log("Error in ability count!");
        }

        abilityCommands = new Command[maxAllowedAbilityNumber];

        for (int i = 0; i < maxAllowedAbilityNumber; i++)
        {
            if (i >= abilities.Count)
            {
                abilityCommands[i] = new EmptyCommand();
            }
            else
            {
                abilityCommands[i] = new AbilityCommand(abilities[i].abilityData.abilityName);
            }
        }
    }
コード例 #18
0
        public void should_read_empty_message()
        {
            var transportMessage = new EmptyCommand().ToTransportMessage();

            var outputStream = new CodedOutputStream();

            outputStream.WriteTransportMessage(transportMessage);

            var inputStream  = new CodedInputStream(outputStream.Buffer, 0, outputStream.Position);
            var deserialized = inputStream.ReadTransportMessage();

            deserialized.Id.ShouldEqual(transportMessage.Id);
            deserialized.MessageTypeId.ShouldEqual(transportMessage.MessageTypeId);
            deserialized.Content.ShouldEqual(Stream.Null);
            deserialized.Originator.ShouldEqualDeeply(transportMessage.Originator);
            deserialized.Environment.ShouldEqual(transportMessage.Environment);
            deserialized.WasPersisted.ShouldEqual(transportMessage.WasPersisted);

            var deserializedMessage = deserialized.ToMessage() as EmptyCommand;

            deserializedMessage.ShouldNotBeNull();
        }
コード例 #19
0
        /// <summary>
        /// Executes commands from the console.
        /// </summary>
        /// <param name="input">The string containing the command and parameters.</param>
        /// <returns>Returns the execution results or error messages.</returns>
        public void Execute(string input)
        {
            if (input == "undo")
            {
                Unexecute();
                return;
            }
            else if (input == "redo")
            {
                Reexecute();
                return;
            }

            bool UnrecognizedCommand = false;

            string[] arguments = input.Split(new Char[] { ' ' });
            ICommand cmd;

            if (!CommandHandlers.ContainsKey(arguments[0]))
            {
                cmd = new EmptyCommand();
                UnrecognizedCommand = true;
            }
            else
            {
                cmd = CommandHandlers[arguments[0]]();
            }

            if (!UnrecognizedCommand)
            {
                UndoneCommands.Clear();
            }
            if (cmd.Execute(arguments))
            {
                Commands.Push(cmd);
            }
            Console.WriteLine(cmd.getOutput());
            Console.Prompt(Prompt, Execute);
        }
コード例 #20
0
        public void should_read_empty_message()
        {
            var transportMessage = new EmptyCommand().ToTransportMessage();

            var bufferWriter = new ProtoBufferWriter();

            bufferWriter.WriteTransportMessage(transportMessage);

            var bufferReader = new ProtoBufferReader(bufferWriter.Buffer, bufferWriter.Position);
            var deserialized = bufferReader.ReadTransportMessage();

            deserialized.Id.ShouldEqual(transportMessage.Id);
            deserialized.MessageTypeId.ShouldEqual(transportMessage.MessageTypeId);
            deserialized.Content.ShouldEqual(Stream.Null);
            deserialized.Originator.ShouldEqualDeeply(transportMessage.Originator);
            deserialized.Environment.ShouldEqual(transportMessage.Environment);
            deserialized.WasPersisted.ShouldEqual(transportMessage.WasPersisted);

            var deserializedMessage = deserialized.ToMessage() as EmptyCommand;

            deserializedMessage.ShouldNotBeNull();
        }
コード例 #21
0
        public void PushPopTest()
        {
            var light    = new Light();
            var command0 = new OnCommand(light);
            var command1 = new OnCommand(light);
            var command2 = new OnCommand(light);
            var command3 = new OnCommand(light);

            _undoStack.Push(command0);
            _undoStack.Push(command1);
            _undoStack.Push(command2);
            _undoStack.Push(command3);

            var retCommand3 = _undoStack.Pop();
            var retCommand2 = _undoStack.Pop();
            var retCommand1 = _undoStack.Pop();
            var retCommand0 = _undoStack.Pop();

            Assert.AreEqual(retCommand0, EmptyCommand.GetEmptyCommand());
            Assert.AreEqual(command1, retCommand1);
            Assert.AreEqual(command2, retCommand2);
            Assert.AreEqual(command3, retCommand3);
        }
コード例 #22
0
    public void DecodeMessage(string s)
    {
        if (_cl != null)
        {
            if (s.Length > 5)
            {
                PlayerCommandsData playerData = JsonConvert.DeserializeObject <PlayerCommandsData>(s);
                if (playerData.commands != null)
                {
                    for (int i = 0; i < playerData.commands.Count; i++)
                    {
                        int    type     = int.Parse(playerData.commands[i][0].ToString());
                        string lCommand = playerData.commands[i].Remove(0, 1);
                        print(playerData.commands[i]);
                        switch (type)
                        {
                        case 0:
                            AttackCommand c = JsonConvert.DeserializeObject <AttackCommand>(lCommand);
                            ServiceLocator.GetService <CommandManager>().allCommands.Add(c);
                            break;

                        case 1:
                            BuildCommand bc = JsonConvert.DeserializeObject <BuildCommand>(lCommand);
                            ServiceLocator.GetService <CommandManager>().allCommands.Add(bc);
                            print(ServiceLocator.GetService <CommandManager>().allCommands.Count);

                            break;

                        case 2:
                            HireCommand hc = JsonConvert.DeserializeObject <HireCommand>(lCommand);
                            ServiceLocator.GetService <CommandManager>().allCommands.Add(hc);

                            break;

                        case 3:
                            PauseCommand pc = JsonConvert.DeserializeObject <PauseCommand>(lCommand);
                            ServiceLocator.GetService <CommandManager>().allCommands.Add(pc);

                            break;

                        case 4:
                            MoveCommand mc = JsonConvert.DeserializeObject <MoveCommand>(lCommand);
                            ServiceLocator.GetService <CommandManager>().allCommands.Add(mc);

                            break;

                        case 5:
                            EmptyCommand ec = JsonConvert.DeserializeObject <EmptyCommand>(lCommand);
                            ServiceLocator.GetService <CommandManager>().allCommands.Add(ec);
                            break;
                        }
                        //Command c = (Command)JsonConvert.DeserializeObject(playerData.commands[i],
                        //    CommandManager.commandTypes[type].GetType());
                    }
                    ProccessedCommands();
                }
            }
            else
            {
                //TODO: change message checks
                if (s == "inc")
                {
                    turnData = ServiceLocator.GetService <CommandManager>().CreateTurnData(turn + 2, _playerRef.id);
                    string msg = JsonConvert.SerializeObject(turnData);
                    _cl.SendMessage(msg);
                    turn++;
                }
                else if (s == "0")
                {
                    _playerRef.id = 0;
                }
                else if (s == "1")
                {
                    _playerRef.id = 1;
                }
                else
                {
                }
            }
        }
    }
コード例 #23
0
 public Void VisitEmptyCommand(EmptyCommand ast, Frame frame)
 {
     return(null);
 }
        /// <summary>
        /// Creates a command according to the user input
        /// </summary>
        /// <param name="command">Command to be created</param>
        /// <returns>The created command</returns>
        public ICommand GetCommand(string command)
        {
            if (!this.CommandsList.ContainsKey(command))
            {
                ICommand commandExecutor = null;

                switch (command)
                {
                    case "help":
                        {
                            commandExecutor = new CheatCommand(this.Data, this.Notifier, this.NumberGenerator);
                            break;
                        }

                    case "start":
                        {
                            commandExecutor = new InitializeGameCommand(this.Data, this.Notifier, this.NumberGenerator);
                            break;
                        }

                    case "commands":
                        {
                            commandExecutor = new DisplayCommandsListCommand(this.Notifier);
                            break;
                        }

                    case "top":
                        {
                            commandExecutor = new DisplayScoreboardCommand(this.Scoreboard);
                            break;
                        }

                    case "quit":
                        {
                            commandExecutor = new QuitGameCommand(this.Notifier);
                            break;
                        }

                    case "exit":
                        {
                            commandExecutor = new ExitGameCommand(this.Notifier);
                            break;
                        }

                    case "empty":
                        {
                            commandExecutor = new EmptyCommand();
                            break;
                        }

                    default:
                        {
                            commandExecutor = this.ProcessGuessAndReturnAppropriateCommand(command);
                            break;
                        }
                }

                this.CommandsList.Add(command, commandExecutor);

                return commandExecutor;
            }
            else
            {
                return this.CommandsList[command];
            }
        }
コード例 #25
0
ファイル: CommandManager.cs プロジェクト: nikitabm/RTS
 public void CommandExecute(EmptyCommand c)
 {
     Debug.Log(c.ToString());
 }
コード例 #26
0
ファイル: CommandFixture.cs プロジェクト: rh/mix
 public void CommandToString()
 {
     Command command = new EmptyCommand();
     Assert.AreEqual("empty", command.ToString());
 }
コード例 #27
0
ファイル: CommandFixture.cs プロジェクト: rh/mix
 public void Execute()
 {
     Command command = new EmptyCommand();
     Assert.AreEqual(0, command.Execute());
 }
コード例 #28
0
 public Void VisitEmptyCommand(EmptyCommand ast, Void arg)
 {
     return(null);
 }
コード例 #29
0
ファイル: BaseCommandTests.cs プロジェクト: vgrinin/gin
        public void TestInit()
        {
            _context = new ExecutionContextMock();
            _testCommand = new EmptyCommand();
            _testCommand.UserInfo = new UserInfoEmbedded
            {
                MessageGuid = "guid",
                MessageText = "text"
            };

            Logging.Logging log = new Logging.Logging();
            _logger = new ExecutionLoggerMock();
            log.AddLogger(_logger);
            _context.Log = log;
        }
コード例 #30
0
        public void CommandWithNoParamaters_AndEmptyParameters()
        {
            ICommand command = new EmptyCommand();

            classUnderTest.Hydrate(ref command, new object());
        }