public ProductQueryCreateViewModel CreateWithExistingModel(ProductQueryCreateViewModel model) { //Note this should come from a look up data service with iso id var countries = new Dictionary<int, string>(); countries.Add(1, "UK"); countries.Add(2, "United States"); countries.Add(3, "Ireland"); var products = new ProductService().GetProducts(); model.Products = new SelectList((IEnumerable) products, "Id", "Name"); model.Countries = new SelectList(countries, "key", "value"); return model; }
public ActionResult Create(ProductQueryCreateViewModel model) { if (!ModelState.IsValid) { model = _productQueryCreateViewModelFactory.CreateWithExistingModel(model); return View(model); } //call service - would wrap this in seperate testable class if more time var customer = new Customer() {AddressLine1 = model.AddressLine1, City = model.City, CountryId = model.SelectedCountryId, DateCreated = DateTime.Now,EmailAddress = model.EmailAddress,FirstName = model.FirstName, LastName = model.LastName,Postcode = model.Postcode}; var query= new AddCustomerQueryRequest () {Customer = customer, ProductIds = model.SelectedProductIds.ToList()}; new ProductService().CreateProductQuery(query); return RedirectToAction("CreateConfirm"); }
public void CreateWhenCalledReturnsCreateView() { // Arrange var mockVMFactory =new Mock<IProductQueryCreateViewModelFactory>(); var model = new ProductQueryCreateViewModel(); var countries = new Dictionary<int, string>(); countries.Add(1, "UK"); model.Countries = new SelectList(countries, "key", "value"); var products = new Dictionary<int, string>(); products.Add(1, "Some Product"); model.Products = new SelectList(countries, "key", "value"); mockVMFactory.Setup(ms => ms.Create()).Returns(model); ProductQueryController controller = new ProductQueryController(mockVMFactory.Object); // Act ViewResult result = controller.Create() as ViewResult; // Assert Assert.AreEqual("Create",result.ViewName); }
public ProductQueryCreateViewModel Create() { var model = new ProductQueryCreateViewModel(); return CreateWithExistingModel(model); }