public ActionResult Create(CreateProductViewModel model)
        {
            if (!ModelState.IsValid)
                return View(model);

            var command = new CreateProduct(model.Name, model.Price);
            Bus.Send<CreateProduct>(command);

            return RedirectToAction("Index");
        }
Example #2
0
        public void CreateProduct()
        {
            var controller = _container.GetInstance<ProductController>();
            var model = new CreateProductViewModel()
            {
                Name = "Product 1",
                Price = 12.3m
            };

            var result = controller.Create(model) as RedirectToRouteResult;
            object view;
            result.RouteValues.TryGetValue("action", out view);
            Assert.AreEqual("Index", view);

            var viewResult = controller.Index() as ViewResult;

            var viewModel = viewResult.Model as ProductsView;
            Assert.AreEqual(1, viewModel.Products.Count);
        }
Example #3
0
        private Guid CreateProduct()
        {
            var controller = _container.GetInstance<ProductController>();
            var model = new CreateProductViewModel()
            {
                Name = "Product 1",
                Price = 12.3m
            };
            var result = controller.Create(model) as RedirectToRouteResult;
            var viewResult = controller.Index() as ViewResult;
            var viewModel = viewResult.Model as ProductsView;

            return viewModel.Products[0].Id;
        }