public void Get_Create_AsArchitect_Returns_CreateStepTwo_ViewResult() { // arrange UserProfile theUser = new UserProfile { UserId = 1, CompanyId = 1 }; Mock<IProjectServiceLayer> service = new Mock<IProjectServiceLayer>(); service.Setup(s => s.GetUserProfile(1)).Returns(theUser); Mock<IWebSecurityWrapper> security = new Mock<IWebSecurityWrapper>(); security.Setup(s => s.GetUserId("*****@*****.**")).Returns(1); Mock<INotificationSender> notice = new Mock<INotificationSender>(); ProjectController controller = new ProjectController(service.Object, security.Object, notice.Object); Mock<ControllerContext> context = new Mock<ControllerContext>(); context.Setup(c => c.HttpContext.User.IsInRole("architect")).Returns(true); context.Setup(p => p.HttpContext.User.Identity.Name).Returns("*****@*****.**"); controller.ControllerContext = context.Object; // act var result = controller.Create(); //assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(ViewResult)); Assert.AreEqual("CreateStepTwo", ((ViewResult)result).ViewName); }
public void Post_Create_UniqueProject_Redirects_CreateStepTwo() { // arrange DupeCheckViewModel viewModel = new DupeCheckViewModel { ArchitectId = 3, Number = "abc123 hello hello", Title = "build a house for cake" }; Mock<IProjectServiceLayer> service = new Mock<IProjectServiceLayer>(); service.Setup(s => s.FindDuplicate(viewModel.Title, viewModel.Number, viewModel.ArchitectId.Value)).Returns(new List<Project>()); // return empty list. no matches found Mock<INotificationSender> notice = new Mock<INotificationSender>(); Mock<IWebSecurityWrapper> security = new Mock<IWebSecurityWrapper>(); ProjectController controller = new ProjectController(service.Object, security.Object, notice.Object); // act var result = controller.Create(viewModel); // assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); Assert.AreEqual("CreateStepTwo", ((RedirectToRouteResult)result).RouteValues["action"]); Assert.AreEqual("Project", ((RedirectToRouteResult)result).RouteValues["controller"]); }
public void Post_Create_NewArchitect_RedirectsTo_CreateArchitect() { // arrange DupeCheckViewModel viewModel = new DupeCheckViewModel { Architect = "u build it, we draw it", Number = "abc123 hello hello", Title = "build a house for cake" }; Mock<IProjectServiceLayer> service = new Mock<IProjectServiceLayer>(); Mock<INotificationSender> notice = new Mock<INotificationSender>(); Mock<IWebSecurityWrapper> security = new Mock<IWebSecurityWrapper>(); ProjectController controller = new ProjectController(service.Object, security.Object, notice.Object); // act var result = controller.Create(viewModel); // assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); Assert.AreEqual("CreateArchitect", ((RedirectToRouteResult)result).RouteValues["action"]); Assert.AreEqual("Company", ((RedirectToRouteResult)result).RouteValues["controller"]); }