public async Task WhenServiceThrows_ThenReturnServerError() { var requestModel = new TotalFeeRequestModel() { VehicleType = Fixture.Create <TotalFeeRequestModel.Vehicle>(), PassageDates = new[] { new DateTime(2021, 04, 06, 17, 53, 0) } }; _tollFeeService.GetTotalFee(Arg.Any <Vehicle>(), Arg.Any <List <DateTime> >()).Throws <Exception>(); var response = await SUT.GetTotalFee(requestModel); response.Should().BeOfType <ObjectResult>(); }
public async Task WhenServiceRunsNormal_ThenReturnOkResult() { var requestModel = new TotalFeeRequestModel() { VehicleType = Fixture.Create <TotalFeeRequestModel.Vehicle>(), PassageDates = new[] { new DateTime(2021, 04, 06, 17, 53, 0) } }; _tollFeeService.GetTotalFee(Arg.Any <Vehicle>(), Arg.Any <List <DateTime> >()).Returns(1); var response = await SUT.GetTotalFee(requestModel); response.Should().BeOfType <OkObjectResult>(); }
public async Task <IActionResult> GetTotalFee([FromQuery] TotalFeeRequestModel requestModel) { try { var totalFee = await _tollFeeService.GetTotalFee(requestModel.VehicleTypeToDomain(), requestModel.PassageDates.ToList()); return(Ok(new TotalFeeResponseModel { TotalFee = totalFee })); } catch (EnumCastException) { return(BadRequest("Unable to parse VehicleType input")); } catch (Exception e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e)); } }