Exemple #1
0
        public void AddRisk_ShouldAddRiskToPolicy()
        {
            var from   = new DateTime(2025, 1, 1);
            var policy = _company.GetPolicy("obj1", from);

            policy.InsuredRisks.Count.Should().Be(0);

            _company.AddRisk("obj1", new Risk("Theft", 10M), from);

            policy.InsuredRisks.Count.Should().Be(1);
        }
        public void RunCompany()
        {
            var from    = new DateTime(2021, 01, 01, 12, 0, 0);
            var policy1 = _company.SellPolicy("car", from, 12, _company.AvailableRisks);
            var policy2 = _company.SellPolicy("car", from.AddMonths(13), 6, _company.AvailableRisks);

            policy1.Premium.Should().Be(50);
            policy2.InsuredRisks.Count.Should().Be(2);

            _company.GetPolicy("car", from).Premium.Should().Be(50);
            _company.GetPolicy("car", from.AddMonths(13)).Premium.Should().Be(25);

            _company.AddRisk("car", new Risk("flood", 10), from);
            _company.AddRisk("car", new Risk("flood", 10), new DateTime(2021, 7, 1, 12, 0, 0));

            policy1.InsuredRisks.Count.Should().Be(4);

            policy1.Premium.Should().Be(65);
        }
Exemple #3
0
        public void CanAddARiskForLessThanOneYear()
        {
            var risks = GetMockRisks();

            InsuranceCompany.AvailableRisks = risks;

            InsuranceCompany.SellPolicy("obj1", new DateTime(2018, 11, 5), 13, risks.Take(2).ToList());
            InsuranceCompany.AddRisk("obj1", risks.Skip(2).First(), new DateTime(2019, 1, 5));

            var policy = InsuranceCompany.GetPolicy("obj1", new DateTime(2018, 11, 5));

            Assert.That(policy.InsuredRisks, Is.EqualTo(risks));
            Assert.That(policy.NameOfInsuredObject, Is.EqualTo("obj1"));
            Assert.That(policy.Premium, Is.EqualTo(9));
            Assert.That(policy.ValidFrom, Is.EqualTo(new DateTime(2018, 11, 5)));
            Assert.That(policy.ValidTill, Is.EqualTo(new DateTime(2019, 12, 5)));
        }
        public void InsuranceCompany_ShouldBeAbleToGetPolicyWithCorrectAmountOfRisksAfterNewRiskAdded()
        {
            List <Risk> riskList = new List <Risk>();

            riskList.Add(Risk1);
            riskList.Add(Risk2);

            var effectiveDate = DateTime.Now;
            var validTill     = effectiveDate.AddMonths(6);

            Company.SellPolicy(DEFAULT_OBJECT_NAME, effectiveDate, 6, riskList);

            Company.AddRisk(DEFAULT_OBJECT_NAME, Risk3, effectiveDate.AddDays(1), effectiveDate);

            var policy = Company.GetPolicy(DEFAULT_OBJECT_NAME, effectiveDate);

            Assert.AreEqual(3, policy.InsuredRisks.Count);
        }
        public void PremiumCalculator_ShouldCalculatePremiumForSoldPolicyWithRiskAdded()
        {
            List <Risk> riskList = new List <Risk>();

            riskList.Add(Risk1);
            riskList.Add(Risk2);

            var effectiveDate = DateTime.Now;

            var soldPolicy = Company.SellPolicy(DEFAULT_OBJECT_NAME, effectiveDate, 6, riskList);

            var policyID = IdGenerator.ConstructPolicyId(DEFAULT_OBJECT_NAME, effectiveDate);

            Company.AddRisk(DEFAULT_OBJECT_NAME, Risk3, effectiveDate.AddDays(1), effectiveDate);

            var premium = PremiumCalculator.CalculatePremiumOfSoldPolicy(DEFAULT_OBJECT_NAME, effectiveDate);

            Assert.AreEqual(851.68m, premium);
        }
        public void AddRisk_NameOfInsuredObjectNull_ThrowsException()
        {
            Action result = () => _target.AddRisk(null, new Risk(), DateTime.Now, DateTime.Now);

            Assert.ThrowsException <ArgumentNullException>(result);
        }
Exemple #7
0
 public void AddRisk_ShouldThrowIfNameIsNull()
 {
     Assert.That(() => Company.AddRisk(null, It.IsAny <Risk>(), It.IsAny <DateTime>(), It.IsAny <DateTime>()),
                 Throws.Exception);
 }