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 UpdateClosingPrices() { var command = new UpdateClosingPricesCommand() { Id = _Stock.Id }; var response = _Controller.UpdateClosingPrices(_Stock.Id, command); response.Should().BeOkResult(); }
public void UpdateClosingPricesValidationError() { var command = new UpdateClosingPricesCommand() { Id = _ValidationErrorId }; var response = _Controller.UpdateClosingPrices(_ValidationErrorId, command); response.Should().BeBadRequestObjectResult(); }
public void UpdateClosingPricesInvalidId() { var command = new UpdateClosingPricesCommand() { Id = _MissingStockId }; var response = _Controller.UpdateClosingPrices(_MissingStockId, command); response.Should().BeNotFoundResult(); }
public ActionResult UpdateClosingPrices([FromRoute] Guid id, [FromBody] UpdateClosingPricesCommand command) { // Check id in URL and id in command match if (id != command.Id) { return(BadRequest("Id in command doesn't match id on URL")); } var closingPrices = command.ClosingPrices.Select(x => new StockPrice(x.Date, x.Price)); var result = _StockService.UpdateClosingPrices(id, closingPrices); return(result.ToActionResult()); }
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); }
public async Task UpdateClosingPrices(UpdateClosingPricesCommand command) { await _MessageHandler.PostAsync <UpdateClosingPricesCommand>("stocks/" + command.Id.ToString() + "/closingprices", command); }