Example #1
0
        public MessageHandling(IEventstore es, FlashcardboxDb db)
        {
            _mp = new MessagePump(es);

            _mp.On <SyncCommand>().Load(new SyncContextManagement(es)).Do(new SyncProcessor(db));
            _mp.On <SelectDueCardCommand>().Load(new SelectDueCardContextManager(es)).Do(new SelectDueCardProcessor());
            _mp.On <RegisterAnswerCommand>().Load(new RegisterAnswerContextManager(es)).Do(new RegisterAnswerProcessor());

            _mp.On <DueCardQuery>().Load(new DueCardContextManager(es)).Do(new DueCardProcessor());
            _mp.On <ProgressQuery>().Load(new ProgressContextManager(es)).Do(new ProgressProcessor());
        }
Example #2
0
        public void Fluent()
        {
            var es  = new InMemoryEventstore();
            var sut = new MessagePump(es);


            sut.On <AddTodoCmd>().Use(new AddTodoCmdCtxModelManager()).Do(new AddTodoCmdProcessor());
            sut.On <AllTodosQuery>().Use(new AllTodosQueryCtxModelManager()).Do(new AllTodosQueryProcessor());
            var checkToDoCtxModelManager = new CheckTodoCmdCtxModelManager();

            sut.On <CheckTodoCmd>().Load(checkToDoCtxModelManager).Finally(checkToDoCtxModelManager).Do(new CheckTodoCmdProcessor());


            // add a couple of tasks
            var response = sut.Handle(new AddTodoCmd {
                Subject = "foo"
            });

            Assert.IsType <Success>(response.Msg);
            Assert.Empty(response.Notifications);

            response = sut.Handle(new AddTodoCmd {
                Subject = "bar"
            });
            Assert.IsType <Success>(response.Msg);
            Assert.Empty(response.Notifications);

            response = sut.Handle(new AddTodoCmd {
                Subject = "baz"
            });
            Assert.IsType <Success>(response.Msg);
            Assert.Empty(response.Notifications);

            // what are the currently active tasks?
            response = sut.Handle(new AllTodosQuery());
            Assert.Empty(response.Notifications);
            var result = response.Msg as AllTodosQueryResult;

            Assert.Equal(new[] { "foo", "bar", "baz" }, result.Todos.Select(x => x.Description));

            // check a task as done
            response = sut.Handle(new CheckTodoCmd {
                Id = result.Todos[0].Id
            });
            Assert.IsType <Success>(response.Msg);
            Assert.Empty(response.Notifications);

            // ...and it still gets listed
            response = sut.Handle(new AllTodosQuery());
            Assert.Empty(response.Notifications);
            result = response.Msg as AllTodosQueryResult;
            Assert.Equal(new[] { "foo, done", "bar", "baz" }, result.Todos.Select(x => x.Description));

            // ...unless done tasks are explicitly excluded
            response = sut.Handle(new AllTodosQuery {
                ActiveOnly = true
            });
            Assert.Empty(response.Notifications);
            result = response.Msg as AllTodosQueryResult;
            Assert.Equal(new[] { "bar", "baz" }, result.Todos.Select(x => x.Description));

            // check all remaining tasks - and a notification gets created, once all are done
            sut.Handle(new CheckTodoCmd {
                Id = result.Todos[0].Id
            });
            response = sut.Handle(new CheckTodoCmd {
                Id = result.Todos[1].Id
            });
            Assert.IsType <Success>(response.Msg);
            Assert.Single(response.Notifications);
            Assert.IsType <FreeCapacityAvailableNotification>(response.Notifications[0]);
        }