Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void Execute(UpdateGrapeBlend cmd)
        {
            if (cmd.Grapes.Sum(x => x.Percentage.Value) > 1)
            {
                throw DomainError.Because("Grape blends cannot exceed 100% combined");
            }

            if (cmd.Grapes.GroupBy(x => x.GrapeVariety).Any(x => x.Count() > 1))
            {
                throw DomainError.Because("A grape can only appear once in the blend");
            }

            RaiseEvent(new GrapeBlendUpdated(Id, cmd.Grapes));
        }