public void UsersControllerEditNewUserInitialTest()
        {
            // Arrange
            UsersController controller = new UsersController();
            
            // Act
            ViewResult result = controller.Edit(0) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("New", ((User)result.Model).EmailAddress);
            Assert.AreEqual(0, ((User)result.Model).UserId);
        }
        public void UsersControllerEditExistingUserInitialTest()
        {
            var db = new FakeDatabase();
            IAuth auth = new FakeFormAuthenticator();
////            var st = new FakeSkyTap();
            db.AddSet(TestUserData.Users);
////            db.AddSet(TestCourseData.Courses);
////            db.AddSet(TestClassroomData.Classrooms);
////            st.AddSet(TestTemplateRESTData.templates);
            var controller = new UsersController(db, auth);
////            controller.ControllerContext = new FakeControllerContext();
            ViewResult result = controller.Edit(1) as ViewResult;
            Assert.IsNotNull(result);
            Assert.AreEqual(typeof(User), result.Model.GetType());
            Assert.AreEqual("*****@*****.**", ((User)result.Model).EmailAddress);
        }
 public void UsersControllerEditNewUserPostbackValidPasswordTest()
 {
     var db = new FakeDatabase();
     IAuth auth = new FakeFormAuthenticator();
     ////var st = new FakeSkyTap();
     db.AddSet(TestUserData.Users);
     ////db.AddSet(TestCourseData.Courses);
     ////db.AddSet(TestClassroomData.Classrooms);
     ////st.AddSet(TestTemplateRESTData.templates);
     UsersController controller = new UsersController(db, auth);
     controller.ControllerContext = new FakeControllerContext();
     User testUser = new User() { UserId = 0, EmailAddress = "TestNew", NewPassword1 = "TestPassword", NewPassword2 = "TestPassword" };
     var result = controller.Edit(testUser);
     Assert.IsNotNull(result);
     Assert.AreEqual(typeof(RedirectToRouteResult), result.GetType());
     Assert.AreEqual(1, db.Added.Count);
     Assert.AreEqual("TestNew", ((User)db.Added[0]).EmailAddress);
     Assert.AreEqual(true, PasswordHash.ValidatePassword("TestPassword", ((User)db.Added[0]).Password));
     Assert.AreEqual(1, db.LogAdded.Count);
     Assert.AreEqual(2, db.saved);
 }
 public void UsersControllerEditNewUserPostbackInValidPasswordTest()
 {
     var db = new FakeDatabase();
     IAuth auth = new FakeFormAuthenticator();
     ////var st = new FakeSkyTap();
     db.AddSet(TestUserData.Users);
     ////db.AddSet(TestCourseData.Courses);
     ////db.AddSet(TestClassroomData.Classrooms);
     ////st.AddSet(TestTemplateRESTData.templates);
     UsersController controller = new UsersController(db, auth);
     controller.ControllerContext = new FakeControllerContext();
     User testUser = new User() { UserId = 0, EmailAddress = "TestNew", NewPassword1 = "TestPassword", NewPassword2 = "WrongPassword" };
     var result = controller.Edit(testUser);
     Assert.IsNotNull(result);
     Assert.AreNotEqual(typeof(RedirectToRouteResult), result.GetType());
     Assert.AreEqual("Edit", ((ViewResult)result).ViewName);
     Assert.AreEqual(0, db.Added.Count);
 }
 public void UsersControllerEditExistingUserPostbackUserInvalidPasswordChangeBadOldPasswordTest()
 {
     var db = new FakeDatabase();
     IAuth auth = new FakeFormAuthenticator();
     ////var st = new FakeSkyTap();
     db.AddSet(TestUserData.Users);
     ////st.AddSet(TestTemplateRESTData.templates);
     UsersController controller = new UsersController(db, auth);
     controller.ControllerContext = new FakeControllerContext();
     User testUser = new User() { UserId = 1, EmailAddress = "TestUpdate", OldPassword = "******", NewPassword1 = "NewPassword", NewPassword2 = "NewPassword" };
     var result = controller.Edit(testUser);
     Assert.IsNotNull(result);
     Assert.AreNotEqual(typeof(RedirectToRouteResult), result.GetType());
     Assert.AreEqual("Edit", ((ViewResult)result).ViewName);
     Assert.AreEqual(0, db.Added.Count);
 }
 public void UsersControllerEditExistingUserPostbackAdminsitratorNoPasswordChangeTest()
 {
     var db = new FakeDatabase();
     IAuth auth = new FakeFormAuthenticator();
     ////var st = new FakeSkyTap();
     db.AddSet(TestUserData.Users);
     ////st.AddSet(TestTemplateRESTData.templates);
     UsersController controller = new UsersController(db, auth);
     controller.ControllerContext = new FakeControllerContext();
     User testUser = new User() { UserId = 1, EmailAddress = "TestUpdate" };
     var result = controller.Edit(testUser);
     Assert.IsNotNull(result);
     Assert.AreEqual(typeof(RedirectToRouteResult), result.GetType());
     Assert.AreEqual(0, db.Added.Count);
     Assert.AreEqual(1, db.Updated.Count);
     Assert.AreEqual("TestUpdate", ((User)db.Updated[0]).EmailAddress);
     Assert.AreEqual(1, db.LogAdded.Count);
     Assert.AreEqual(2, db.saved);
 }