public async void GetHistoricalPriceDataHttpError() { var mockRepository = new MockRepository(MockBehavior.Strict); var messageHandler = mockRepository.CreateHttpStatusMessageHandler(HttpStatusCode.NotFound); var httpClient = new HttpClient(messageHandler.Object); var dataService = new AsxDataService(httpClient); var result = await dataService.GetHistoricalPriceData("IBM", new DateRange(new Date(2020, 05, 14), new Date(2020, 05, 15)), CancellationToken.None); result.Should().BeEmpty(); }
public async void GetHistoricalPriceDataInvalidJson() { var mockRepository = new MockRepository(MockBehavior.Strict); var json = "xxxxx"; var messageHandler = mockRepository.CreateJsonMessageHandler(json); var httpClient = new HttpClient(messageHandler.Object); var dataService = new AsxDataService(httpClient); var result = await dataService.GetHistoricalPriceData("IBM", new DateRange(new Date(2020, 05, 14), new Date(2020, 05, 15)), CancellationToken.None); result.Should().BeEmpty(); }
public async void GetHistoricalPriceData() { var mockRepository = new MockRepository(MockBehavior.Strict); var json = "{\"data\": [" + " {\"code\":\"BHP\",\"close_date\":\"2020-05-20T00:00:00+1000\",\"close_price\":34.05,\"change_price\":1.95,\"volume\":11664353,\"day_high_price\":35.11,\"day_low_price\":34.32,\"change_in_percent\":\"5.891 % \"}," + " {\"code\":\"BHP\",\"close_date\":\"2020-05-19T00:00:00+1000\",\"close_price\":35.05,\"change_price\":1.95,\"volume\":11664353,\"day_high_price\":35.11,\"day_low_price\":34.32,\"change_in_percent\":\"5.891 % \"}," + " {\"code\":\"BHP\",\"close_date\":\"2020-05-18T00:00:00+1000\",\"close_price\":33.1,\"change_price\":1.43,\"volume\":7894590,\"day_high_price\":33.2,\"day_low_price\":32.37,\"change_in_percent\":\"4.515 % \"}]}"; HttpRequestMessage requestMessage = null; var messageHandler = mockRepository.CreateJsonMessageHandler(json, x => requestMessage = x); var httpClient = new HttpClient(messageHandler.Object); var dataService = new AsxDataService(httpClient); var result = await dataService.GetHistoricalPriceData("BHP", new DateRange(new Date(2020, 05, 18), new Date(2020, 05, 19)), CancellationToken.None); requestMessage.Method.Should().Be(HttpMethod.Get); var days = (Date.Today - new Date(2020, 05, 18)).TotalDays; requestMessage.RequestUri.AbsoluteUri.Should().StartWith("https://www.asx.com.au/asx/1/share/BHP/prices?interval=daily&count=" + days.ToString()); result.Should().BeEquivalentTo(new StockPrice[] { new StockPrice("BHP", new Date(2020, 05, 19), 35.05m), new StockPrice("BHP", new Date(2020, 05, 18), 33.10m) }); }