public async Task UpdateClosingPrices() { var mockRepository = new MockRepository(MockBehavior.Strict); var stockId = Guid.NewGuid(); var messageHandler = mockRepository.Create <IRestClientMessageHandler>(); messageHandler.Setup(x => x.PostAsync <UpdateClosingPricesCommand>( It.Is <string>(x => x == "stocks/" + stockId + "/closingprices"), It.Is <UpdateClosingPricesCommand>(x => x.Id == stockId && x.ClosingPrices.Count == 1))) .Returns(Task.CompletedTask) .Verifiable(); var resource = new StockResource(messageHandler.Object); var update = new UpdateClosingPricesCommand() { Id = stockId }; update.AddClosingPrice(new Date(2000, 01, 02), 12.00m); await resource.UpdateClosingPrices(update); mockRepository.Verify(); }
public void DeserializeUpdateClosingPricesCommand() { var serializer = new RestClientSerializer(); var id = Guid.NewGuid(); var json = "{\"id\":\"" + id + "\"," + "\"closingPrices\":[" + "{\"date\":\"2000-01-01\",\"price\":10.00}" + "]}"; var command = serializer.Deserialize <UpdateClosingPricesCommand>(json); var expected = new UpdateClosingPricesCommand() { Id = id }; expected.AddClosingPrice(new Date(2000, 01, 01), 10.00m); command.Should().BeEquivalentTo(expected); }
public void SerializeUpdateClosingPricesCommand() { var serializer = new RestClientSerializer(); var id = Guid.NewGuid(); var command = new UpdateClosingPricesCommand() { Id = id }; command.AddClosingPrice(new Date(2000, 01, 01), 10.00m); var json = JToken.Parse(serializer.Serialize(command)); var expectedJson = JToken.Parse("{\"id\":\"" + id + "\"," + "\"closingPrices\":[" + "{\"date\":\"2000-01-01\",\"price\":10.00}" + "]}"); json.Should().BeEquivalentTo(expectedJson); }