public async Task ChangeStock() { var mockRepository = new MockRepository(MockBehavior.Strict); var stockId = Guid.NewGuid(); var messageHandler = mockRepository.Create <IRestClientMessageHandler>(); messageHandler.Setup(x => x.PostAsync <ChangeStockCommand>( It.Is <string>(x => x == "stocks/" + stockId + "/change"), It.Is <ChangeStockCommand>(x => x.Id == stockId && x.AsxCode == "ABC"))) .Returns(Task.CompletedTask) .Verifiable(); var resource = new StockResource(messageHandler.Object); var change = new ChangeStockCommand() { Id = stockId, AsxCode = "ABC", }; await resource.ChangeStock(change); mockRepository.Verify(); }
public ActionResult ChangeStock([FromRoute] Guid id, [FromBody] ChangeStockCommand 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 result = _StockService.ChangeStock(id, command.ChangeDate, command.AsxCode, command.Name, command.Category.ToDomain()); return(result.ToActionResult()); }
public void ChangeStockValidationError() { var command = new ChangeStockCommand() { Id = _ValidationErrorId, ChangeDate = new Date(2009, 01, 01), AsxCode = "XYZ", Name = "XYZ Name", Category = RestApi.Stocks.AssetCategory.AustralianFixedInterest }; var response = _Controller.ChangeStock(_Stock.Id, command); response.Should().BeBadRequestObjectResult(); }
public void ChangeStockInvalidId() { var command = new ChangeStockCommand() { Id = _MissingStockId, ChangeDate = new Date(2012, 01, 01), AsxCode = "XYZ", Name = "XYZ Name", Category = RestApi.Stocks.AssetCategory.AustralianFixedInterest }; var response = _Controller.ChangeStock(_MissingStockId, command); response.Should().BeNotFoundResult(); }
public async void AdminUserHasUpdateAccess() { var client = new RestClient(_Fixture.CreateClient(), "https://integrationtest.com/api/"); await client.Authenticate("AdminUser", "secret"); var command = new ChangeStockCommand() { Id = Ids.BHP, ChangeDate = new Date(2013, 01, 02), AsxCode = "ABC", Category = RestApi.Stocks.AssetCategory.AustralianStocks, }; await client.Stocks.ChangeStock(command); }
public void ChangeStock() { var command = new ChangeStockCommand() { Id = _Stock.Id, ChangeDate = new Date(2009, 01, 01), AsxCode = "XYZ", Name = "XYZ Name", Category = RestApi.Stocks.AssetCategory.AustralianFixedInterest }; var response = _Controller.ChangeStock(_Stock.Id, command); response.Should().BeOkResult(); _StockServiceMock.Verify(x => x.ChangeStock(_Stock.Id, new Date(2009, 01, 01), "XYZ", "XYZ Name", Domain.Stocks.AssetCategory.AustralianFixedInterest)); }
public async void StandardUserShouldNotHaveUpdateAccess() { var client = new RestClient(_Fixture.CreateClient(), "https://integrationtest.com/api/"); await client.Authenticate("StandardUser", "secret"); var command = new ChangeStockCommand() { Id = Ids.BHP, ChangeDate = new Date(2013, 01, 02), AsxCode = "ABC", Category = RestApi.Stocks.AssetCategory.AustralianStocks, }; Func <Task> a = async() => await client.Stocks.ChangeStock(command); a.Should().Throw <RestException>().Which.StatusCode.Should().Be(HttpStatusCode.Forbidden); }
public void DeserializeChangeStockCommand() { var serializer = new RestClientSerializer(); var id = Guid.NewGuid(); var json = "{\"id\":\"" + id + "\"," + "\"changeDate\":\"2013-01-02\"," + "\"asxCode\":\"ABC\"," + "\"name\":\"ABC Pty Ltd\"," + "\"category\":\"australianStocks\"}"; var command = serializer.Deserialize <ChangeStockCommand>(json); var expected = new ChangeStockCommand() { Id = id, ChangeDate = new Date(2013, 01, 02), AsxCode = "ABC", Name = "ABC Pty Ltd", Category = AssetCategory.AustralianStocks }; command.Should().BeEquivalentTo(expected); }
public async Task ChangeStock(ChangeStockCommand command) { await _MessageHandler.PostAsync <ChangeStockCommand>("stocks/" + command.Id.ToString() + "/change", command); }