コード例 #1
0
        public void Record_GrapeBlendUpdated_When_Updating_Blend()
        {
            //Arrange
            var originalName = new ChampagneName("Bollinger 2007");
            var sut          = new Champagne();

            sut.Execute(new CreateChampagne(new AggregateId(Guid.NewGuid()), originalName));
            sut.ClearUncommittedEvents();

            var grapes = new[]
            {
                new GrapeBlend(new GrapeBlendPercentage(0.3), new GrapeVariety("PinotNoir")),
                new GrapeBlend(new GrapeBlendPercentage(0.7), new GrapeVariety("PinotBlanc")),
            };
            var cmd = new UpdateGrapeBlend(sut.Id, grapes);

            //Act
            sut.Execute(cmd);

            //Assert
            sut.GetUncommittedEvents().Count().ShouldBe(1);

            var evt = sut.GetUncommittedEvents().Single() as GrapeBlendUpdated;

            evt.ShouldNotBeNull();
            evt.Id.ShouldBeSameAs(sut.Id);
            evt.UpdatedBlend.ShouldBeSameAs(grapes);
        }
コード例 #2
0
        public void Throw_Error_When_Reusing_Grapes_In_Blend()
        {
            //Arrange
            var originalName = new ChampagneName("Bollinger 2007");
            var sut          = new Champagne();

            sut.Execute(new CreateChampagne(new AggregateId(Guid.NewGuid()), originalName));
            sut.ClearUncommittedEvents();

            var grapes = new[]
            {
                new GrapeBlend(new GrapeBlendPercentage(0.3), new GrapeVariety("PinotNoir")),
                new GrapeBlend(new GrapeBlendPercentage(0.7), new GrapeVariety("PinotNoir")),
            };
            var cmd = new UpdateGrapeBlend(sut.Id, grapes);

            //Act
            Should.Throw <DomainError>(() =>
            {
                sut.Execute(cmd);
            });

            //Assert
            sut.GetUncommittedEvents().Count().ShouldBe(0);
        }
コード例 #3
0
        public void Record_ChampagneRenamed_Event_When_Changing_Champagne_Name(RenameChampagne cmd)
        {
            //Arrange
            var originalName = new ChampagneName("Bollinger 2007");
            var sut          = new Champagne();

            sut.Execute(new CreateChampagne(new AggregateId(Guid.NewGuid()), originalName));
            sut.ClearUncommittedEvents();

            //Act
            sut.Execute(cmd);

            //Assert
            sut.GetUncommittedEvents().Count().ShouldBe(1);

            var evt = sut.GetUncommittedEvents().Single() as ChampagneRenamed;

            evt.ShouldNotBeNull();
            evt.OldName.ShouldBeSameAs(originalName);
            evt.NewName.ShouldBeSameAs(cmd.NewName);
        }
コード例 #4
0
        public async Task Never_Persist_If_Domain_Logic_Fails([Frozen] Mock <IPublishingAggregateRepository> repo, Champagne pagne, ChampagneHandler sut)
        {
            //Arrange
            repo.Setup(x => x.LoadAsync <Champagne>(It.IsAny <AggregateId>(), null))
            .ReturnsAsync(pagne);

            var cmd = new UpdateGrapeBlendCommand(Guid.NewGuid(), new []
コード例 #5
0
        public async Task Fail_When_Changing_Name_On_Non_Existing_Champagne([Frozen] Mock <IPublishingAggregateRepository> repo, RenameChampagneCommand cmd, Champagne pagne, ChampagneHandler sut)
        {
            //Arrange
            repo.Setup(x => x.LoadAsync <Champagne>(It.IsAny <AggregateId>(), null))
            .ReturnsAsync((Champagne)null);

            //Act
            Should.Throw <DomainError>(async() =>
            {
                await sut.Handle(cmd);
            });

            //Assert
            repo.Verify(x =>
                        x.StoreAsync(pagne, It.IsAny <IDocumentSession>()),
                        Times.Never);
        }
コード例 #6
0
        public async Task Store_Events_When_Changing_Name_On_Existing_Champagne([Frozen] Mock <IPublishingAggregateRepository> repo, RenameChampagneCommand cmd, Champagne pagne, ChampagneHandler sut)
        {
            //Arrange
            repo.Setup(x => x.LoadAsync <Champagne>(It.IsAny <AggregateId>(), null))
            .ReturnsAsync(pagne);

            //Act
            var response = await sut.Handle(cmd);

            //Assert
            response.ShouldNotBeNull();
            response.IsSuccessful.ShouldBeTrue();

            repo.Verify(x =>
                        x.StoreAsync(pagne, It.IsAny <IDocumentSession>()),
                        Times.Once);
        }