コード例 #1
0
        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);
        }
コード例 #2
0
        public void Get_CreateStepTwo_Returns_ViewResult()
        {
            // arrange
            Mock<IProjectServiceLayer> service = new Mock<IProjectServiceLayer>();
            Mock<IWebSecurityWrapper> security = new Mock<IWebSecurityWrapper>();
            Mock<INotificationSender> notice = new Mock<INotificationSender>();
            ProjectController controller = new ProjectController(service.Object, security.Object, notice.Object);

            // act
            var result = controller.CreateStepTwo(1, "a project", "abc123");

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.AreEqual("CreateStepTwo", ((ViewResult)result).ViewName);
        }
コード例 #3
0
        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"]);
        }
コード例 #4
0
        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"]);
        }
コード例 #5
0
        public void Post_CreateStepTwo_ValidProject_RedirectsTo_Details()
        {
            // arrange
            ProjectEditModel viewModel = new ProjectEditModel();
            viewModel.SelectedScope = new int[0];

            Mock<IProjectServiceLayer> service = new Mock<IProjectServiceLayer>();
            service.Setup(s => s.Create(It.IsAny<BCModel.Projects.Project>())).Returns(true);
            service.Setup(s => s.GetUserProfile(It.IsAny<int>())).Returns(new BCModel.UserProfile { CompanyId = 1, UserId = 1 });

            Mock<IWebSecurityWrapper> security = new Mock<IWebSecurityWrapper>();
            security.Setup(s => s.GetUserId(It.IsAny<string>())).Returns(1);
            Mock<INotificationSender> notice = new Mock<INotificationSender>();
            ProjectController controller = new ProjectController(service.Object, security.Object, notice.Object);

            Mock<IPrincipal> principal = new Mock<IPrincipal>();
            principal.Setup(p => p.Identity.Name).Returns("*****@*****.**");

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.SetupGet(c => c.HttpContext.User.Identity.Name).Returns("*****@*****.**");
            context.SetupGet(c => c.HttpContext.Request.IsAuthenticated).Returns(true);

            controller.ControllerContext = context.Object;

            // act
            var result = controller.CreateStepTwo(viewModel);

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            Assert.AreEqual("Details", ((RedirectToRouteResult)result).RouteValues["action"]);
        }
コード例 #6
0
        public void PostEditValidProjectRedirectsToDetails()
        {
            // arrange
            ProjectEditModel viewModel = new ProjectEditModel { Id = 1, PostalCode = "98008" };
            viewModel.SelectedScope = new int[0];
            Project aProject = new Project
            {
                Id = 1,
                ArchitectId = 1,
                Scopes = new List<ProjectXScope>(),
                BidPackages = new List<BidPackage>(),
                Title = "foo"
            };
            aProject.BidPackages.Add(new BidPackage { Id = 1, IsMaster = true, Project = aProject, ProjectId = aProject.Id, Scopes = new List<BidPackageXScope>(), CreatedById = 1 });

            Mock<IProjectServiceLayer> service = new Mock<IProjectServiceLayer>();
            service.Setup(s => s.Update(It.IsAny<BCModel.Projects.Project>())).Returns(true);
            service.Setup(s => s.GetUserProfile(It.IsAny<int>())).Returns(new BCModel.UserProfile { CompanyId = 1, UserId = 1 });
            service.Setup(s => s.Get(It.IsAny<int>())).Returns(aProject);

            Mock<IWebSecurityWrapper> security = new Mock<IWebSecurityWrapper>();
            security.Setup(s => s.GetUserId(It.IsAny<string>())).Returns(1);
            Mock<INotificationSender> notice = new Mock<INotificationSender>();
            ProjectController controller = new ProjectController(service.Object, security.Object, notice.Object);

            Mock<IPrincipal> principal = new Mock<IPrincipal>();
            principal.Setup(p => p.Identity.Name).Returns("*****@*****.**");

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.SetupGet(c => c.HttpContext.User.Identity.Name).Returns("*****@*****.**");
            context.SetupGet(c => c.HttpContext.Request.IsAuthenticated).Returns(true);

            controller.ControllerContext = context.Object;

            // act
            var result = controller.Edit(viewModel);

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            Assert.AreEqual("Details", ((RedirectToRouteResult)result).RouteValues["action"]);
        }
コード例 #7
0
        public void PostCreateStepTwoProjectValidationFailReturnsModelStateErrors()
        {
            // arrange
            ProjectEditModel viewModel = new ProjectEditModel();
            viewModel.SelectedScope = new int[0];

            Mock<IProjectServiceLayer> service = new Mock<IProjectServiceLayer>();
            service.Setup(s => s.Create(It.IsAny<BCModel.Projects.Project>())).Returns(false);
            service.Setup(s => s.GetUserProfile(It.IsAny<int>())).Returns(new BCModel.UserProfile { CompanyId = 1, UserId = 1 });
            service.SetupGet(s => s.ValidationDic).Returns(new Dictionary<string, string> { { "Duplicate", "Title already exists" } });

            Mock<IWebSecurityWrapper> security = new Mock<IWebSecurityWrapper>();
            security.Setup(s => s.GetUserId(It.IsAny<string>())).Returns(1);
            Mock<INotificationSender> notice = new Mock<INotificationSender>();
            ProjectController controller = new ProjectController(service.Object, security.Object, notice.Object);

            Mock<IPrincipal> principal = new Mock<IPrincipal>();
            principal.Setup(p => p.Identity.Name).Returns("*****@*****.**");

            Mock<ControllerContext> context = new Mock<ControllerContext>();
            context.SetupGet(c => c.HttpContext.User.Identity.Name).Returns("*****@*****.**");
            context.SetupGet(c => c.HttpContext.Request.IsAuthenticated).Returns(true);

            controller.ControllerContext = context.Object;

            // act
            var result = controller.CreateStepTwo(viewModel);

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.AreEqual("CreateStepTwo", ((ViewResult)result).ViewName);
            Assert.IsTrue(((ViewResult)result).ViewData.ModelState.ContainsKey("Duplicate"));
            Assert.AreEqual("Title already exists", ((ViewResult)result).ViewData.ModelState["Duplicate"].Errors[0].ErrorMessage.ToString());
        }
コード例 #8
0
        public void IndexReturnsViewResult()
        {
            // arrange
            Mock<IProjectServiceLayer> service = new Mock<IProjectServiceLayer>();
            Mock<IWebSecurityWrapper> security = new Mock<IWebSecurityWrapper>();
            Mock<INotificationSender> notice = new Mock<INotificationSender>();
            ProjectController controller = new ProjectController(service.Object, security.Object, notice.Object);

            // act
            var result = controller.Index();

            // assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.AreEqual("Index", ((ViewResult)result).ViewName);
        }