public async Task <GetShortestRouteResponse> Handle(GetShortestRouteRequest request, CancellationToken cancellationToken) { ValidationResult result = await ValidateRequest(request); if (!result.IsValid) { return(CreateInvalidResponse(result.Errors[0].ErrorMessage)); } request.Origin = request.Origin.ToUpper(); request.Destination = request.Destination.ToUpper(); var airports = await _service.GetAiports(request.Origin, request.Destination); var validationMessage = ValidateAirports(airports, request.Origin); if (!string.IsNullOrEmpty(validationMessage)) { return(CreateInvalidResponse(validationMessage)); } var response = await GetShortestRoute(airports, request.Origin, request.Destination); if (response == "No Route") { return(new GetShortestRouteResponse(true, true, response)); } return(new GetShortestRouteResponse(true, false, response)); }
public async void Should_ReturnLessThanTwoItems_When_AirpotIsInvalid(string origin, string destination, string fakeResult) { //Arrange var returnList = fakeResult.Split(',').Select(s => new Airport { Iata3 = s }).ToList(); _repository.Setup(s => s.GetAiports(origin, destination)).ReturnsAsync(returnList); //Act var airports = await _service.GetAiports(origin, destination); //Assert Assert.NotNull(airports); Assert.True(airports.Count < 2); }