Пример #1
0
        public async Task ConvertToBitcoin_UnsuccessfulHttpRequest_ThrowsBitcoinPriceServiceException()
        {
            var mockHttp = new MockHttpMessageHandler();

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

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

            var conversionInfo = new BitcoinConversionInfo
            {
                Abbreviation = "GBP",
                Amount       = 1323
            };

            await Assert
            .ThrowsAsync <BitcoinPriceService.BitcoinPriceServiceException>(async() =>
                                                                            await service.ConvertToBitcoin(conversionInfo,
                                                                                                           CancellationToken.None));
        }
Пример #2
0
        public async Task ConvertToBitcoin_AbbreviationNull_ThrowsArgumentException()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("https://blockchain.info/tobtc")
            .Respond("application/json",
                     "200");

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

            var conversionInfo = new BitcoinConversionInfo
            {
                Abbreviation = null,
                Amount       = 1323
            };

            await Assert
            .ThrowsAsync <ArgumentException>(async() =>
                                             await service.ConvertToBitcoin(conversionInfo,
                                                                            CancellationToken.None));
        }
Пример #3
0
        public async Task ConvertToBitcoin_ReturnsCorrectResponse()
        {
            var mockHttp = new MockHttpMessageHandler();

            mockHttp.When("https://blockchain.info/tobtc")
            .Respond("application/json",
                     "200");

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

            var conversionInfo = new BitcoinConversionInfo
            {
                Abbreviation = "GBP",
                Amount       = 1323
            };

            var value =
                await service.ConvertToBitcoin(conversionInfo,
                                               CancellationToken.None);

            Assert.Equal(200,
                         value);
        }