public async Task <ActionResult> CreateManualStockOperation(ManualStockOperationDto manualStockOperationDto) { await _stockItemAuthorizationLoader.AssertResourceAccessAsync(User, manualStockOperationDto.StockItemId, IsAuthorizedUserPolicy.Instance); return(await SendAndHandleIdentifierResultCommand( new CreateManualStockOperation(Guid.NewGuid(), manualStockOperationDto.StockItemId, manualStockOperationDto.Quantity, User.GetUserId(), manualStockOperationDto.Comment), nameof(GetManualStockOperation) )); }
public void GetManualStockOperation_ConstructsQuery_ReturnsResultOfDispatch() { var stockItemId = TestIds.A; var result = new ManualStockOperationDto(); _dispatcherMock.Setup(d => d.QueryAsync(It.Is <GetManualStockOperation>(q => q.Id == stockItemId))).ReturnsAsync(result).Verifiable(); var actionResult = _controller.GetManualStockOperation(stockItemId).GetAwaiter().GetResult(); Assert.AreEqual(actionResult.Value, result); _dispatcherMock.Verify(); }
public async Task <ActionResult> UpdateManualStockOperation(Guid id, ManualStockOperationDto manualStockOperationDto) { var stockOperation = await _stockOperationsService.GetStockOperation(id); if (stockOperation is null) { return(NotFound()); } await _stockItemAuthorizationLoader.AssertResourceAccessAsync(User, stockOperation.StockItemId, IsAuthorizedUserPolicy.Instance); if (manualStockOperationDto.StockItemId != stockOperation.StockItemId) { await _stockItemAuthorizationLoader.AssertResourceAccessAsync(User, manualStockOperationDto.StockItemId, IsAuthorizedUserPolicy.Instance); } return(await SendAndHandleOperationCommand( new UpdateManualStockOperation(id, manualStockOperationDto.StockItemId, manualStockOperationDto.Quantity, User.GetUserId(), manualStockOperationDto.Comment) )); }