Esempio n. 1
0
        public void ThrowIfInsuredObjectNameIsNullOrEmpty(string nameOfInsuredObject)
        {
            var policy          = new Policy();
            var insurancePeriod = new NewInsurancePeriod(DateTime.Now, fixture.Create <short>());
            var insuredRisks    = fixture.CreateMany <Risk>().ToList();

            var policyAggregate = new PolicyAggregate(policy);

            Assert.Throws <MissingNameOfInsuredObjectException>(() =>
                                                                policyAggregate.Create(nameOfInsuredObject, insurancePeriod, insuredRisks));
        }
Esempio n. 2
0
        public void ThrowIfRemovedRiskIsNotInsured()
        {
            var validTill = DateTime.Now.AddDays(100);
            var risk      = fixture.Create <Risk>();
            var policy    = fixture.Create <Policy>();

            var policyAggregate = new PolicyAggregate(policy);

            Assert.Throws <InvalidRiskException>(() =>
                                                 policyAggregate.RemoveRisk(risk, validTill));
        }
Esempio n. 3
0
        public void ThrowIfRisksAreNotSelected()
        {
            var policy = new Policy();
            var nameOfInsuredObject = fixture.Create <string>();
            var insurancePeriod     = new NewInsurancePeriod(DateTime.Now, fixture.Create <short>());
            var insuredRisks        = new List <Risk>();

            var policyAggregate = new PolicyAggregate(policy);

            Assert.Throws <MissingInitialInsuredRisksException>(() =>
                                                                policyAggregate.Create(nameOfInsuredObject, insurancePeriod, insuredRisks));
        }
Esempio n. 4
0
        public void CalculatePremiumOnCreation()
        {
            var policy = new Policy();
            var nameOfInsuredObject = fixture.Create <string>();
            var insurancePeriod     = new NewInsurancePeriod(DateTime.Now, fixture.Create <short>());
            var insuredRisks        = fixture.CreateMany <Risk>().ToList();

            var policyAggregate = new PolicyAggregate(policy);

            policyAggregate.Create(nameOfInsuredObject, insurancePeriod, insuredRisks);

            Assert.True(policy.Premium > 0m);
        }
Esempio n. 5
0
        public void RecalculatePremiumForNewlyAddedRisk()
        {
            var validFrom = DateTime.Now;
            var risk      = fixture.Create <Risk>();
            var policy    = fixture
                            .Build <Policy>()
                            .With(p => p.ValidTill, validFrom.AddMonths(3))
                            .Create();
            var originalPremium = policy.Premium;

            var policyAggregate = new PolicyAggregate(policy);

            policyAggregate.AddRisk(risk, validFrom);

            Assert.NotEqual(originalPremium, policy.Premium);
        }
Esempio n. 6
0
        public void PropagateArgumentsToEntityOnCreation()
        {
            var policy = new Policy();
            var nameOfInsuredObject = fixture.Create <string>();
            var insurancePeriod     = new NewInsurancePeriod(DateTime.Now, fixture.Create <short>());
            var insuredRisks        = fixture.CreateMany <Risk>().ToList();

            var policyAggregate = new PolicyAggregate(policy);

            policyAggregate.Create(nameOfInsuredObject, insurancePeriod, insuredRisks);

            Assert.Equal(nameOfInsuredObject, policy.NameOfInsuredObject);
            Assert.Equal(insurancePeriod.From, policy.ValidFrom);
            Assert.Equal(insurancePeriod.Till, policy.ValidTill);
            Assert.Equal(insuredRisks, policy.InsuredRisks);
        }
Esempio n. 7
0
        public void RecalculatePremiumForRemovedRisk()
        {
            var validTill = DateTime.Now;
            var risk      = fixture.Create <Risk>();
            var policy    = fixture.Build <Policy>()
                            .With(p => p.ValidTill, validTill.AddMonths(3))
                            .With(p => p.InsuredRisks, new List <Risk> {
                risk
            })
                            .Create();
            var originalPremium = policy.Premium;

            var policyAggregate = new PolicyAggregate(policy);

            policyAggregate.RemoveRisk(risk, validTill);

            Assert.NotEqual(originalPremium, policy.Premium);
        }
Esempio n. 8
0
        public void ThrowIfRemovedRiskEndsSameMonthWithPolicy()
        {
            var validTill = new DateTime(DateTime.Now.Year, 01, 15);
            var risk      = fixture.Create <Risk>();
            var policy    = fixture.Build <Policy>()
                            .With(p => p.ValidTill, new DateTime(DateTime.Now.Year, 01, 30))
                            .With(p => p.InsuredRisks, new List <Risk> {
                risk
            })
                            .Create();

            policy.ValidTill = new DateTime(DateTime.Now.Year, 01, 30);

            var policyAggregate = new PolicyAggregate(policy);

            Assert.Throws <InvalidRiskRemovePeriodException>(() =>
                                                             policyAggregate.RemoveRisk(risk, validTill));
        }
Esempio n. 9
0
        public void ThrowIfAddedRiskAlreadyInsured()
        {
            var validFrom = DateTime.Now;
            var risk      = fixture.Create <Risk>();
            var policy    = fixture
                            .Build <Policy>()
                            .With(p => p.ValidTill, validFrom.AddMonths(3))
                            .With(p => p.InsuredRisks, new List <Risk> {
                risk
            })
                            .Create();
            var originalPremium = policy.Premium;

            var policyAggregate = new PolicyAggregate(policy);

            Assert.Throws <ExistingRiskException>(() =>
                                                  policyAggregate.AddRisk(risk, validFrom));
        }