Ejemplo n.º 1
0
        public async Task When_ThrowAnyException_Should_ReturnFriendlyErrorMessage()
        {
            // arrange
            var handler    = GetMockedHttpHandler("exception content");
            var httpClient = new HttpClient(handler.Object);
            var stooqApi   = new StooqApi(_loggerMock.Object, httpClient, _configurationMock.Object);

            // act
            var result = await stooqApi.GetStockQuote("STOCK");

            // assert
            result.ShouldBe($"Oops, Something Went Wrong Please Try Again!");

            handler.Protected().Verify(
                "SendAsync",
                Times.Exactly(1),
                ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get),
                ItExpr.IsAny <CancellationToken>());
        }
Ejemplo n.º 2
0
        public async Task When_StooqApiReturns200_With_InvalidContent_Should_ReturnNotFoundMessage()
        {
            // arrange
            var handler    = GetMockedHttpHandler(InvalidContent);
            var httpClient = new HttpClient(handler.Object);
            var stooqApi   = new StooqApi(_loggerMock.Object, httpClient, _configurationMock.Object);

            // act
            var result = await stooqApi.GetStockQuote("STOCK");

            // assert
            result.ShouldBe($"Stock STOCK not found");

            handler.Protected().Verify(
                "SendAsync",
                Times.Exactly(1),
                ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get),
                ItExpr.IsAny <CancellationToken>());
        }