public async Task <SurchargeRateCreateResponseDto> CreateSurchargeRateAsync(SurchargeRateCreateRequestDto request) { var isProductIdExists = await _productTypeService.IsProductTypeIdExistsAsync(request.ProductTypeId); if (!isProductIdExists) { var message = $"ProductTypeId[{request.ProductTypeId}] is not found."; _logger.LogError(message); throw new SurchargeRateProductTypeNotFoundException(message); } var productTypeSurchargeRate = new ProductTypeSurchargeRate() { ProductTypeId = request.ProductTypeId, SurchargeRates = request.SurchareRates.Select(r => new SurchargeRate() { Rate = r }).ToList() }; var surchargeRate = await _surchargeRateManager.CreateSurchargeRateAsync(productTypeSurchargeRate); return(new SurchargeRateCreateResponseDto() { SurchareRates = surchargeRate.SurchargeRates.Select(r => r.Rate).ToList(), ProductTypeId = surchargeRate.ProductTypeId }); }
public async Task AddProductTypeSurchargeRates_ExpectedCreated(SurchargeRateCreateRequestDto surchargeRateCreateRequestDto) { //we need async data structure for storing the product type and its surcharge rate var result = await _surchargeRateController.CreateSurchargeRateAsync(surchargeRateCreateRequestDto); Assert.IsType <OkObjectResult>(result); Assert.Equal( expected: surchargeRateCreateRequestDto.ProductTypeId, actual: ((SurchargeRateCreateResponseDto)((OkObjectResult)result).Value).ProductTypeId ); Assert.Equal( expected: surchargeRateCreateRequestDto.SurchareRates, actual: ((SurchargeRateCreateResponseDto)((OkObjectResult)result).Value).SurchareRates ); }
public async Task GetProductInsurance_SalesPriceAbove2000_WithSurchargeRate_ExpectedInsurance2500Euros(int productId, float expectedInsuranceValue, SurchargeRateCreateRequestDto surchargeRateCreateRequestDto) { var createSurchargeRateResponse = await _surchargeRateController.CreateSurchargeRateAsync(surchargeRateCreateRequestDto); Assert.IsType <OkObjectResult>(createSurchargeRateResponse); var result = await _productInsuranceController.GetProductInsuranceAsync(productId); Assert.IsType <OkObjectResult>(result); Assert.Equal( expected: expectedInsuranceValue, actual: ((InsuranceResponseDto)((OkObjectResult)result).Value).InsuranceValue ); }
public async Task <IActionResult> CreateSurchargeRateAsync([FromBody] SurchargeRateCreateRequestDto request) { var surchargeRateCreateResponse = await _surchargeRateService.CreateSurchargeRateAsync(request); return(new OkObjectResult(surchargeRateCreateResponse)); }