public async Task Returns_current_quotes_for_a_given_cryptocurrency_code() { var request = new CryptocurrencyQuotesRequest { CryptocurrencyCode = BTC }; var expectedResponse = new CryptocurrencyQuotesResponse { BaseCryptocurrencyCode = BTC, Quotes = QuoteCurrencyDetailsOf( (USD, BTC_to_USD), (EUR, BTC_to_EUR), (BRL, BTC_to_BRL), (GBP, BTC_to_GBP), (AUD, BTC_to_AUD)) }; _fakeExchangeRatesService.Setup(service => service.GetQuotesFor(CurrencyCode.Of(BTC))) .ReturnsAsync( QuoteCurrenciesOf( (USD, BTC_to_USD), (EUR, BTC_to_EUR), (BRL, BTC_to_BRL), (GBP, BTC_to_GBP), (AUD, BTC_to_AUD))); var response = await _useCase.Execute(request); response.Should().BeEquivalentTo(expectedResponse); }
private static void TryParseQuoteCurrencyCode( string previousPropertyName, string currentPropertyName, ref CurrencyCode currencyCode) { if (previousPropertyName == QuotesPropertyName) { currencyCode = CurrencyCode.Of(currentPropertyName); } }
public async Task <CryptocurrencyQuotesResponse> Execute(CryptocurrencyQuotesRequest request) { if (request is null) { throw new ArgumentNullException(nameof(request)); } var baseCryptocurrencyCode = CurrencyCode.Of(request.CryptocurrencyCode); var quotes = await _exchangeRatesService.GetQuotesFor(baseCryptocurrencyCode); return(CryptocurrencyQuotesResponse.From(baseCryptocurrencyCode, quotes)); }
public async Task Sets_given_cryptocurrency_code_in_URL_of_get_latest_cryptocurrency_quotes_requests() { ConfigureGetLatestCryptocurrencyQuotesRequestsToRespondSuccessfully(); await _exchangeRatesService.GetQuotesFor(CurrencyCode.Of(BTC)); var foundRequests = _mockServer.FindLogEntries( Request.Create() .WithPath(GetLatestCryptocurrencyQuotesRequestUrlPath) .WithParam(BaseCryptocurrencyCodeParameterName, BTC) .UsingGet()); foundRequests.Should().HaveCount(5); }
public async Task Sets_authentication_header_with_configured_api_key_for_get_latest_cryptocurrency_quotes_request() { ConfigureGetLatestCryptocurrencyQuotesRequestsToRespondSuccessfully(); await _exchangeRatesService.GetQuotesFor(CurrencyCode.Of(BTC)); var foundRequests = _mockServer.FindLogEntries( Request.Create() .WithPath(GetLatestCryptocurrencyQuotesRequestUrlPath) .WithHeader(ApiKeyHeaderName, SampleApiKeyValue) .UsingGet()); foundRequests.Should().HaveCount(5); }
public async Task Returns_quotes_for_base_cryptocurrency_code_when_get_latest_cryptocurrency_quotes_request_responds_with_ok_status() { ConfigureGetLatestCryptocurrencyQuotesRequestsToRespondSuccessfully(); var expectedQuotes = QuoteCurrenciesBuilder.QuoteCurrenciesOf( (USD, BTC_to_USD), (EUR, BTC_to_EUR), (BRL, BTC_to_BRL), (GBP, BTC_to_GBP), (AUD, BTC_to_AUD)); var quotes = await _exchangeRatesService.GetQuotesFor(CurrencyCode.Of(BTC)); quotes.Should().BeEquivalentTo(expectedQuotes); }
public void Is_successfully_created_from_base_cryptocurrency_code_and_quotes_when_both_values_are_present() { var expectedCryptocurrencyQuotesResponse = new CryptocurrencyQuotesResponse { BaseCryptocurrencyCode = BTC, Quotes = new List <QuoteCurrencyDetails> { new QuoteCurrencyDetails { Code = USD, ExchangeRate = BTC_to_USD } } }; var cryptocurrencyQuotesResponse = CryptocurrencyQuotesResponse.From( CurrencyCode.Of(BTC), QuoteCurrenciesOf((USD, BTC_to_USD))); cryptocurrencyQuotesResponse.Should().BeEquivalentTo(expectedCryptocurrencyQuotesResponse); }
public async Task Includes_specific_quote_currency_codes_in_URL_of_get_latest_cryptocurrency_quotes_requests() { ConfigureGetLatestCryptocurrencyQuotesRequestsToRespondSuccessfully(); await _exchangeRatesService.GetQuotesFor(CurrencyCode.Of(BTC)); var foundLatestQuotesForBitcoinToUsDollarRequests = _mockServer.FindLogEntries( Request.Create() .WithPath(GetLatestCryptocurrencyQuotesRequestUrlPath) .WithParam(QuoteCurrencyCodeParameterName, USD) .UsingGet()); var foundLatestQuotesForBitcoinToEuroRequests = _mockServer.FindLogEntries( Request.Create() .WithPath(GetLatestCryptocurrencyQuotesRequestUrlPath) .WithParam(QuoteCurrencyCodeParameterName, EUR) .UsingGet()); var foundLatestQuotesForBitcoinToBrazilianRealRequests = _mockServer.FindLogEntries( Request.Create() .WithPath(GetLatestCryptocurrencyQuotesRequestUrlPath) .WithParam(QuoteCurrencyCodeParameterName, BRL) .UsingGet()); var foundLatestQuotesForBitcoinToPoundSterlingRequests = _mockServer.FindLogEntries( Request.Create() .WithPath(GetLatestCryptocurrencyQuotesRequestUrlPath) .WithParam(QuoteCurrencyCodeParameterName, GBP) .UsingGet()); var foundLatestQuotesForBitcoinToAustralianDollarRequests = _mockServer.FindLogEntries( Request.Create() .WithPath(GetLatestCryptocurrencyQuotesRequestUrlPath) .WithParam(QuoteCurrencyCodeParameterName, AUD) .UsingGet()); foundLatestQuotesForBitcoinToUsDollarRequests.Should().HaveCount(1); foundLatestQuotesForBitcoinToEuroRequests.Should().HaveCount(1); foundLatestQuotesForBitcoinToBrazilianRealRequests.Should().HaveCount(1); foundLatestQuotesForBitcoinToPoundSterlingRequests.Should().HaveCount(1); foundLatestQuotesForBitcoinToAustralianDollarRequests.Should().HaveCount(1); }
public void Requires_quotes_when_created_from_base_cryptocurrency_code_and_quotes() { Action createCryptocurrencyQuotesResponseFromBaseCryptocurrencyCodeAndQuotes = () => CryptocurrencyQuotesResponse.From(CurrencyCode.Of(BTC), null); createCryptocurrencyQuotesResponseFromBaseCryptocurrencyCodeAndQuotes.Should() .ThrowExactly <ArgumentNullException>() .Which.ParamName.Should().Be("quotes"); }
public void Fails_to_return_quotes_for_base_cryptocurrency_code_when_get_latest_cryptocurrency_quotes_request_responds_with_internal_server_error_status() { ConfigureGetLatestCryptocurrencyQuotesRequestsToRespondWithIntervalServerErrorStatus(); Func <Task> executeGetQuotesForBaseCryptocurrencyCode = () => _exchangeRatesService.GetQuotesFor(CurrencyCode.Of(BTC)); executeGetQuotesForBaseCryptocurrencyCode.Should().ThrowExactly <HttpRequestException>(); }
private IEnumerable <Task <HttpResponseMessage> > PrepareGetLatestCryptocurrencyQuotesRequests( CurrencyCode baseCryptocurrencyCode, HttpClient httpClient) => SupportedQuoteCurrencyCodes.Select(code => httpClient.GetAsync( FormatGetLatestCryptocurrencyQuotesRequestUrlPathFor( baseCryptocurrencyCode, CurrencyCode.Of(code))));