コード例 #1
0
        public void CreateProperty(RentalProperty propertyToCreate)
        {
            propertyToCreate.ImageUrl1 = "../../Images/property4-1.JPG";
            propertyToCreate.ImageUrl2 = "../../Images/property4-2.JPG";

            Properties.Add(propertyToCreate);
        }
コード例 #2
0
ファイル: RentController.cs プロジェクト: changhongfu/TDDKata
 public ActionResult Create(RentalProperty propertyToCreate)
 {
     _service.CreateProperty(propertyToCreate);
     if (Request.IsAjaxRequest())
     {
         return PartialView("PropertyPartial", propertyToCreate);
     }
     return RedirectToAction("List");
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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"));
        }
コード例 #7
0
 public void CreateProperty(RentalProperty propertyToCreate)
 {
     LastCreatedProperty = propertyToCreate;
 }