コード例 #1
0
        public async Task GetCryptoCurrenciesAsync_WithoutActiveCryptoCurrency_ReturnListIsEmpty()
        {
            // Arrange
            Initialize();

            var getCryptoCurrencies = new GetCryptoCurrencies
            {
                Status = new StatusData
                {
                    ErrorCode = 0
                },
                CryptoCurrencies = new List <CryptoCurrencyData>
                {
                    new CryptoCurrencyData
                    {
                        Id       = 1,
                        IsActive = false,
                        Name     = "Bitcoin"
                    }
                }
            };

            _coinMarketCapProxy.Setup(x => x.GetCryptoCurrenciesAsync()).ReturnsAsync(getCryptoCurrencies);

            // Act
            var result = await _cryptoCurrencyService.GetCryptoCurrenciesAsync();

            // Assert
            Assert.NotNull(result);
            Assert.True(result.Count() == 0);
            _coinMarketCapProxy.Verify(x => x.GetCryptoCurrenciesAsync(), Times.Once);
        }
コード例 #2
0
        public async Task GetCryptoCurrenciesAsync_WithActiveCryptoCurrency_ReturnListContainsActiveItems()
        {
            // Arrange
            Initialize();

            var getCryptoCurrencies = new GetCryptoCurrencies
            {
                Status = new StatusData
                {
                    ErrorCode = 0
                },
                CryptoCurrencies = new List <CryptoCurrencyData>
                {
                    new CryptoCurrencyData
                    {
                        Id       = 1,
                        IsActive = false,
                        Name     = "Bitcoin"
                    },
                    new CryptoCurrencyData
                    {
                        Id       = 3,
                        Name     = "Namecoin",
                        IsActive = true
                    },
                    new CryptoCurrencyData
                    {
                        Id       = 4,
                        Name     = "Terracoin",
                        IsActive = true
                    }
                }
            };

            _coinMarketCapProxy.Setup(x => x.GetCryptoCurrenciesAsync()).ReturnsAsync(getCryptoCurrencies);

            // Act
            var result = await _cryptoCurrencyService.GetCryptoCurrenciesAsync();

            // Assert
            Assert.NotNull(result);
            Assert.True(result.Count() == 2);

            var namecoinCryptoCurrency = result.FirstOrDefault(x => x.Name == "Namecoin");

            Assert.NotNull(namecoinCryptoCurrency);
            Assert.Equal(3, namecoinCryptoCurrency.Id);
            Assert.True(namecoinCryptoCurrency.IsActive);

            var terracoinCryptoCurrency = result.FirstOrDefault(x => x.Name == "Terracoin");

            Assert.NotNull(terracoinCryptoCurrency);
            Assert.Equal(4, terracoinCryptoCurrency.Id);
            Assert.True(terracoinCryptoCurrency.IsActive);

            _coinMarketCapProxy.Verify(x => x.GetCryptoCurrenciesAsync(), Times.Once);
        }
コード例 #3
0
        public async Task GetCryptoCurrencyQuoteAsync_InactiveCryptoCurrency_ReturnRequestedCryptoCurrencyIsNotActiveInMessage()
        {
            // Arrange
            Initialize();

            var request = new GetCryptoCurrencyQuoteRequest
            {
                CryptoCurrencySymbol = "BTN"
            };

            GetCryptoCurrencies getCryptoCurrenciesResponse = new GetCryptoCurrencies
            {
                CryptoCurrencies = new List <CryptoCurrencyData>
                {
                    new CryptoCurrencyData
                    {
                        Id       = 1,
                        Name     = "Bitcoin",
                        Symbol   = "BTN",
                        IsActive = false
                    }
                },
                Status = new StatusData
                {
                    ErrorCode = 0
                }
            };

            _coinMarketCapProxy.Setup(x => x.GetCryptoCurrenciesAsync()).ReturnsAsync(getCryptoCurrenciesResponse);

            // Act
            var result = await _cryptoCurrencyService.GetCryptoCurrencyQuoteAsync(request).ConfigureAwait(false);

            // Assert
            Assert.NotNull(result);
            Assert.False(result.Success);
            Assert.Equal("Requested Crypto Currency Is Not Active.", result.Message);
            Assert.Null(result.Quotes);
            Assert.Equal(string.Empty, result.CryptoCurrencySymbol);

            _coinMarketCapProxy.Verify(x => x.GetCryptoCurrenciesAsync(), Times.Once);
        }
コード例 #4
0
        public async Task GetCryptoCurrencyQuoteAsync_CryptoCurrencyQuoteWithExchangeApproach_VerifyCoinMarketCapProxyMethodsVerifyExchangeRatesProxyOnce()
        {
            // Arrange
            Initialize();
            _appSettings.CalculateQuoteApproach = "CryptoCurrencyQuoteWithExchangeApproach";
            _appSettings.Currencies             = new List <string> {
                "USD", "EUR"
            };
            _appSettings.BaseCurrency = "USD";
            _appSettings.MaximumFloatingPointDigit = 3;

            string cryptoCurrencySymbol = "BTN";
            int    cryptoCurrencyId     = 1;

            var request = new GetCryptoCurrencyQuoteRequest
            {
                CryptoCurrencySymbol = cryptoCurrencySymbol
            };

            GetCryptoCurrencies getCryptoCurrenciesResponse = new GetCryptoCurrencies
            {
                CryptoCurrencies = new List <CryptoCurrencyData>
                {
                    new CryptoCurrencyData
                    {
                        Id       = cryptoCurrencyId,
                        Name     = "Bitcoin",
                        Symbol   = cryptoCurrencySymbol,
                        IsActive = true
                    }
                },
                Status = new StatusData
                {
                    ErrorCode = 0
                }
            };

            _coinMarketCapProxy.Setup(x => x.GetCryptoCurrenciesAsync()).ReturnsAsync(getCryptoCurrenciesResponse);

            GetCryptoCurrencyQuotes getCryptoCurrencyQuotesRequestForUSD = null;
            decimal usdPrice = 100000;
            CryptoCurrencyQuotesData getCryptoCurrencyQuotesResponseForUSD = new CryptoCurrencyQuotesData
            {
                Data = new Dictionary <string, CryptoCurrencyQuoteData> {
                    { cryptoCurrencyId.ToString(), new CryptoCurrencyQuoteData {
                          Id = cryptoCurrencyId, Quotes = new Dictionary <string, QuoteData> {
                              { "USD", new QuoteData {
                                                                                                         Price = usdPrice
                                                                                                     } }
                          }
                      } }
                }
            };

            _coinMarketCapProxy.Setup(x => x.GetCryptoCurrencyQuotesAsync(It.IsAny <GetCryptoCurrencyQuotes>()))
            .Callback <GetCryptoCurrencyQuotes>(x => getCryptoCurrencyQuotesRequestForUSD = x)
            .ReturnsAsync(getCryptoCurrencyQuotesResponseForUSD);


            decimal         eurRateToUsd     = 0.1m;
            GetExchangeData exchangeRequest  = null;
            ExchangeData    exchangeResponse = new ExchangeData
            {
                Base  = _appSettings.BaseCurrency,
                Rates = new Dictionary <string, decimal> {
                    { "EUR", eurRateToUsd }
                }
            };

            _exchangeRatesProxy.Setup(x => x.GetExchangeRateAsync(It.IsAny <GetExchangeData>())).Callback <GetExchangeData>(x => exchangeRequest = x).ReturnsAsync(exchangeResponse);


            // Act
            var result = await _cryptoCurrencyService.GetCryptoCurrencyQuoteAsync(request).ConfigureAwait(false);

            // Assert
            Assert.NotNull(result);
            Assert.True(result.Success);
            Assert.Equal("Success", result.Message);
            Assert.NotNull(result.Quotes);
            Assert.Equal(cryptoCurrencySymbol, result.CryptoCurrencySymbol);

            Assert.True(result.Quotes.Count() == 2);
            var usdQuote = result.Quotes.FirstOrDefault(x => x.Key == "USD");

            Assert.NotNull(usdQuote);
            Assert.Equal(usdPrice, usdQuote.Value);
            var eurQuote = result.Quotes.FirstOrDefault(x => x.Key == "EUR");

            Assert.NotNull(eurQuote);
            Assert.Equal(decimal.Round(eurRateToUsd * usdPrice, _appSettings.MaximumFloatingPointDigit), eurQuote.Value);


            _coinMarketCapProxy.Verify(x => x.GetCryptoCurrenciesAsync(), Times.Once);
            _exchangeRatesProxy.Verify(x => x.GetExchangeRateAsync(It.IsAny <GetExchangeData>()), Times.Once);
            Assert.NotNull(exchangeRequest);
            Assert.Equal(_appSettings.BaseCurrency, exchangeRequest.BaseCurrency);
            Assert.NotNull(exchangeRequest.TargetCurrencies);
            Assert.True(_appSettings.Currencies.Count() == exchangeRequest.TargetCurrencies.Count());

            foreach (var currency in _appSettings.Currencies)
            {
                Assert.Contains(currency, exchangeRequest.TargetCurrencies);
            }

            _coinMarketCapProxy.Verify(x => x.GetCryptoCurrencyQuotesAsync(It.IsAny <GetCryptoCurrencyQuotes>()), Times.Once);

            Assert.NotNull(getCryptoCurrencyQuotesRequestForUSD);
            Assert.NotNull(getCryptoCurrencyQuotesRequestForUSD.CryptoCurrencies);
            Assert.True(getCryptoCurrencyQuotesRequestForUSD.CryptoCurrencies.Count() == 1);
            Assert.Contains(cryptoCurrencyId, getCryptoCurrencyQuotesRequestForUSD.CryptoCurrencies);

            Assert.NotNull(getCryptoCurrencyQuotesRequestForUSD.ConvertCurrencies);
            Assert.True(getCryptoCurrencyQuotesRequestForUSD.ConvertCurrencies.Count() == 1);
            Assert.Contains("USD", getCryptoCurrencyQuotesRequestForUSD.ConvertCurrencies);
        }