public InsurancePolicy CreateAndSavePolicy(params Vehicle[] vehicles)
        {
            InsurancePolicy policy = new InsurancePolicy();

            foreach (Vehicle vehicle in vehicles)
            {
                Risk newRisk = new Risk();
                newRisk.InsuredVehicle = vehicle;

                // Basic Premium
                newRisk.Premium = 100;

                if (VehicleType.MotorCycle == vehicle.Type)
                {
                    if (vehicle.HorsePower > 120)
                    {
                        throw new ArgumentException("Motorcycles above 120 horsepower cannot be insured");
                    }
                    if (vehicle.HorsePower > 20)
                    {
                        newRisk.Premium = newRisk.Premium * 2;
                    }
                    if (vehicle.HorsePower > 60)
                    {
                        newRisk.Premium = newRisk.Premium * 2;
                    }
                }
                else if (VehicleType.Car == vehicle.Type)
                {
                    newRisk.Premium = newRisk.Premium * 4;
                    if (vehicle.HorsePower > 100)
                    {
                        newRisk.Premium = newRisk.Premium * 2;
                    }
                }
                else if (VehicleType.Car == vehicle.Type)
                {
                    // Flatrate
                    newRisk.Premium = newRisk.Premium * 10;
                }

                policy.AddRisk(newRisk);
            }

            policy.PolicyNr = Guid.NewGuid().ToString();

            string[] lines = new string[policy.GetNumberOfRisks() + 2];
            lines[0] = policy.PolicyNr;
            lines[1] = policy.Premium.ToString();
            for (int i = 0; i < policy.GetNumberOfRisks(); i++)
            {
                Risk risk = policy.GetRisk(i);
                lines[i + 2] = String.Format("{0},{1},{2}",
                                             risk.Premium, risk.InsuredVehicle.RegistrationId, risk.InsuredVehicle.Type);
            }

            System.IO.File.WriteAllLines("/Temp/policy.txt", lines);

            return(policy);
        }
Ejemplo n.º 2
0
        public static void EditPolicy(int ID, InsurancePolicyEditor p)
        {
            QCTLinqDataContext db = new QCTLinqDataContext();

            // create and populate!
            InsurancePolicy ins = db.InsurancePolicies.Single(i => i.ID == ID);

            ins.TenantsLegalLiability = p.TenantsLiability;
            ins.CertReqFor            = p.CertificateRequestFor;
            ins.TypeOfPolicy          = p.TypeOfPolicy;
            ins.PerOccurance          = p.PerOccurance;
            ins.ProductsCompletedOps  = p.ProductsCompletedOps;
            ins.NonOwnedAuto          = p.NonOwnedAuto;
            ins.CrossLiability        = p.CrossLiability;
            ins.NCasAddIns            = p.NorfolkCountyAsAdditionallyInsured;
            ins.PolicyNumber          = p.PolicyNumber;
            ins.PolicyLimit           = p.PolicyLimit;
            ins.PolicyLimitOther      = p.PolicyLimitOther;
            ins.ExpiryDate            = p.ExpiryDate;
            ins.insID         = p.InsuranceCompany;
            ins.BrokerID      = p.Broker;
            ins.BrokerEmailID = p.BrokerEmail;
            ins.CertSigned    = p.CertificateSigned;
            ins.Active        = p.Active;
            // save to database!
            db.SubmitChanges();

            // let's look at the uploaded file
            if (p.Files.Count > 0) // see if there's a file to attach...
            {
                UploadInsuranceDocument(ins.ID, p.Files);
            }
        }
Ejemplo n.º 3
0
        public async Task SetExpiredInsurancePoliciesLogicAsyncShouldSetAllExpiredInsuranceTrue(DateTime endDate, bool expired = false)
        {
            //Arrange
            var newInsurance = new InsurancePolicy
            {
                TypeInsurance      = TypeInsurance.FullCasco,
                StartDate          = DateTime.MinValue,
                EndDate            = endDate,
                Expired            = expired,
                InsuranceCompanyId = 1,
                VehicleId          = int.MaxValue
            };

            //Act
            await this.fixture.Context.InsurancePolicies.AddAsync(newInsurance);

            await this.fixture.Context.SaveChangesAsync();

            await insuranceServices.SetExpiredInsurancePoliciesLogicAsync();

            newInsurance = await this.fixture.Context
                           .InsurancePolicies.FirstOrDefaultAsync(i => i.VehicleId == int.MaxValue);

            //Assert
            Assert.True(newInsurance.Expired);
        }
Ejemplo n.º 4
0
        public static void AssertAreEqual(InsurancePolicy expected, InsurancePolicy actual)
        {
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.InsuranceType, actual.InsuranceType);
            Assert.AreEqual(expected.Price, actual.Price);
            Assert.AreEqual(expected.TermLength, actual.TermLength);
            Assert.AreEqual(expected.TermUnit, expected.TermUnit);
            Assert.AreEqual(expected.CoverageBeginDateTime, actual.CoverageBeginDateTime);
            Assert.AreEqual(expected.LastUpdateDate, actual.LastUpdateDate);

            Assert.AreEqual(expected.Customer.Id, actual.Customer.Id);
            Assert.AreEqual(expected.Customer.AddressLine1, actual.Customer.AddressLine1);
            Assert.AreEqual(expected.Customer.City, actual.Customer.City);
            Assert.AreEqual(expected.Customer.FirstName, actual.Customer.FirstName);
            Assert.AreEqual(expected.Customer.LastName, actual.Customer.LastName);
            Assert.AreEqual(expected.Customer.PostalCode, actual.Customer.PostalCode);
            Assert.AreEqual(expected.Customer.State, actual.Customer.State);
            Assert.AreEqual(expected.Customer.Country, actual.Customer.Country);

            Assert.AreEqual(expected.PaymentInformation.Id, actual.PaymentInformation.Id);
            Assert.AreEqual(expected.PaymentInformation.CreditCardNumber, actual.PaymentInformation.CreditCardNumber);
            Assert.AreEqual(expected.PaymentInformation.CreditCardType, actual.PaymentInformation.CreditCardType);
            Assert.AreEqual(expected.PaymentInformation.CreditCardVerificationNumber, actual.PaymentInformation.CreditCardVerificationNumber);
            Assert.AreEqual(expected.PaymentInformation.ExpirationDate, actual.PaymentInformation.ExpirationDate);
        }
Ejemplo n.º 5
0
        public void Should_create_policy_with_non_null_values()
        {
            InsurancePolicy policy = InsurancePolicy.NewInsurancePolicy();

            #region Policy
            Assert.AreNotEqual(Guid.Empty, policy.Id);
            Assert.IsNotNull(policy.Customer);
            Assert.AreNotEqual(DateTime.MinValue, policy.CoverageBeginDateTime);
            Assert.AreEqual(InsuranceTypes.Unspecified, policy.InsuranceType);
            Assert.IsNotNull(policy.PaymentInformation);
            Assert.AreEqual(0, policy.Price);
            Assert.AreEqual(0, policy.TermLength);
            Assert.AreEqual(TermUnits.Months, policy.TermUnit);
            Assert.AreNotEqual(DateTime.MinValue, policy.LastUpdateDate);
            #endregion Policy

            #region Customer
            Assert.AreNotEqual(Guid.Empty, policy.Customer.Id);
            Assert.IsNotNull(policy.Customer.AddressLine1);
            Assert.IsNotNull(policy.Customer.City);
            Assert.IsNotNull(policy.Customer.Country);
            Assert.IsNotNull(policy.Customer.FirstName);
            Assert.IsNotNull(policy.Customer.LastName);
            Assert.IsNotNull(policy.Customer.PostalCode);
            Assert.IsNotNull(policy.Customer.State);
            #endregion Customer

            #region PaymentInformation
            Assert.AreNotEqual(Guid.Empty, policy.PaymentInformation.Id);
            Assert.IsNotNull(policy.PaymentInformation.CreditCardNumber);
            Assert.IsNotNull(policy.PaymentInformation.CreditCardVerificationNumber);
            Assert.AreEqual(CreditCardTypes.Unspecified, policy.PaymentInformation.CreditCardType);
            #endregion PaymentInformation
        }
Ejemplo n.º 6
0
 public static void payPremiumByCreditCard(InsurancePolicy p, List <Receipt> receiptList)
 {
     Console.WriteLine("Use Case Changes to \"Pay Premium By Credit Card\"");
     p.Duration.AddPayDate(p);
     receiptList.Add(new Receipt(p));
     p.AutoState();
 }
Ejemplo n.º 7
0
 public static void PayPremiumByCheque(ref InsurancePolicy p, Customer customer)
 {
     Console.WriteLine("Use Case Changes to \"Pay Premium By Cheque\"");
     while (true)
     {
         Console.WriteLine("Type in \"Confirm\" to confirm that Customer has Paid Premium by Cheque OR \"Cancel\" to return back to editing policy:   ");
         string confirmation = Console.ReadLine();
         if (confirmation.ToUpper() == "CONFIRM")
         {
             p.Duration.AddPayDate(p);
             p.AutoState();
             break;
         }
         else if (confirmation == "CANCEL")
         {
             EditPolicy(customer);
             break;
         }
         else
         {
             Console.WriteLine("Please key in a valid option");
             continue;
         }
     }
 }
        public async Task UpdatingAPolicyMustCallThroughToTheRepositoryWithTheUpdatedValues()
        {
            var policyGuid     = Guid.NewGuid();
            var originalPolicy = new InsurancePolicy(policyGuid, "123", "123", new Dictionary <InsuranceCoverage, float>(), DateTime.Now, 10, 10, RiskLevel.Low);
            var expectedPolicy = new InsurancePolicy(policyGuid, "Updated Policy", "This is an updated policy",
                                                     new Dictionary <InsuranceCoverage, float>(), originalPolicy.CoverageStartDate, 10, 10, RiskLevel.Low);

            repoMock
            .Setup(mock => mock.GetPolicyAsync(policyGuid))
            .ReturnsAsync(originalPolicy);

            InsurancePolicy storedPolicy = null;

            repoMock
            .Setup(mock => mock.StorePolicyAsync(It.IsAny <InsurancePolicy>()))
            .Callback((InsurancePolicy policy) => { storedPolicy = policy; })
            .Returns(Task.CompletedTask)
            .Verifiable();

            var actualPolicy = await service.UpdatePolicyAsync(policyGuid, expectedPolicy.Name, expectedPolicy.Description, expectedPolicy.PremiumCostInDollars);

            Check.That(actualPolicy).IsNotNull();
            Check.That(actualPolicy).IsSameReferenceAs(storedPolicy);

            Check.That(expectedPolicy.Name).IsEqualTo(actualPolicy.Name);
            Check.That(expectedPolicy.Description).IsEqualTo(actualPolicy.Description);
            Check.That(expectedPolicy.CoveragePercentages).IsEqualTo(actualPolicy.CoveragePercentages);
            Check.That(expectedPolicy.CoverageStartDate).IsEqualTo(actualPolicy.CoverageStartDate);
            Check.That(expectedPolicy.PremiumCostInDollars).IsEqualTo(actualPolicy.PremiumCostInDollars);
            Check.That(expectedPolicy.InsuredRiskLevel).IsEqualTo(actualPolicy.InsuredRiskLevel);
        }
        public async Task DeletingAPolicyMustDeleteAllAssignmentsAndCallThroughToTheRepository()
        {
            var targetGuid = Guid.NewGuid();
            var client     = new Client(Guid.NewGuid(), "Carlos");
            var policy     = new InsurancePolicy(targetGuid, "123", "123", new Dictionary <InsuranceCoverage, float>(), DateTime.Now, 10, 10, RiskLevel.Low, new[] { client });

            repoMock
            .Setup(mock => mock.GetPolicyAsync(policy.Id))
            .ReturnsAsync(policy)
            .Verifiable();

            repoMock
            .Setup(mock => mock.DeleteClientAssignmentAsync(policy.Id, client.Id))
            .Returns(Task.CompletedTask)
            .Verifiable();

            repoMock
            .Setup(mock => mock.DeletePolicyAsync(targetGuid))
            .Returns(Task.CompletedTask)
            .Verifiable();

            await service.DeletePolicyAsync(targetGuid);

            repoMock.Verify();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Method for adding a new entry in xml-file
        /// </summary>
        /// <param name="card">Insurance policy</param>
        public void XMLCreateInsurancePolicy(InsurancePolicy card)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(@"../../XMLFileCardInf.xml");
            XmlElement xRoot    = xDoc.DocumentElement;
            XmlElement userElem = xDoc.CreateElement("insurancePolicy");
            XmlElement a1       = xDoc.CreateElement("number");
            XmlElement a2       = xDoc.CreateElement("surname");
            XmlElement a3       = xDoc.CreateElement("name");
            XmlElement a4       = xDoc.CreateElement("middlename");
            XmlElement a5       = xDoc.CreateElement("sex");
            XmlElement a6       = xDoc.CreateElement("dateOfBirth");
            XmlElement a7       = xDoc.CreateElement("insuranceNumber");

            a1.AppendChild(xDoc.CreateTextNode(card.Number.ToString()));
            a2.AppendChild(xDoc.CreateTextNode(card.Surname));
            a3.AppendChild(xDoc.CreateTextNode(card.Name));
            a4.AppendChild(xDoc.CreateTextNode(card.Middlename));
            a5.AppendChild(xDoc.CreateTextNode(card.Sex));
            a6.AppendChild(xDoc.CreateTextNode(card.DateOfBirth.ToShortDateString()));
            a7.AppendChild(xDoc.CreateTextNode(card.InsuranceNumber));
            userElem.AppendChild(a1);
            userElem.AppendChild(a2);
            userElem.AppendChild(a3);
            userElem.AppendChild(a4);
            userElem.AppendChild(a5);
            userElem.AppendChild(a6);
            userElem.AppendChild(a7);
            xRoot.AppendChild(userElem);
            xDoc.Save(@"../../XMLFileCardInf.xml");
        }
Ejemplo n.º 11
0
        private async void ProcessPolicyCreatedMessage(Task <BrokeredMessage> t)
        {
            BrokeredMessage message = t.Result;

            try
            {
                // Process message from subscription.
                Console.WriteLine("\n**PolicyIssued**");

                var @event = message.GetBody <PolicyCreatedEvent>();
                Console.WriteLine("Body: " + @event.PolicyNumber);
                Console.WriteLine("StreamRevision: " + message.Properties["StreamRevision"]);
                var policy = new InsurancePolicy(null); //Yuck!
                policy.ApplyEvent(@event);
                CreateVersionOfPolicy(policy);

                // Remove message from subscription.
                await message.CompleteAsync();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                // Indicates a problem, unlock message in subscription.
                message.Abandon();
            }
        }
Ejemplo n.º 12
0
 public Receipt(InsurancePolicy policy)
 {
     _receiptNum = _receiptNumIncrement.ToString();
     _receiptNumIncrement++;
     _paidDate = DateTime.Today;
     _policy   = policy;
 }
        internal static bool PolicyDetails(DataGridView dataGridView1)
        {
            try
            {
                policy = dataGridView1.CurrentRow.DataBoundItem as InsurancePolicy;

                policy = komunikacija.SelectPolicy(policy) as InsurancePolicy;

                if (policy == null)
                {
                    MessageBox.Show("System can't find policy");
                    return(false);
                }
                else
                {
                    MessageBox.Show("Successfully find policy.");
                    return(true);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Select policy.");
                return(false);
            }
        }
Ejemplo n.º 14
0
        public override double HandleRequest(InsurancePolicy policy, double currentPremium)
        {
            var youngestDriver = policy.YoungestDriver;

            if (youngestDriver != null)
            {
                var ageOnStartDate = youngestDriver.DateOfBirth.CalculateAgeOnDate(policy.StartDate);

                if (ageOnStartDate >= 21 && ageOnStartDate <= 25)
                {
                    currentPremium = currentPremium * 1.2;

                    return(Successor?.HandleRequest(policy, currentPremium) ?? currentPremium);
                }

                if (ageOnStartDate >= 26 && ageOnStartDate <= 75)
                {
                    currentPremium = currentPremium * 0.9;

                    return(Successor?.HandleRequest(policy, currentPremium) ?? currentPremium);
                }
            }

            return(Successor?.HandleRequest(policy, currentPremium) ?? currentPremium);
        }
        public void HandleRequest_ShouldDecreasePremiumByTenPercentIfYoungestDriverBetween26And75OnStartDate()
        {
            // Setup dependencies
            var policy = new InsurancePolicy
            {
                StartDate = DateTime.UtcNow,
                Drivers   = new List <InsurancePolicyDriver>
                {
                    new InsurancePolicyDriver
                    {
                        DateOfBirth = DateTime.UtcNow.AddYears(-30)
                    },
                    new InsurancePolicyDriver
                    {
                        DateOfBirth = DateTime.UtcNow.AddYears(-64)
                    }
                }
            };

            // Call HandleRequest
            var returnedPremium = new InsurancePremiumCalculationYoungestDriverHandler()
                                  .HandleRequest(policy, 100);

            // Verify result
            Assert.AreEqual(90, returnedPremium);
        }
        public async Task RemovingAPolicyFromAClientMustCallThroughToTheRepository()
        {
            var clientId = Guid.NewGuid();
            var policyId = Guid.NewGuid();

            var client = new Client(Guid.NewGuid(), "Louise");
            var policy = new InsurancePolicy(Guid.NewGuid(), "123", "123", new Dictionary <InsuranceCoverage, float>(), DateTime.Now, 10, 10, RiskLevel.Low, new[] { client });

            repoMock
            .Setup(mock => mock.GetPolicyAsync(policyId))
            .ReturnsAsync(policy);

            repoMock
            .Setup(mock => mock.GetClientAsync(clientId))
            .ReturnsAsync(client);

            repoMock
            .Setup(mock => mock.DeleteClientAssignmentAsync(policyId, clientId))
            .Returns(Task.CompletedTask)
            .Verifiable();

            await service.RemovePolicyFromClientAsync(policyId, clientId);

            repoMock.Verify();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Data input
        /// </summary>
        /// <returns>Insurance policy</returns>
        private static InsurancePolicy CreateInsurancePolicy()
        {
            int Num = Number;

            Console.WriteLine("Страховой полис:");
            Console.WriteLine("Введите имя:");
            string Name = Console.ReadLine();

            Console.WriteLine("Введите фамилию:");
            string Surname = Console.ReadLine();

            Console.WriteLine("Введите отчество:");
            string Middlename = Console.ReadLine();

            Console.WriteLine("Введите пол:");
            string Sex = Console.ReadLine();

            Console.WriteLine("Введите дату рождения:");
            DateTime DateOfBirth = Convert.ToDateTime(Console.ReadLine());

            Console.WriteLine("Введите страховой номер:");
            string          InsuranceNumber = Console.ReadLine();
            InsurancePolicy insurancePolicy = new InsurancePolicy(Name, Surname, Num, Middlename, Sex, DateOfBirth, InsuranceNumber);

            cards.Add(insurancePolicy);
            Console.WriteLine("Ваша карта:\n" + insurancePolicy.ToString());
            return(insurancePolicy);
        }
Ejemplo n.º 18
0
        public MedicalRecord Read(uint id)
        {
            List <string[]> data = Persistence.ReadEntryByPrimaryKey(path, id.ToString());

            if (data.Count == 1)
            {
                uint            mrID        = uint.Parse(data[0][0]);
                uint            patID       = uint.Parse(data[0][1]);
                string          insuranceID = data[0][2];
                InsurancePolicy policy      = InsurancePolicyRepository.GetInstance().Read(insuranceID);
                if (policy != null)
                {
                    Patient            patient = (Patient)PeopleRepository.GetInstance().Read(patID);
                    List <Examination> exams   = new List <Examination>();


                    string[] examIDs = data[0][3].Split(' ');
                    foreach (string exID in examIDs)
                    {
                        if (exID.Equals(""))
                        {
                            break;
                        }
                        Examination e = ExaminationRepository.GetInstance().Read(uint.Parse(exID));
                        exams.Add(e);
                    }

                    MedicalRecord ret = new MedicalRecord(policy, exams, patient);
                    ret.SetId(mrID);
                    return(ret);
                }
            }
            return(null);
        }
Ejemplo n.º 19
0
        // Richeton's Individual Code

        public static void EditPolicy(Customer customer)
        {
            Console.WriteLine("Please select the index of the customer's policy you wish to edit :  ");
            int customerIndex = Convert.ToInt16(Console.ReadLine());

            InsurancePolicy myPolicy = customer.MyPolicies.GetPolicy(customerIndex);
            int             option   = -1;

            while (option != 0)
            {
                Console.WriteLine("Please select what needs to be edited :  ");
                Console.WriteLine("1 : Add Rider ");
                Console.WriteLine("2 : Pay Premium by Cheque ");
                Console.WriteLine("3 : Select another customer's policy ");
                Console.WriteLine("0 : Exit ");
                option = Convert.ToInt16(Console.ReadLine());
                switch (option)
                {
                case 1:
                    AddRider(ref myPolicy);
                    break;

                case 2:
                    PayPremiumByCheque(ref myPolicy, customer);
                    break;

                case 3:
                    EditPolicy(customer);
                    break;
                }
            }

            Environment.Exit(1);
        }
Ejemplo n.º 20
0
        public void Given_setup_policy_When_restoring_from_snapshot_Then_policy_is_the_same_as_before()
        {
            var            policy          = new InsurancePolicy();
            var            address         = Address.New <InsurancePolicy>();
            IAggregateRoot policyAggregate = policy;

            policyAggregate.Apply(new PolicyCreatedEvent(address.Id));
            var durationSetEvent =
                policyAggregate.ApplyEvent(new PolicyDurationSetEvent(address.Id, TimeSpan.FromDays(30)));
            var policyAmountEvent = policyAggregate.ApplyEvent(new PolicyAmountSetEvent(address.Id, 20m));
            var issuedEvent       = policyAggregate.ApplyEvent(new PolicyIssuedEvent(address.Id, DateTimeOffset.Now));

            policyAggregate.Apply(new PolicyTimePassedEvent(address.Id, DateTimeOffset.Now.AddMinutes(1)));
            policyAggregate.Apply(new ClaimFulfilledEvent(address.Id, 2m));
            policyAggregate.Apply(new PolicyExpiredEvent(address.Id));

            var snapshot = (SnapshotState <PolicyState>)(policy as ISupportSnapshots).BuildSnapshot();

            snapshot.Address.Should().BeEquivalentTo(address);
            snapshot.Id.Should().NotBeNullOrEmpty();
            snapshot.Version.Should().Be(policy.Version);
            snapshot.State.Duration.Should().Be(durationSetEvent.Duration);
            snapshot.State.IssueDate.Should().Be(issuedEvent.Issued);

            var restoredSnapshot =
                ((InsurancePolicy) new InsurancePolicy().RestoreFromSnapshot(snapshot)).BuildSnapshot();

            snapshot.Should().BeEquivalentTo(restoredSnapshot, o => o.Excluding(s => s.Id));
        }
        public void ValidatePolicy_ShouldFailIfMoreThan2ClaimsForDriver()
        {
            // Setup dependencies
            var policy = new InsurancePolicy
            {
                StartDate = DateTime.UtcNow.AddMonths(1),
                Drivers   = new List <InsurancePolicyDriver>
                {
                    new InsurancePolicyDriver
                    {
                        FirstName   = "Test",
                        Surname     = "Driver",
                        DateOfBirth = DateTime.UtcNow.AddYears(-30),
                        Claims      = new List <DriverClaim>
                        {
                            new DriverClaim(),
                            new DriverClaim(),
                            new DriverClaim(),
                            new DriverClaim()
                        }
                    }
                }
            };

            // Call Validate
            var result = policy.Validate();

            // Verify result
            Assert.IsFalse(result.Succeeded);
            Assert.AreEqual("Driver has more than 2 claims: Test Driver", result.Error);
        }
        public void ValidatePolicy_ShouldSucceed()
        {
            // Setup dependencies
            var policy = new InsurancePolicy
            {
                StartDate = DateTime.UtcNow,
                Drivers   = new List <InsurancePolicyDriver>
                {
                    new InsurancePolicyDriver
                    {
                        FirstName   = "Test",
                        Surname     = "Driver",
                        DateOfBirth = DateTime.UtcNow.AddYears(-30),
                        Claims      = new List <DriverClaim>
                        {
                            new DriverClaim(),
                        }
                    }
                }
            };

            // Call Validate
            var result = policy.Validate();

            // Verify result
            Assert.IsTrue(result.Succeeded);
        }
Ejemplo n.º 23
0
        //// GET api/values/5
        //public string Get(int id)
        //{
        //    return "value";
        //}

        // POST api/values
        public void Post([FromBody] CreatePolicyCommand command)
        {
            var insurancePolicy = new InsurancePolicy(this.ServiceLocator);

            //Create the policy. This is the only way you can create a policy
            insurancePolicy.CreatePolicy(command);
        }
Ejemplo n.º 24
0
        public void HandleRequest_ShouldDecreasePremiumByTenPercentIfAnyAccountants()
        {
            // Setup dependencies
            var policy = new InsurancePolicy
            {
                Drivers = new List <InsurancePolicyDriver>
                {
                    new InsurancePolicyDriver
                    {
                        Occupation = new RefOccupation
                        {
                            Code = Occupation.Accountant.Description()
                        }
                    },
                    new InsurancePolicyDriver
                    {
                        Occupation = new RefOccupation
                        {
                            Code = Occupation.Accountant.Description()
                        }
                    }
                }
            };

            // Call HandleRequest
            var returnedPremium = new InsurancePremiumCalculationOccupationHandler()
                                  .HandleRequest(policy, 100);

            // Verify result
            Assert.AreEqual((double)90, Math.Round(returnedPremium, 2));
        }
Ejemplo n.º 25
0
        public void TestEquals2()
        {
            InsurancePolicy card = new InsurancePolicy()
            {
                Number          = 1,
                Name            = "Alex",
                Surname         = "Ivanov",
                Middlename      = "Ivanovich",
                Sex             = "men",
                DateOfBirth     = new DateTime(2002, 10, 10),
                InsuranceNumber = "685FJ9765BG"
            };

            InsurancePolicy card1 = new InsurancePolicy()
            {
                Number          = card.Number,
                Name            = card.Name,
                Surname         = card.Surname,
                Middlename      = card.Middlename,
                Sex             = card.Sex,
                DateOfBirth     = card.DateOfBirth,
                InsuranceNumber = card.InsuranceNumber
            };

            var actual = card.Equals(card1);

            Assert.IsTrue(actual);
        }
        public async Task PolicyServiceCLient_FetchAll_Returns_All()
        {
            //Arrange
            var mockHttp        = new MockHttpMessageHandler();
            var insurancePolicy = new InsurancePolicy
            {
                EffectiveDate  = DateTime.Now,
                Expiration     = DateTime.Now,
                PolicyNumber   = "123456",
                PrimaryInsured = new PrimaryInsured
                {
                    PrimaryInsuredFirstName = "Mark",
                    PrimaryInsuredLastName  = "Wilson"
                }
            };

            mockHttp.When("http://localhost:50697/api/Policy/fetchall*")
            .Respond("application/json", JsonConvert.SerializeObject(
                         new List <InsurancePolicy> {
                insurancePolicy
            }));

            var client = mockHttp.ToHttpClient();
            var sut    = new PolicyServiceClient(client);

            //Act
            var displayPolicies = await sut.FetchAll();

            //Assert
            Assert.IsTrue(displayPolicies.Count() == 1);
            Assert.AreEqual(123456, displayPolicies.First().PolicyNumber);
        }
Ejemplo n.º 27
0
        public async Task <InsurancePolicy> UpdatePolicyAsync(Guid policyId, string name, string description, float premiumPrice)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (string.IsNullOrEmpty(description))
            {
                throw new ArgumentNullException(nameof(description));
            }

            if (premiumPrice <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(premiumPrice), "Coverage cannot be priced at 0 dollars");
            }

            var policy = await dataRepository.GetPolicyAsync(policyId);

            var updatedPolicy = new InsurancePolicy(policyId, name, description, policy.CoveragePercentages, policy.CoverageStartDate,
                                                    policy.CoverageLengthInMonths, policy.PremiumCostInDollars, policy.InsuredRiskLevel, policy.CoveredClients);

            await dataRepository.StorePolicyAsync(updatedPolicy);

            return(updatedPolicy);
        }
        public void HandleRequest_ShouldIncreasePremiumByTenPercentForLessRecentClaims()
        {
            // Setup dependencies
            var policy = new InsurancePolicy
            {
                StartDate = DateTime.UtcNow,
                Drivers   = new List <InsurancePolicyDriver>
                {
                    new InsurancePolicyDriver
                    {
                        Claims = new List <DriverClaim>
                        {
                            new DriverClaim {
                                DateOfClaim = DateTime.UtcNow.AddMonths(-26)
                            },
                            new DriverClaim {
                                DateOfClaim = DateTime.UtcNow.AddMonths(-37)
                            },
                            new DriverClaim {
                                DateOfClaim = DateTime.UtcNow.AddYears(-10)
                            }
                        }
                    }
                }
            };

            // Call HandleRequest
            var returnedPremium = new InsurancePremiumCalculationClaimsHandler()
                                  .HandleRequest(policy, 100);

            // Verify result
            Assert.AreEqual((double)121, Math.Round(returnedPremium, 2));
        }
        public void HandleRequest_ShouldIncreasePremiumByTwentyPercentForRecentClaims()
        {
            // Setup dependencies
            var policy = new InsurancePolicy
            {
                StartDate = DateTime.UtcNow,
                Drivers   = new List <InsurancePolicyDriver>
                {
                    new InsurancePolicyDriver
                    {
                        Claims = new List <DriverClaim>
                        {
                            new DriverClaim {
                                DateOfClaim = DateTime.UtcNow.AddMonths(-1)
                            },
                            new DriverClaim {
                                DateOfClaim = DateTime.UtcNow.AddMonths(-7)
                            }
                        }
                    }
                }
            };

            // Call HandleRequest
            var returnedPremium = new InsurancePremiumCalculationClaimsHandler()
                                  .HandleRequest(policy, 100);

            // Verify result
            Assert.AreEqual(144, returnedPremium);
        }
        public void HandleRequest_ShouldReturnPremiumIfNoClaims()
        {
            var policy = new InsurancePolicy();

            var returnedPremium = _handler.HandleRequest(policy, 100);

            Assert.AreEqual(100, returnedPremium);
        }