コード例 #1
0
        public async void WhenServerTimeoutErrorOccurs_TimeoutExceptionThrown()
        {
            // Arrange

            var httpClient          = FakeHttpClientFactory.CreateFakeHttpClientForTimeout();
            StockQuoteClient client = new StockQuoteClient(httpClient);

            // Act and Assert
            var result = await Assert.ThrowsAsync <TimeoutException>(() => client.GetStockQuote("ZVZZT"));
        }
コード例 #2
0
        public async void WhenInternalServerError_UnknownTickerSymbolExceptionThrown()
        {
            // Arrange

            var httpClient          = FakeHttpClientFactory.CreateFakeHttpClientForStringContent(HttpStatusCode.InternalServerError, "text/plain", "Internal Server Error");
            StockQuoteClient client = new StockQuoteClient(httpClient);

            // Act and Assert
            var result = await Assert.ThrowsAsync <ApplicationException>(() => client.GetStockQuote("ZVZZT"));
        }
コード例 #3
0
        public async void WhenTickerSymbolNotFound_UnknownTickerSymbolExceptionThrown()
        {
            // Arrange

            var httpClient          = FakeHttpClientFactory.CreateFakeHttpClientForStringContent(HttpStatusCode.NotFound, "text/plain", "Symbol not found");
            StockQuoteClient client = new StockQuoteClient(httpClient);

            // Act and Assert
            var result = await Assert.ThrowsAsync <UnknownTickerSymbolException>(() => client.GetStockQuote("ZVZZT"));

            Assert.Equal("ZVZZT", result.TickerSymbol);
        }
コード例 #4
0
        public async void TestStockTickerGoodResult()
        {
            // Arrange
            var httpClient          = FakeHttpClientFactory.CreateFakeHttpClientForJsonStringContent(HttpStatusCode.OK, AAPL_QUOTE);
            StockQuoteClient client = new StockQuoteClient(httpClient);

            // Act
            var result = await client.GetStockQuote("AAPL");

            // Assert
            Assert.Equal("AAPL", result.Symbol);
        }