Beispiel #1
0
        public async Task WhenProcessingMultipleCommandThenCommandsAreProcessed()
        {
            // Arrange
            Mock <ISpy> spy = new Mock <ISpy>(MockBehavior.Strict);

            spy.Setup(s => s.Spy("MultipleCommand1"));
            spy.Setup(s => s.Spy("MultipleCommand2"));
            MultipleCommandCommandHandler commandCommandHandler = new MultipleCommandCommandHandler(spy.Object);

            this.SetupHandler <MultipleCommand1>(commandCommandHandler);
            MessageProcessor processor = this.CreatTestableProcessor();
            MultipleCommand1 command1  = new MultipleCommand1();
            MultipleCommand2 command2  = new MultipleCommand2();

            // Act & assert
            await processor.ProcessAsync(command1);

            spy.Verify(h => h.Spy("MultipleCommand1"), Times.Once());
            spy.Verify(h => h.Spy("MultipleCommand2"), Times.Never());

            // Handler must be configured now to avoid incorrect descriptor creation
            this.SetupHandler <MultipleCommand2>(commandCommandHandler);
            await processor.ProcessAsync(command2);

            spy.Verify(h => h.Spy("MultipleCommand1"), Times.Once());
            spy.Verify(h => h.Spy("MultipleCommand2"), Times.Once());

            await processor.ProcessAsync(command2);

            spy.Verify(h => h.Spy("MultipleCommand1"), Times.Once());
            spy.Verify(h => h.Spy("MultipleCommand2"), Times.Exactly(2));
        }
Beispiel #2
0
 public void Handle(MultipleCommand2 command)
 {
     this.spy.Spy("MultipleCommand2");
 }