Esempio n. 1
0
        //Identical to above, except only returning a single SimpleCoin instead of a list.
        public async Task <IActionResult> GetLivePriceAsync()
        {
            SimpleCoin newCoin = new SimpleCoin();

            using (var client = new HttpClient())
            {
                try
                {
                    client.BaseAddress = new Uri("https://min-api.cryptocompare.com");

                    var response = await client.GetAsync($"/data/price?fsym=BTC&tsyms=USD");

                    response.EnsureSuccessStatusCode();
                    var stringResult = await response.Content.ReadAsStringAsync();

                    var rawData = PriceOnly.FromJson(stringResult);

                    newCoin.Currency = "USD";
                    newCoin.USD      = rawData.Usd;
                }
                catch (HttpRequestException httpRequestException)
                {
                    return(BadRequest($"Error getting requested price history from CryptoCompare: {httpRequestException.Message}"));
                }
                return(Json(newCoin));
            }
        }
Esempio n. 2
0
        public void SetGetPrice()
        {
            // Arrange
            PriceOnly priceOnly = this.CreatePriceOnly();
            double    price     = 5.42;


            // Act
            priceOnly.Usd = price;


            // Assert
            Assert.Equal(priceOnly.Usd, price);
        }