示例#1
0
        public void Patron_Can_Be_Hydrated_From_Patron_Created()
        {
            var patronId = Guid.NewGuid();

            PatronCreated created = new PatronCreated("Create User", TestHelper.Now, Guid.NewGuid())
            {
                DisplayName = "Test Creation",
                IsAnonymous = false,
                PatronType  = "Test Account",
                PatronId    = patronId,
                Version     = 0
            };
            Patron result = new Patron(patronId, new[] { created });

            Assert.Equal("Test Creation", result.DisplayName);
            Assert.False(result.IsAnonymous);
            Assert.Equal("Test Account", result.PatronType);
            Assert.Equal(patronId, result.Id);
            Assert.Equal(0, result.Version);
            Assert.Equal("Create User", result.CreatedBy);
            Assert.Equal(TestHelper.Now, result.CreatedOn);
            Assert.Null(result.ModifiedBy);
            Assert.Null(result.ModifiedOn);
            Assert.Null(result.DeletedBy);
            Assert.Null(result.DeletedOn);
        }
示例#2
0
        public void Handle_PatronCreated_Adds_NewPatron()
        {
            IEventHandler <PatronCreated> handler = new PatronEventHandler(Context);
            PatronCreated evnt = new PatronCreated("Create User", TestHelper.Now, Guid.NewGuid())
            {
                DisplayName = "New Patron",
                IsAnonymous = false,
                PatronType  = "Test Account",
                PatronId    = Guid.NewGuid()
            };

            handler.Handle(evnt);

            using var context = Context.Invoke();
            Patron result = context.Patrons.Single();

            Assert.Equal("New Patron", result.DisplayName);
            Assert.Equal("Test Account", result.PatronType);
            Assert.Equal(evnt.PatronId, result.Id);
            Assert.False(result.IsAnonymous);
            Assert.Equal("Create User", result.CreatedBy);
            Assert.Equal(TestHelper.Now, result.CreatedOn);
            Assert.Equal(0, result.Version);
            Assert.Null(result.ModifiedBy);
            Assert.Null(result.ModifiedOn);
            Assert.Null(result.DeletedBy);
            Assert.Null(result.DeletedOn);
        }
示例#3
0
        public void User_Can_Create_New_Patron()
        {
            CreatePatron command = new CreatePatron("Create User", TestHelper.Now)
            {
                DisplayName = "Test Patron",
                IsAnonymous = false,
                PatronType  = "Test Account"
            };

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

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

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

            handler.Handle(command);

            Assert.NotEqual(Guid.Empty, command.Id);
            eventBus.VerifyPublish <PatronCreated>(Times.Once());
            Assert.NotNull(publishedEvent);
            Assert.Equal(command.DisplayName, 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.NotEqual(command.PatronId, publishedEvent.Id);
            Assert.Equal(0, publishedEvent.Version);
        }
示例#4
0
文件: Patron.cs 项目: drovani/Vigil
 private void OnPatronCreated(PatronCreated evnt)
 {
     DisplayName = evnt.DisplayName;
     IsAnonymous = evnt.IsAnonymous;
     PatronType  = evnt.PatronType;
     CreatedBy   = evnt.GeneratedBy;
     CreatedOn   = evnt.GeneratedOn;
 }
示例#5
0
        public void Handle(CreatePatron command)
        {
            var evnt = new PatronCreated(command.GeneratedBy, command.GeneratedOn, command.Id)
            {
                PatronId    = command.PatronId,
                DisplayName = command.DisplayName,
                IsAnonymous = command.IsAnonymous,
                PatronType  = command.PatronType
            };

            eventBus.Publish(evnt);
        }