public void Command_targeted_to_certain_object_are_executed()
        {
            var executorMock = new Mock<ICommandExecutor>();
            var targetObjectId = ObjectId.NewUniqueId();
            var command = new TestingCommand(targetObjectId);
            var collection = new CommandsByObjectCollection();
            collection.Add(command);

            collection.ExecuteCommands(targetObjectId, executorMock.Object, null);

            executorMock.Verify(x => x.Execute(command, null), Times.Once());
        }
Esempio n. 2
0
        public void Command_not_targeted_to_certain_object_are_not_executed()
        {
            var executorMock   = new Mock <ICommandExecutor>();
            var targetObjectId = ObjectId.NewUniqueId();
            var command        = new TestingCommand(ObjectId.NewUniqueId());
            var collection     = new CommandsByObjectCollection();

            collection.Add(command);

            collection.ExecuteCommands(targetObjectId, executorMock.Object, null);

            executorMock.Verify(x => x.Execute(command, null), Times.Never());
        }
        public static Dictionary <string, ICommand> FindICommands()
        {
            // Just hard code the list for now
            var      commandLookup = new Dictionary <string, ICommand>();
            ICommand each;

            each = new CloudScriptListener();
            commandLookup.Add(each.commandKey.ToLower(), each);

            each = new KillTaskCommand();
            commandLookup.Add(each.commandKey.ToLower(), each);

            each = new TestingCommand();
            commandLookup.Add(each.commandKey.ToLower(), each);

            return(commandLookup);
        }
Esempio n. 4
0
        public async Task SendingMessageSerializesEncodesMessageAndCallsSendOnClient()
        {
            Message capturedMessage = null;

            A.CallTo(() => _queueClient.SendAsync(A <Message> .Ignored))
            .Invokes((Message message) => capturedMessage = message);

            var command = new TestingCommand("bar");

            await _commandQueueClient.Send("test-queue", command);

            var json  = JsonConvert.SerializeObject(command);
            var bytes = Encoding.UTF8.GetBytes(json);

            A.CallTo(() => _queueClient.SendAsync(A <Message> .Ignored))
            .MustHaveHappenedOnceExactly();

            Assert.IsNotNull(capturedMessage, "Failed to capture the sent message");
            Assert.AreEqual(bytes, capturedMessage.Body);
        }
Esempio n. 5
0
        public async Task SubscribePumpsNewObservableMessagesFromMessageHandler()
        {
            var receivedMessages = new List <IActionableMessage <ICommand> >();

            _commandQueueClient
            .GetCommandQueueStream("test-queue")
            .Subscribe(message => receivedMessages.Add(message));

            A.CallTo(() => _queueClient.RegisterMessageHandler(
                         A <Func <Message, CancellationToken, Task> > .Ignored,
                         A <MessageHandlerOptions> .Ignored))
            .MustHaveHappenedOnceExactly();
            Assert.IsNotNull(_messageHandler, "Failed to capture the message handler");

            var command = new TestingCommand("bar");

            await SimulateCommandDelivery(command);

            Assert.AreEqual(1, receivedMessages.Count);
            Assert.AreEqual(command.Foo, ((TestingCommand)receivedMessages[0].ReceivedCommand).Foo);
        }
Esempio n. 6
0
 public MainVM(FoodAppContext context, IDataRepository repo)
 {
     _dbContext     = context;
     _repo          = repo;
     TestingCommand = new TestingCommand(this);
 }