Esempio n. 1
0
        [InlineData(-1, false)] // Unsuccessful ChangeLockoutDate
        public void TestChangeLockoutDate(int userId, bool expectingSuccess)
        {
            var controllerContextMock = new Mock <ControllerContext>()
            {
                CallBase = true
            };
            var contextMock = new Mock <ApplicationDbContext>()
            {
                CallBase = true
            };

            contextMock.Setup(c => c.SaveChanges()).Returns(1);
            var controller = new ModeratorsController
            {
                ControllerContext = controllerContextMock.Object,
                Context           = contextMock.Object
            };

            var result = controller.ChangeLockoutDate(userId);

            if (expectingSuccess)
            {
                Assert.True(result is ViewResult);
            }
            else
            {
                Assert.True(result is HttpNotFoundResult);
            }
        }
Esempio n. 2
0
        [InlineData(-1, false)] // Unsuccessful DeleteGroupReport
        public void TestDeleteGroupReport(int groupReportId, bool expectingSuccess)
        {
            var controllerContextMock = new Mock <ControllerContext>()
            {
                CallBase = true
            };
            var contextMock = new Mock <ApplicationDbContext>()
            {
                CallBase = true
            };

            contextMock.Setup(c => c.SaveChanges()).Returns(1);
            var controller = new ModeratorsController
            {
                ControllerContext = controllerContextMock.Object,
                Context           = contextMock.Object
            };

            var result = controller.DeleteGroupReport(groupReportId);

            if (expectingSuccess)
            {
                Assert.True(result is RedirectToRouteResult);
            }
            else
            {
                Assert.True(result is HttpNotFoundResult);
            }
        }
Esempio n. 3
0
        [InlineData(-1, "1/01/2099 00:00:00", false)] // Unsuccessful PostLockoutDate (User does not exist)
        public void TestPostLockoutDate(int userId, string datetime, bool expectingSuccess)
        {
            var controllerContextMock = new Mock <ControllerContext>()
            {
                CallBase = true
            };
            var contextMock = new Mock <ApplicationDbContext>()
            {
                CallBase = true
            };

            contextMock.Setup(c => c.SaveChanges()).Returns(1);
            var controller = new ModeratorsController
            {
                ControllerContext = controllerContextMock.Object,
                Context           = contextMock.Object
            };

            var viewModel = new ModeratorLockoutViewModel()
            {
                LockoutDate = DateTime.Parse(datetime),
                UserId      = userId
            };

            var result = controller.PostLockoutDate(viewModel);

            if (expectingSuccess)
            {
                Assert.True(result is RedirectToRouteResult);
            }
            else
            {
                var valContext = new ValidationContext(viewModel, null, null);
                var valResults = new List <ValidationResult>();
                if (Validator.TryValidateObject(viewModel, valContext, valResults, true))
                {
                    Assert.True(result is HttpNotFoundResult);
                }
                else
                {
                    // This means that the passed model was not valid, meaning the system will not successfully save.
                    // However, ModelState object of the controller does not work properly in unit test cases.
                    // So, we deem this test a success, as if it had failed.
                    Assert.True(true);
                }
            }
        }