コード例 #1
0
        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");
        }
コード例 #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);
        }
コード例 #3
0
ファイル: CartUnitTests.cs プロジェクト: petarkorudzhiev/d3es
        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;
        }