示例#1
0
        public async Task TestExecuteSaveShouldReturnProductViewModelAndStringList()
        {
            ProductViewModel viewModel = new ProductViewModel {
                Name         = "Test",
                NoOfUnit     = 12,
                ReOrderLevel = 1,
                UnitPrice    = 100,
            };

            _mediator.Setup(m => m.Send(It.IsAny <CreateProductCommand>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new CreateProductCommandResponse()
            {
                Id = 1
            });

            var result = await _factory.ExceuteSave(viewModel);

            Assert.That(result.GetType(), Is.EqualTo(typeof((ProductViewModel Model, List <string> Errors))));
        }
        public async Task <IActionResult> Create(ProductViewModel model)
        {
            if (ModelState.IsValid)
            {
                var modelResult = await _factory.ExceuteSave(model);

                model = modelResult.Model;

                if (modelResult.Errors.Count > 0)
                {
                    AddErrors(modelResult.Errors);
                }

                return(View(model));
            }
            return(View(model));
        }