Esempio n. 1
0
 public ActionResult Create(ProjectModel projectModel)
 {
     if(ModelState.IsValid)
     {
         var project = projectModel.ConvertToProject();
         var response = projectService.CreateProject(project);
         if (response.HasSucceeded)
         {
             return RedirectToAction("Index");
         }
     }
     return View(projectModel);
 }
        public void CanCreateProject()
        {
            var projectService = new Mock<IProjectProvider>();
            var project = new Project { Id = 4, Description = "lll", Title = "sdf",Velocity = 3};
            var projectModel = new ProjectModel { Id = project.Id, Description = project.Description, Title = project.Title, Velocity = project.Velocity };

            projectService.Setup(e => e.CreateProject(It.Is<Project>(j=> j.Id == project.Id))).Returns(new OperationResponse(true));
            var controller = new ProjectsController(projectService.Object);

            var actionResult = controller.Create(projectModel);
            var viewresult = actionResult as RedirectToRouteResult;
            Assert.IsNotNull(viewresult);
            Assert.AreEqual("Index", viewresult.RouteValues.Single().Value);
            projectService.Verify();
        }