Beispiel #1
0
        public void Cannot_Edit_Nonexistent_Task()
        {
            Mock<ITaskRepository> mock = new Mock<ITaskRepository>();
            UserProfile testUser = new UserProfile { UserId = 1, UserName = "******" };
            var contextMock = new Mock<ControllerContext>();

            mock.Setup(m => m.GetTaskByID(It.IsAny<int>())).Returns((Task) null);

            contextMock.SetupGet(p => p.HttpContext.User.Identity.Name).Returns("brad-greene");
            contextMock.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);

            TaskController target = new TaskController(mock.Object);
            target.ControllerContext = contextMock.Object;

            ActionResult T1 = target.Edit(2); //for some reason this wont work in the unit test, it comes out as null...

            //Assert
            Assert.IsInstanceOfType(T1, typeof(HttpNotFoundResult));
        }
Beispiel #2
0
        public void Can_Save_Changes()
        {
            Mock<ITaskRepository> mock = new Mock<ITaskRepository>();
            UserProfile testUser = new UserProfile { UserId = 1, UserName = "******" };
            var contextMock = new Mock<ControllerContext>();
            contextMock.SetupGet(p => p.HttpContext.User.Identity.Name).Returns("brad-greene");
            contextMock.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);
            TaskController target = new TaskController(mock.Object);
            target.ControllerContext = contextMock.Object;

            Task t = new Task { Category = "misc" };
            ActionResult result = target.Edit(t);

            mock.Verify(m => m.UpdateTask(t));
        }
Beispiel #3
0
        public void Can_Edit_Task()
        {
            Mock<ITaskRepository> mock = new Mock<ITaskRepository>();
            UserProfile testUser = new UserProfile { UserId = 1, UserName = "******" };
            var contextMock = new Mock<ControllerContext>();

            mock.Setup(m => m.GetTaskByID(It.IsAny<int>())).Returns(new Task {ID = 1, Description = "T1", UserProfile = testUser, UserID = 1 });

            contextMock.SetupGet(p => p.HttpContext.User.Identity.Name).Returns("brad-greene");
            contextMock.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);

            TaskController target = new TaskController(mock.Object);
            target.ControllerContext = contextMock.Object;

            Task T1 = ((ViewResult)target.Edit(1)).ViewData.Model as Task; //for some reason this wont work in the unit test, it comes out as null...

            //Assert
            Assert.AreEqual(1, T1.ID);
        }