public async Task EditPolicyAsyncShoudEditSucessfullyPolicy() { const int policyId = 2; //Arrange var editingPolicy = new InsurancePolicyFormServiceModel { StartDate = DateTime.Parse("2021-12-31 23:59:59.9999999"), EndDate = DateTime.Parse("2022-01-01 00:00:00.0000000"), Expired = false, InsuranceCompanyId = 4, TypeInsurance = TypeInsurance.FullCasco, }; //Act ////Active FullCasco insurance await this.insuranceServices.EditPolicyAsync(policyId, editingPolicy); var editedPolicy = await this.fixture .Context .InsurancePolicies .FirstOrDefaultAsync(i => i.Id == policyId); //Assert Assert.Equal(editingPolicy.StartDate, editedPolicy.StartDate); Assert.Equal(editingPolicy.EndDate, editedPolicy.EndDate); Assert.Equal(editingPolicy.Expired, editedPolicy.Expired); Assert.Equal(editingPolicy.InsuranceCompanyId, editedPolicy.InsuranceCompanyId); Assert.Equal(editingPolicy.TypeInsurance, editedPolicy.TypeInsurance); }
public async Task AddPolicyAsync(int vehicleId, InsurancePolicyFormServiceModel newPolicy) { if (!this.CompareStartEndDate(newPolicy.StartDate, newPolicy.EndDate)) { throw new ArgumentException(WrongDateExceptionMessage); } if (!await ExistInsuranceCompany(newPolicy.InsuranceCompanyId)) { throw new ArgumentException(NotExistItemExceptionMessage); } if (await ExistTypeOfInsurancePolicyOnVehicle( vehicleId, newPolicy.TypeInsurance)) { throw new ArgumentException(ExistItemExceptionMessage); } var newInsurancePolicy = this.mapper .Map <InsurancePolicyFormServiceModel, Data.Models.InsurancePolicy>(newPolicy, opt => opt.ConfigureMap() .ForMember(p => p.Id, opt => opt.Ignore()) .ForMember(p => p.InsuanceCompany, opt => opt.Ignore()) .ForMember(p => p.Vehicle, opt => opt.Ignore()) .ForMember(p => p.VehicleId, opt => opt.Ignore())); newInsurancePolicy.VehicleId = vehicleId; await this.db.InsurancePolicies.AddAsync(newInsurancePolicy); await this.db.SaveChangesAsync(); }
public async Task AddPolicyAsyncShouldReturnErrorIfStartDateIsBiggerOrEqualEndDateAndLessThanOneYear(string startDate, string endDate) { //Arrange var model = new InsurancePolicyFormServiceModel { StartDate = DateTime.Parse(startDate), EndDate = DateTime.Parse(endDate) }; //Act var exceptionMessage = await Assert.ThrowsAsync <ArgumentException>(() => this.insuranceServices.AddPolicyAsync(0, model)); //Assert Assert.Equal(WrongDateExceptionMessage, exceptionMessage.Message); }
public async Task AddPolicyAsyncShouldReturnErrorIfInsuranceCompanyDoesnExist() { //Arrange var model = new InsurancePolicyFormServiceModel { StartDate = DateTime.Parse("2021-01-01 00:00:00.0000000"), EndDate = DateTime.Parse("2022-01-01 00:00:00.0000000"), InsuranceCompanyId = int.MaxValue }; //Act var exceptionMessage = await Assert.ThrowsAsync <ArgumentException>(() => this.insuranceServices.AddPolicyAsync(0, model)); //Assert Assert.Equal(NotExistItemExceptionMessage, exceptionMessage.Message); }
public async Task AddPolicyAsyncShouldReturnErrorIfVehicleHasActiveInsurance(TypeInsurance typeInsurance) { //Arrange var model = new InsurancePolicyFormServiceModel { StartDate = DateTime.UtcNow, EndDate = DateTime.Parse("2022-01-01 00:00:00.0000000"), InsuranceCompanyId = 2, TypeInsurance = typeInsurance }; //Act var exceptionMessage = await Assert.ThrowsAsync <ArgumentException>(() => this.insuranceServices.AddPolicyAsync(1, model)); //Assert Assert.Equal(ExistItemExceptionMessage, exceptionMessage.Message); }
public async Task EditPolicyAsyncShoudReturnErrorIfDatesIsNotValid(string startDate, string endDate) { //Arrange var model = new InsurancePolicyFormServiceModel { StartDate = DateTime.Parse(startDate), EndDate = DateTime.Parse(endDate), }; //Act foreach (var item in await this.fixture.AllInsurancePoliciesAsync()) { var exceptionMessage = await Assert.ThrowsAsync <ArgumentException>(() => this.insuranceServices.EditPolicyAsync(item.Id, model)); //Assert Assert.Equal(WrongDateExceptionMessage, exceptionMessage.Message); } }
public async Task EditPolicyAsync(int insuranceId, InsurancePolicyFormServiceModel insurancePolicyModel) { var existInsurancePolicy = await this.db.InsurancePolicies.FindAsync(insuranceId); if (existInsurancePolicy == null) { throw new ArgumentException(NotExistItemExceptionMessage); } if (!this.CompareStartEndDate(insurancePolicyModel.StartDate, insurancePolicyModel.EndDate)) { throw new ArgumentException(WrongDateExceptionMessage); } existInsurancePolicy.TypeInsurance = insurancePolicyModel.TypeInsurance; existInsurancePolicy.StartDate = insurancePolicyModel.StartDate; existInsurancePolicy.EndDate = insurancePolicyModel.EndDate; existInsurancePolicy.Expired = insurancePolicyModel.Expired; existInsurancePolicy.InsuranceCompanyId = insurancePolicyModel.InsuranceCompanyId; await this.db.SaveChangesAsync(); }