Пример #1
0
        public async Task No_exception_is_thrown_when_no_handler_for_TCommand_is_found()
        {
            var sut = CreateSystemUnderTest();

            sut.SubscribeToCommand <TestCommand>();

            var message = fixture.Create <CommandMessage <TestCommand> >();

            mockScope.Setup(p => p.Resolve <ICommandHandler <TestCommand> >()).Returns(() => null);

            await testBusEngine.HandleCommand(message);

            mockScope.Verify(p => p.Resolve <ICommandHandler <TestCommand> >(), Times.Once);
        }
        public void Commands_are_pushed_into_observable()
        {
            var busEngine = new InMemoryBusEngine();
            var builder   = new NybusBusBuilder(busEngine);

            var list = new List <TestCommand>();

            var disposable = builder.ObserveCommand <TestCommand>().Select(c => c.Message).Subscribe(list.Add);

            var observable = scheduler.CreateHotObservable(
                OnNext(500, fixture.Create <CommandMessage <TestCommand> >()),
                OnNext(600, fixture.Create <CommandMessage <TestCommand> >()),
                OnNext(1000, fixture.Create <CommandMessage <TestCommand> >()),
                OnNext(1200, fixture.Create <CommandMessage <TestCommand> >()),
                OnNext(1500, fixture.Create <CommandMessage <TestCommand> >())
                );

            var results = scheduler.Start(() => observable.Do(msg => Task.WaitAll(busEngine.HandleCommand(msg))).Select(c => c.Command), 100, 150, 3000);

            disposable.Dispose();

            for (int i = 0; i < list.Count; i++)
            {
                Assert.That(list[i], Is.SameAs(results.Messages[i].Value.Value));
            }
        }