コード例 #1
0
        public void CanAddTheSameCoverTwice()
        {
            var product = ProductsTestData.StandardCarInsurance();
            var policy  = PolicyTestData.StandardOneYearPolicy(new DateTime(2019, 1, 1));

            var doubledCover = product.CoverWithCode("OC");
            var ex           = Throws <ApplicationException>(() => policy.ExtendCoverage
                                                             (
                                                                 new DateTime(2019, 7, 1),
                                                                 new CoverPrice(Guid.NewGuid(), doubledCover, Money.Euro(100), TimeSpan.FromDays(365))
                                                             ));

            Equal("This cover is already present", ex.Message);
        }
コード例 #2
0
        public void CanExtendCoverageWithMiddleDayOfPolicy()
        {
            var product = ProductsTestData.StandardCarInsurance();
            var policy  = PolicyTestData.StandardOneYearPolicy(new DateTime(2019, 1, 1));

            var newCover = product.CoverWithCode("AC");

            policy.ExtendCoverage
            (
                new DateTime(2019, 7, 1),
                new CoverPrice(Guid.NewGuid(), newCover, Money.Euro(100), TimeSpan.FromDays(365))
            );

            var resultingEvents = policy.GetUncommittedChanges();

            //assert state
            policy
            .Should()
            .HaveVersions(2);

            policy.Versions.WithNumber(1).Should()
            .BeActive()
            .HaveActivePolicyStatus()
            .HaveTotalPremiumEqualTo(Money.Euro(500));

            policy.Versions.WithNumber(2)
            .Should()
            .BeDraft()
            .HaveActivePolicyStatus()
            .CoverPeriod(new DateTime(2019, 1, 1), new DateTime(2020, 1, 1))
            .HaveTotalPremiumEqualTo(Money.Euro(550.41));


            //assert events
            resultingEvents
            .Should()
            .BeSingle()
            .ContainEvent(
                new CoverageExtendedPolicyVersionCreated
                (
                    2,
                    1,
                    ValidityPeriod.Between(new DateTime(2019, 7, 1), new DateTime(2020, 1, 1)),
                    new PolicyCoverData("AC", new DateTime(2019, 7, 1), new DateTime(2020, 1, 1), Money.Euro(50.41), Money.Euro(100), TimeSpan.FromDays(365))
                )
                );
        }
コード例 #3
0
        public void CanTerminatePolicyInTheMiddle()
        {
            var policy          = PolicyTestData.StandardOneYearPolicy(new DateTime(2019, 1, 1));
            var terminationDate = new DateTime(2019, 7, 1);

            policy.TerminatePolicy(terminationDate);
            var resultingEvents = policy.GetUncommittedChanges();

            //assert state
            policy
            .Should()
            .HaveVersions(2);

            policy.Versions.WithNumber(1).Should()
            .BeActive()
            .HaveActivePolicyStatus()
            .HaveTotalPremiumEqualTo(Money.Euro(500));

            policy.Versions.WithNumber(2)
            .Should()
            .BeDraft()
            .HaveTerminatedPolicyStatus()
            .CoverPeriod(new DateTime(2019, 1, 1), terminationDate.AddDays(-1))
            .HaveTotalPremiumEqualTo(Money.Euro(246.58));


            //assert events
            resultingEvents
            .Should()
            .BeSingle()
            .ContainEvent(
                new TerminalPolicyVersionCreated
                (
                    2,
                    1,
                    new DateTime(2019, 7, 1),
                    new DateTime(2020, 1, 1),
                    new DateTime(2019, 1, 1),
                    new DateTime(2019, 6, 30),
                    new List <PolicyCoverData>
            {
                new PolicyCoverData("OC", new DateTime(2019, 1, 1), new DateTime(2019, 6, 30), Money.Euro(246.58), Money.Euro(500), TimeSpan.FromDays(365))
            }
                )
                );
        }