public void CreateProperty(RentalProperty propertyToCreate) { propertyToCreate.ImageUrl1 = "../../Images/property4-1.JPG"; propertyToCreate.ImageUrl2 = "../../Images/property4-2.JPG"; Properties.Add(propertyToCreate); }
public ActionResult Create(RentalProperty propertyToCreate) { _service.CreateProperty(propertyToCreate); if (Request.IsAjaxRequest()) { return PartialView("PropertyPartial", propertyToCreate); } return RedirectToAction("List"); }
public void TestList_ShouldLoadAllPropertiesAndAssignToViewModel() { //Arrange var service = new FakePropertyService(); var controller = new RentController(service); var properties = new RentalProperty[0]; service.PropertiesToReturn = properties; //Act var result = (ViewResult)controller.List(); //Assert Assert.AreEqual(properties, result.ViewData.Model); }
public void TestCreate_ShouldSaveProperty() { //Arrange var service = new FakePropertyService(); var controller = new RentController(service); CreateControllerContextStubFor(controller); //Must setup ControllerContext, as method under test needs asscess to Controller.Resuest //Act var propertyToCreate = new RentalProperty(); controller.Create(propertyToCreate); //Assert Assert.AreEqual(propertyToCreate, service.LastCreatedProperty); }
public void TestCreate_ShouldReturnPropertyPartialView_ForAjaxRequest() { //Arrange var service = new FakePropertyService(); var controller = new RentController(service); CreateControllerContextStubFor(controller); controller.Request.Stub(r => r["X-Requested-With"]).Return("XMLHttpRequest"); //make it Ajax request //Act var propertyToCreate = new RentalProperty(); var result = (PartialViewResult)controller.Create(propertyToCreate); //Assert Assert.AreEqual("PropertyPartial", result.ViewName); }
public void TestCreate_ShouldRedirectToListView_ForNonAjaxRequest() { //Arrange var service = new FakePropertyService(); var controller = new RentController(service); CreateControllerContextStubFor(controller); controller.Request.Stub(r => r["X-Requested-With"]).Return(""); //make it Non-Ajax request //Act var propertyToCreate = new RentalProperty(); var result = controller.Create(propertyToCreate); //Assert //Assert.AreEqual("List", result.RouteValues["action"]); result.Assert(Redirect.To.Action("List")); //controller.Assert(HasError.On("Name").WithMessage("Error Message")); //result.Assert(Direct.To.DefaultView()); //result.Assert(Direct.To.View("SomeView")); //result.Assert(Redirect.To.Controller("SomeController").Action("SomeAction")); }
public void CreateProperty(RentalProperty propertyToCreate) { LastCreatedProperty = propertyToCreate; }