public void DeserializeStockHistoryResponse() { var serializer = new RestClientSerializer(); var id = Guid.NewGuid(); var json = "{\"id\":\"" + id + "\"," + "\"asxCode\":\"ABC\"," + "\"name\":\"ABC Pty Ltd\"," + "\"trust\":true," + "\"listingDate\":\"2000-01-01\"," + "\"delistedDate\":\"9999-12-31\"," + "\"history\":[" + "{\"fromDate\":\"2001-01-02\",\"toDate\":\"2001-01-03\",\"asxCode\":\"OLD\",\"name\":\"Old Name\",\"category\":\"australianStocks\"}" + "]," + "\"dividendRules\":[" + "{\"fromDate\":\"2001-01-02\",\"toDate\":\"2001-01-03\",\"companyTaxRate\":0.45,\"roundingRule\":\"truncate\",\"drpActive\":true,\"drpMethod\":\"roundDown\"}" + "]}"; var command = serializer.Deserialize <StockHistoryResponse>(json); var expected = new StockHistoryResponse() { Id = id, AsxCode = "ABC", Name = "ABC Pty Ltd", ListingDate = new Date(2000, 01, 01), DelistedDate = Date.MaxValue, }; expected.AddHistory(new Date(2001, 01, 02), new Date(2001, 01, 03), "OLD", "Old Name", AssetCategory.AustralianStocks); expected.AddDividendRules(new Date(2001, 01, 02), new Date(2001, 01, 03), 0.45m, RoundingRule.Truncate, true, DrpMethod.RoundDown); command.Should().BeEquivalentTo(expected); }
public static StockHistoryResponse ToHistoryResponse(this Stock stock) { var stockProperties = stock.Properties.ClosestTo(Date.Today); var result = new StockHistoryResponse() { Id = stock.Id, AsxCode = stockProperties.AsxCode, Name = stockProperties.Name, ListingDate = stock.EffectivePeriod.FromDate, DelistedDate = stock.EffectivePeriod.ToDate, }; foreach (var property in stock.Properties.Values.Reverse()) { result.AddHistory(property.EffectivePeriod.FromDate, property.EffectivePeriod.ToDate, property.Properties.AsxCode, property.Properties.Name, property.Properties.Category.ToResponse()); } foreach (var rules in stock.DividendRules.Values.Reverse()) { result.AddDividendRules(rules.EffectivePeriod.FromDate, rules.EffectivePeriod.ToDate, rules.Properties.CompanyTaxRate, rules.Properties.DividendRoundingRule, rules.Properties.DrpActive, rules.Properties.DrpMethod.ToResponse()); } return(result); }
public async Task GetHistory() { var mockRepository = new MockRepository(MockBehavior.Strict); var stock = new StockHistoryResponse() { Id = Guid.NewGuid(), AsxCode = "ABC" }; var messageHandler = mockRepository.Create <IRestClientMessageHandler>(); messageHandler.Setup(x => x.GetAsync <StockHistoryResponse>(It.Is <string>(x => x == "stocks/" + stock.Id + "/history"))) .Returns(Task <StockHistoryResponse> .FromResult(stock)) .Verifiable(); var resource = new StockResource(messageHandler.Object); var result = await resource.GetHistory(stock.Id); result.Should().BeEquivalentTo(stock); mockRepository.Verify(); }