Beispiel #1
0
        public async Task GetAllCurrencies_MappingCorrect()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("https://blockchain.info/ticker")
            .Respond("application/json",
                     "{\r\n  \"USD\" : {\"15m\" : 52374.71, \"last\" : 52374.71, \"buy\" : 52374.71, \"sell\" : 52374.71, \"symbol\" : \"$\"}\r\n}");

            var service = new BitcoinPriceService(_configuration.Object,
                                                  mockHttp.ToHttpClient());

            var res =
                await service.GetCurrentPrices(CancellationToken.None);

            var dto = res.FirstOrDefault()
                      .Value;

            Assert.Single(res);
            Assert.Equal("USD",
                         res.FirstOrDefault()
                         .Key);
            Assert.Equal(52374.71,
                         dto._15m);
            Assert.Equal(52374.71,
                         dto.Last);
            Assert.Equal(52374.71,
                         dto.Buy);
            Assert.Equal(52374.71,
                         dto.Sell);
            Assert.Equal("$",
                         dto.Symbol);
        }
Beispiel #2
0
        public async Task GetAllCurrencies_UnsuccessfulHttpRequest_ThrowsBitcoinPriceServiceException()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("https://blockchain.info/ticker")
            .Respond(HttpStatusCode.InternalServerError);

            var service = new BitcoinPriceService(_configuration.Object,
                                                  mockHttp.ToHttpClient());

            await Assert
            .ThrowsAsync <BitcoinPriceService.BitcoinPriceServiceException>(async() =>
                                                                            await service.GetCurrentPrices(CancellationToken.None));
        }