コード例 #1
0
        public void DepartmentController_Create_Get_Successfull()
        {
            //arrange
            var repositoryMock = new Mock<IDepartmentRepository>();

            DepartmentController objController = new DepartmentController(repositoryMock.Object);

            //act
            var result = objController.Create();

            //assert
            Assert.IsInstanceOfType(result, typeof(ViewResult));

            result = null;
        }
コード例 #2
0
        public void DepartmentController_Create_Post_NullDepartment()
        {
            //arrange
            var repositoryMock = new Mock<IDepartmentRepository>();
            Department department = null;

            repositoryMock.Setup(x => x.Store(department));
            DepartmentController objController = new DepartmentController(repositoryMock.Object);

            //act
            var result = objController.Create(department);

            //assert
            repositoryMock.Verify(x => x.Store(department), Times.Never());
            Assert.IsInstanceOfType(result, typeof(System.Web.Mvc.HttpNotFoundResult));

            result = null;
        }
コード例 #3
0
        public void DepartmentController_Create_Post_ModelStateInvalid()
        {
            //arrange
            var repositoryMock = new Mock<IDepartmentRepository>();
            var department = new Department { DepartmentId = 7, Name = "CleanUp", Description = "This place is a mess", Address = "4445 East Lansing Road", City = "Salt Lake City", State = "UT", PostalCode = "29854", IsActive = true, IsDeleted = false };

            repositoryMock.Setup(x => x.Store(department));
            DepartmentController objController = new DepartmentController(repositoryMock.Object);

            // you add this value on ModelState to force the error
            objController.ModelState.AddModelError("", "mock error message");

            //act
            var result = objController.Create(department);

            //assert
            repositoryMock.Verify(x => x.Store(department), Times.Never());
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.IsInstanceOfType(((ViewResult)result).Model, typeof(Department));

            result = null;
        }
コード例 #4
0
        public void DepartmentController_Create_Post_Successfull()
        {
            //arrange
            var repositoryMock = new Mock<IDepartmentRepository>();
            var department = new Department { DepartmentId = 7, Name = "CleanUp", Description = "This place is a mess", Address = "4445 East Lansing Road", City = "Salt Lake City", State = "UT", PostalCode = "29854", IsActive = true, IsDeleted = false };

            repositoryMock.Setup(x => x.Store(department));
            DepartmentController objController = new DepartmentController(repositoryMock.Object);

            //act
            var result = objController.Create(department);

            //assert
            repositoryMock.Verify(x => x.Store(department), Times.Once());
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));

            result = null;
        }