예제 #1
0
        public void User_Can_Delete_a_Patron()
        {
            DeletePatron command = new DeletePatron("Delete User", TestHelper.Later)
            {
                PatronId = Guid.NewGuid()
            };

            var           eventBus       = new Mock <IEventBus>();
            PatronDeleted publishedEvent = null;

            eventBus.Setup(bus => bus.Publish(It.IsAny <PatronDeleted>()))
            .Callback <PatronDeleted>(evnt => publishedEvent = evnt)
            .Verifiable();

            ICommandHandler <DeletePatron> handler = new PatronCommandHandler(eventBus.Object);

            handler.Handle(command);

            Assert.NotEqual(Guid.Empty, command.Id);
            eventBus.VerifyPublish <PatronDeleted>(Times.Once());
            Assert.NotNull(publishedEvent);
            Assert.Equal(command.Id, publishedEvent.SourceId);
            Assert.Equal(command.PatronId, publishedEvent.PatronId);
            Assert.NotEqual(command.Id, publishedEvent.Id);
            Assert.NotEqual(command.Id, publishedEvent.PatronId);
            Assert.NotEqual(Guid.Empty, publishedEvent.PatronId);
            Assert.NotEqual(Guid.Empty, publishedEvent.Id);
        }
예제 #2
0
        public void Handle(DeletePatron command)
        {
            var evnt = new PatronDeleted(command.GeneratedBy, command.GeneratedOn, command.Id)
            {
                PatronId = command.PatronId
            };

            eventBus.Publish(evnt);
        }