public void CanConvertOfferToPolicyBeforeItExpires() { var offer = OffersTestData.StandardOneYearOCOfferValidUntil(new DateTime(2019, 1, 31)); var purchaseDate = new DateTime(2019, 1, 12); var policyStartDate = new DateTime(2019, 1, 15); var policy = Policy.BuyOffer(offer, purchaseDate, policyStartDate); var resultingEvents = policy.GetUncommittedChanges(); //assert state policy .Should() .HaveVersions(1); policy.Versions.WithNumber(1) .Should() .BeActive() .HaveActivePolicyStatus() .HaveTotalPremiumEqualTo(Money.Euro(500)); //assert events Single(resultingEvents); IsType <InitialPolicyVersionCreated>(resultingEvents.First()); }
public void CannotConvertStartPolicyAfterOfferExpiryDate() { var offer = OffersTestData.StandardOneYearOCOfferValidUntil(new DateTime(2019, 1, 10)); var ex = Throws <ApplicationException>(() => Policy.BuyOffer(offer, new DateTime(2019, 1, 10), new DateTime(2019, 1, 15))); Equal("Offer not valid at policy start date", ex.Message); }
public void CannotConvertOfferToPolicyAfterItsRejected() { var offer = OffersTestData.RejectedOfferValidUntil(new DateTime(2019, 1, 10)); var ex = Throws <ApplicationException>(() => Policy.BuyOffer(offer, new DateTime(2019, 1, 10), new DateTime(2019, 1, 10))); Equal("Offer already rejected", ex.Message); }
public void CannotConvertOfferToPolicyAfterItExpires() { var offer = OffersTestData.StandardOneYearOCOfferValidUntil(new DateTime(2019, 1, 10)); var ex = Throws <ApplicationException>(() => Policy.BuyOffer(offer, new DateTime(2019, 1, 12), new DateTime(2019, 1, 15))); Equal("Offer expired", ex.Message); }
public async Task <CreatePolicyResult> Handle(CreatePolicyCommand request, CancellationToken cancellationToken) { var offer = await offerRepository.WithNumber(request.OfferNumber); var policy = Policy.BuyOffer(offer, request.PurchaseDate, request.PolicyStartDate); policyRepository.Save(policy, -1); return(new CreatePolicyResult { PolicyId = policy.Id, PolicyNumber = policy.PolicyNumber }); }
public void CanConvertOfferToPolicyBeforeItExpires() { var offer = OffersTestData.StandardOneYearOCOfferValidUntil(new DateTime(2019, 1, 31)); var purchaseDate = new DateTime(2019, 1, 12); var policyStartDate = new DateTime(2019, 1, 15); var policy = Policy.BuyOffer(offer, purchaseDate, policyStartDate); var resultingEvents = policy.GetUncommittedChanges(); //assert state policy .Should() .HaveVersions(1); policy.Versions.WithNumber(1) .Should() .BeActive() .HaveActivePolicyStatus() .HaveTotalPremiumEqualTo(Money.Euro(500)); //assert events resultingEvents .Should() .BeSingle() .ContainEvent( new InitialPolicyVersionCreated ( policy.PolicyNumber, "STD_CAR_INSURANCE", policyStartDate, policyStartDate.AddDays(365), purchaseDate, new PersonData("Jan", "Kowalski", "1111111116"), new CarData("Ford Focus", "WAW1010", 2005), new List <PolicyCoverData> { new PolicyCoverData("OC", policyStartDate, policyStartDate.AddDays(365), Money.Euro(500), Money.Euro(500), TimeSpan.FromDays(365)) } ) ); }