コード例 #1
0
    private static Result <IataPoint> ValidateApiResponse(string iata, IApiResponse <PlacesApiResponse> response)
    {
        if (!response.IsSuccessStatusCode)
        {
            return(Result.Failure <IataPoint>(
                       response.StatusCode == HttpStatusCode.NotFound
                    ? ErrorMessages.ExternalApiIataNotFound.Template(iata)
                    : ErrorMessages.ExternalApiFailed));
        }

        var placeInfo = response.Content;

        if (placeInfo?.Iata == null || placeInfo.Location == null)
        {
            return(Result.Failure <IataPoint>(ErrorMessages.ExternalApiInvalidResponse));
        }

        var location = new Location(placeInfo.Location.Lat, placeInfo.Location.Lon);

        return(new IataPoint(placeInfo.Iata, location));
    }
コード例 #2
0
 private void SetupRepositoryGetAsyncMethod(Location location)
 => this.repositoryMock
 .Setup(x => x.GetAsync(
            It.IsAny <string>(),
            It.IsAny <CancellationToken>()))
 .ReturnsAsync(location);