public ProductItem Post([FromBody] ProductItemAddCommand Product) { Product.Owner = User != null ? (User.FindFirst(ClaimTypes.NameIdentifier))?.Value : "1";//Defaulted to constant 1 to proceed if user null Task <ProductItem> createdProduct = _mediator.Send(Product); return(new ProductItem { Id = createdProduct.Result.Id, Owner = createdProduct.Result.Owner, Title = createdProduct.Result.Title }); }
public void PostTestAsync() { var productItemAddCommand = new ProductItemAddCommand(); mockMediator.Setup(x => x.Send(It.IsAny <ProductItemAddCommand>(), new CancellationToken())).Returns(Task.FromResult(GetProductItem())); var controller = new ProductController(mockProductRepositoryService.Object, mockMediator.Object); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var actionResult = controller.Post(new ProductItemAddCommand { }); Assert.IsInstanceOf <ProductItem>(actionResult); }