コード例 #1
0
        public async Task SuccessfulRequestReturnsListofStocks()
        {
            Environment.SetEnvironmentVariable("API_KEY", "123");
            Environment.SetEnvironmentVariable("API_HOST", "www.host");
            Environment.SetEnvironmentVariable("API_BASE_ADDRESS", "http://www.xyz.com");

            var responseMessage = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent("{\"quoteResponse\":{\"result\":[{\"symbol\":\"AAPL\",\"bid\":100}] }}")
            };

            var httpClient = new HttpClient(new MockHttpMessageHandler(responseMessage));

            var stockClient = new StockQuoteClient(httpClient);

            var stockList = new List <string>();

            stockList.Add("AAPL");
            var actual = await stockClient.GetQuotes(stockList);

            var expectedStock = new Stock();

            expectedStock.Symbol = "AAPL";
            expectedStock.Price  = 100;

            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(expectedStock.Price, actual[0].Price);
            Assert.AreEqual(expectedStock.Symbol, actual[0].Symbol);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: jowasp/WebSocket-Samples
        static void Main(string[] args)
        {
            var context = new InstanceContext(new QuoteHandler());
            StockQuoteClient client = new StockQuoteClient(context);

            client.StartSendingQuotes();
            Console.ReadLine();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            var context             = new InstanceContext(new QuoteHandler());
            StockQuoteClient client = new StockQuoteClient(context);

            client.StartSendingQuotes();
            Console.ReadLine();
        }
コード例 #4
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"));
        }
コード例 #5
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"));
        }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
0
        public async Task BadRequestReturnsNull()
        {
            Environment.SetEnvironmentVariable("API_KEY", "123");
            Environment.SetEnvironmentVariable("API_HOST", "www.host");
            Environment.SetEnvironmentVariable("API_BASE_ADDRESS", "http://www.xyz.com");

            var responseMessage = new HttpResponseMessage(HttpStatusCode.BadRequest);

            var httpClient = new HttpClient(new MockHttpMessageHandler(responseMessage));

            var stockClient = new StockQuoteClient(httpClient);

            var stockList = new List <string>();

            stockList.Add("AAPL");
            var result = await stockClient.GetQuotes(stockList);

            Assert.IsNull(result);
        }