Exemplo n.º 1
0
        public void User_Can_Update_a_Patron_Header()
        {
            UpdatePatronHeader command = new UpdatePatronHeader("Update User", TestHelper.Now)
            {
                PatronId    = Guid.NewGuid(),
                DisplayName = "Updated Test Patron",
                IsAnonymous = true,
                PatronType  = "Updated Type"
            };

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

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

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

            handler.Handle(command);

            Assert.NotEqual(Guid.Empty, command.Id);
            eventBus.VerifyPublish <PatronHeaderChanged>(Times.Once());
            Assert.NotNull(publishedEvent);
            Assert.Equal("Updated Test Patron", publishedEvent.DisplayName);
            Assert.Equal(command.IsAnonymous, publishedEvent.IsAnonymous);
            Assert.Equal(command.PatronType, publishedEvent.PatronType);
            Assert.Equal(command.Id, publishedEvent.SourceId);
            Assert.Equal(command.PatronId, publishedEvent.PatronId);
            Assert.NotEqual(command.Id, publishedEvent.Id);
            Assert.Equal("Update User", publishedEvent.GeneratedBy);
            Assert.Equal(TestHelper.Now, publishedEvent.GeneratedOn);
        }
Exemplo n.º 2
0
 private void OnPatronHeaderChanged(PatronHeaderChanged evnt)
 {
     DisplayName = evnt.DisplayName ?? DisplayName;
     IsAnonymous = evnt.IsAnonymous ?? IsAnonymous;
     PatronType  = evnt.PatronType ?? PatronType;
     ModifiedBy  = evnt.GeneratedBy;
     ModifiedOn  = evnt.GeneratedOn;
 }
Exemplo n.º 3
0
        public void Handle(PatronHeaderChanged evnt)
        {
            using var context = contextFactory.Invoke();
            var patron = context.Patrons.Find(evnt.PatronId);

            if (patron != null)
            {
                patron.Update(evnt);
                context.SaveChanges();
            }
        }
Exemplo n.º 4
0
        public void Handle(UpdatePatronHeader command)
        {
            var evnt = new PatronHeaderChanged(command.GeneratedBy, command.GeneratedOn, command.Id)
            {
                PatronId    = command.PatronId,
                DisplayName = command.DisplayName,
                IsAnonymous = command.IsAnonymous,
                PatronType  = command.PatronType
            };

            eventBus.Publish(evnt);
        }