public void LogOutSuccessful() { Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(x => x.Request).Returns(moqRequest.Object); var controller = new HomeController(); var user = new LoginModels() { UserName = "******", Password = "******" }; var validationResults = TestModelHelper.ValidateModel(controller, user); controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); moqContext.SetupGet(x => x.Session["ID"]).Returns(39); moqContext.SetupGet(x => x.Session["Role"]).Returns(2); var redirectRoute = controller.Login(user) as RedirectToRouteResult; var redirectRouteResult = controller.Logout() as RedirectToRouteResult; Assert.AreEqual(0, validationResults.Count); Assert.AreEqual("Course", redirectRouteResult.RouteValues["action"]); Assert.AreEqual("Home", redirectRouteResult.RouteValues["controller"]); }
public void StudentLogin_WithAccountStatusIs2() { //Arrange Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpSessionStateBase> moqSession = new Mock <HttpSessionStateBase>(); moqContext.Setup(ctx => ctx.Session).Returns(moqSession.Object); moqContext.Setup(r => r.Request).Returns(moqRequest.Object); var controller = new UserController(); var studentAccount = new tutor { username = "******", password = "******", }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, studentAccount); var temp = (new { error = "No Access", message = "Tài khoản của bạn chưa được kích hoạt", status = 2 }); //Action var redirectRoute = controller.Login(studentAccount.username, studentAccount.password, null) as JsonResult; //Assert Assert.IsNotNull(redirectRoute.Data); Assert.AreEqual(temp.ToString(), redirectRoute.Data.ToString()); }
public void TestThatUserUnsuccessfullyLoginWithNoInputPassword() { Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(x => x.Request).Returns(moqRequest.Object); var controller = new HomeController(); var user = new LoginModels() { UserName = "******", Password = "" }; var validationResults = TestModelHelper.ValidateModel(controller, user); controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var viewResult = controller.Login(user) as ViewResult; //moqContext.SetupGet(x => x.Session["ID"]).Returns(1); //moqContext.SetupGet(x => x.Session["Role"]).Returns(1); Assert.IsFalse(viewResult.ViewData.ModelState.IsValid); Assert.AreEqual(1, validationResults.Count); Assert.IsTrue(validationResults[0].ErrorMessage.Equals("Hãy điền mật khẩu")); }
public void ParentLogin_WithAccountStatusIs3() { //Arrange Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpSessionStateBase> moqSession = new Mock <HttpSessionStateBase>(); moqContext.Setup(ctx => ctx.Session).Returns(moqSession.Object); moqContext.Setup(r => r.Request).Returns(moqRequest.Object); var controller = new UserController(); var parentAccount = new tutor { email = "*****@*****.**", password = "******", }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, parentAccount); var temp = (new { error = "Block", message = "Tài khoản của bạn đã bị khóa , vui lòng liên hệ ban quản trị hệ thống", status = 3 }); //Action var redirectRoute = controller.Login(parentAccount.email, parentAccount.password, null) as JsonResult; //Assert Assert.IsNotNull(redirectRoute.Data); Assert.AreEqual(temp.ToString(), redirectRoute.Data.ToString()); }
public void DetailModelTest() { Guid testId = new Guid(); DateTime testStartDate = new DateTime(2000, 1, 1, 12, 0, 0); DateTime testEndDate = new DateTime(2000, 1, 1, 12, 50, 0); var model = new DetailModel() { Id = testId, CheckIn = testStartDate, CheckOut = testEndDate, FeedbackMessage = "feedback", NoOfPages = 5, Rating = 5 }; var result = TestModelHelper.Validate(model); Assert.AreEqual(0, result.Count); Assert.AreEqual(testId, model.Id); Assert.AreEqual(testStartDate, model.CheckIn); Assert.AreEqual(testEndDate, model.CheckOut); Assert.AreEqual("feedback", model.FeedbackMessage); Assert.AreEqual(5, model.NoOfPages); Assert.AreEqual(5, model.Rating); }
public void ParentLogin_WithInvalidEmail() { //Arrange Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpSessionStateBase> moqSession = new Mock <HttpSessionStateBase>(); moqContext.Setup(ctx => ctx.Session).Returns(moqSession.Object); moqContext.Setup(r => r.Request).Returns(moqRequest.Object); var controller = new UserController(); var parentAccount = new tutor { email = "*****@*****.**", password = "******", }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, parentAccount); //Action var redirectRoute = controller.Login(parentAccount.email, parentAccount.password, null) as JsonResult; var temp = (new { error = "No Access", message = "username hoặc email không tồn tại", status = 0 }); //Assert Assert.IsNotNull(redirectRoute.Data); Assert.AreEqual(temp.ToString(), redirectRoute.Data.ToString()); }
public void CreateWorkSpace() { //Setup a fake HttpRequest Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(x => x.Request).Returns(moqRequest.Object); //arrange var controller = new GroupController(); var workspace = new WorkSpace() { WorkSpaceName = "WorkSpace TestCorrect", Bilimail = "*****@*****.**", Description = "Demo test is correct", ImageWS = "name.jpg" }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, workspace); //act var redirectRoute = controller.CreateGroup(workspace) as RedirectToRouteResult; //assert Assert.IsNotNull(redirectRoute); Assert.AreEqual("Index", redirectRoute.RouteValues["action"]); //Assert.AreEqual("Home", redirectRoute.RouteValues["controller"]); Assert.AreEqual(0, validationResults.Count); }
public void AddMemberWS(int id) { //Setup a fake HttpRequest Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(x => x.Request).Returns(moqRequest.Object); //arrange var controller = new HomeController(); var ws_user_roles = new WS_User_Roles() { WorkSpace_ID = 1, Role_Admin = true, User_ID = "", }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, ws_user_roles); //act var redirectRoute = controller.AddMemberWS(id) as RedirectToRouteResult; //assert Assert.IsNotNull(redirectRoute); Assert.AreEqual("ShowWorkSpace", redirectRoute.RouteValues["action"]); //Assert.AreEqual("Home", redirectRoute.RouteValues["controller"]); Assert.AreEqual(0, validationResults.Count); }
public void ValidateCreateBookModel_WithValidModel_ExpectValidNavigation() { //Setup a fake HttpRequest Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(x => x.Request).Returns(moqRequest.Object); //Arrange var controller = new CatalogController(); var book = new Book { Title = "The Cucumber Book", Author = "Matt Wynne and Aslak Hellesoy", Price = Convert.ToDecimal(18.00) }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, book); //Act var redirectRoute = controller.Create(book) as RedirectToRouteResult; //Assert Assert.IsNotNull(redirectRoute); Assert.AreEqual("Index", redirectRoute.RouteValues["action"]); Assert.AreEqual("Catalog", redirectRoute.RouteValues["controller"]); Assert.AreEqual(0, validationResults.Count); }
public void ValidateParentRegisterAccount_WithValidModel_ExpectValidNavigation() { Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(r => r.Request).Returns(moqRequest.Object); // Arrange var controller = new UserController(); var parent = new parent { fullname = "Trần Phú Hòa", username = "******", phone = "090 123 7654", email = "*****@*****.**", password = "******" }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, parent); // Act var redirectRoute = controller.RegisterParent(parent) as RedirectToRouteResult; //Assert Assert.IsNotNull(redirectRoute); Assert.AreEqual("ConfirmEmail", redirectRoute.RouteValues["action"]); Assert.AreEqual("User", redirectRoute.RouteValues["controller"]); Assert.AreEqual(0, validationResults.Count); }
public void ValidateAdminUnsuccessfullyResetPasswordUserWithNonInput() { Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(x => x.Request).Returns(moqRequest.Object); var controller = new AdminController(); var user = new TaiKhoan().ID.ToString(); var matkhau = new ResetPasswordModel() { matkhau = "", nhaplaimatkhau = "" }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, matkhau); //Act var viewResult = controller.ResetPassword(user) as ViewResult; Assert.IsFalse(viewResult.ViewData.ModelState.IsValid); Assert.AreEqual(2, validationResults.Count); Assert.IsFalse(validationResults[0].ErrorMessage.Equals("'Mời nhập mật khẩu, mời nhập lại mật khẩu.")); }
public void ValidateAdminUnsuccessfullyResetPasswordUserWithIncorrectPasswordFormat() { Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(x => x.Request).Returns(moqRequest.Object); var controller = new AdminController(); var id = new TaiKhoan().ID.ToString(); var matkhaumoi = new ResetPasswordModel { matkhau = "123", nhaplaimatkhau = "123" }; var validationResults = TestModelHelper.ValidateModel(controller, matkhaumoi); controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var viewResult = controller.ResetPassword(id) as ViewResult; //Act //var viewResult = controller.ResetPassword(user) as ViewResult; Assert.IsFalse(viewResult.ViewData.ModelState.IsValid); Assert.AreEqual(1, validationResults.Count); Assert.IsFalse(validationResults[0].ErrorMessage.Equals("Mật khẩu: phải có ít nhất 6 kí tự.")); }
public void ParentLogin_WithAccountStatusIs2() { //Arrange Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpSessionStateBase> moqSession = new Mock <HttpSessionStateBase>(); moqContext.Setup(ctx => ctx.Session).Returns(moqSession.Object); moqContext.Setup(r => r.Request).Returns(moqRequest.Object); var controller = new UserController(); var parentAccount = new tutor { email = "*****@*****.**", password = "******", }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, parentAccount); //Action var redirectRoute = controller.Login(parentAccount.email, parentAccount.password, null) as ViewResult; //Assert Assert.IsNotNull(redirectRoute); Assert.AreEqual("Tài khoản của bạn chưa được kích hoạt", redirectRoute.ViewBag.msg); Assert.AreEqual("Login", redirectRoute.ViewName); }
public void TutorLogin_WithInvalidUserName() { //Arrange Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpSessionStateBase> moqSession = new Mock <HttpSessionStateBase>(); moqContext.Setup(ctx => ctx.Session).Returns(moqSession.Object); moqContext.Setup(r => r.Request).Returns(moqRequest.Object); var controller = new UserController(); var tutorAccount = new tutor { email = "*****@*****.**", password = "******", }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, tutorAccount); //Action var redirectRoute = controller.Login(tutorAccount.email, tutorAccount.password, null) as ViewResult; //Assert Assert.IsNotNull(redirectRoute); Assert.AreEqual("username hoặc email không tồn tại", redirectRoute.ViewBag.msg); Assert.AreEqual("Login", redirectRoute.ViewName); }
public void ParentLogin_WithValidEmailAndInvanlidPassword() { //Arrange Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpSessionStateBase> moqSession = new Mock <HttpSessionStateBase>(); moqContext.Setup(ctx => ctx.Session).Returns(moqSession.Object); moqContext.Setup(r => r.Request).Returns(moqRequest.Object); var controller = new UserController(); var parentAccount = new tutor { email = "*****@*****.**", password = "******", }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, parentAccount); //Action var redirectRoute = controller.Login(parentAccount.email, parentAccount.password, null) as ViewResult; //Assert Assert.IsNotNull(redirectRoute); Assert.AreEqual("Mật khẩu sai rồi !", redirectRoute.ViewBag.msg); Assert.AreEqual("Login", redirectRoute.ViewName); }
public void StudentLogin_WithAccountStatusIs3() { //Arrange Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpSessionStateBase> moqSession = new Mock <HttpSessionStateBase>(); moqContext.Setup(ctx => ctx.Session).Returns(moqSession.Object); moqContext.Setup(r => r.Request).Returns(moqRequest.Object); var controller = new UserController(); var studentAccount = new tutor { username = "******", password = "******", }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, studentAccount); //Action var redirectRoute = controller.Login(studentAccount.username, studentAccount.password, null) as ViewResult; //Assert Assert.IsNotNull(redirectRoute); Assert.AreEqual("Tài khoản của bạn đã bị khóa , vui lòng liên hệ ban quản trị hệ thống", redirectRoute.ViewBag.msg1); Assert.AreEqual("Login", redirectRoute.ViewName); }
public void TutorLogin_WithValidInput() { //Arrange Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpSessionStateBase> moqSession = new Mock <HttpSessionStateBase>(); moqContext.Setup(ctx => ctx.Session).Returns(moqSession.Object); moqContext.Setup(r => r.Request).Returns(moqRequest.Object); var controller = new UserController(); var tutorAccount = new tutor { email = "*****@*****.**", password = "******", }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, tutorAccount); //Action var redirectRoute = controller.Login(tutorAccount.email, tutorAccount.password, null) as RedirectToRouteResult; //Assert Assert.IsNotNull(redirectRoute); Assert.AreEqual("InfoOfTutor", redirectRoute.RouteValues["action"]); Assert.AreEqual("Tutor", redirectRoute.RouteValues["controller"]); }
public void TutorLogin_WithValidUsernameAndInvalidPassword() { //Arrange Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpSessionStateBase> moqSession = new Mock <HttpSessionStateBase>(); moqContext.Setup(ctx => ctx.Session).Returns(moqSession.Object); moqContext.Setup(r => r.Request).Returns(moqRequest.Object); var controller = new UserController(); var tutorAccount = new tutor { email = "*****@*****.**", password = "******", }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, tutorAccount); //Action var redirectRoute = controller.Login(tutorAccount.email, tutorAccount.password, null) as JsonResult; var temp = (new { error = "No Access", message = "Mật khẩu sai rồi !", status = 0 }); //Assert Assert.IsNotNull(redirectRoute.Data); Assert.AreEqual(temp.ToString(), redirectRoute.Data.ToString()); }
public void ValidateAdminUnsuccessfullyResetPasswordUserWithIncorrectConfirmPassword() { Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(x => x.Request).Returns(moqRequest.Object); var controller = new AdminController(); var user = new TaiKhoan().ID.ToString(); var matkhau = new ResetPasswordModel() { matkhau = "12345678", nhaplaimatkhau = "123456789" }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, matkhau); //Act var viewResult = controller.ResetPassword(user) as ViewResult; Assert.IsTrue(viewResult.ViewData.ModelState.IsValid); Assert.AreEqual(1, validationResults.Count); Assert.IsTrue(validationResults[0].ErrorMessage.Equals("Mật khẩu không khớp.")); }
public void ValidateCreateBookModel_WithTitleExceeds100Characters_ExpectValidationError() { //Setup a fake HttpRequest Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(x => x.Request).Returns(moqRequest.Object); //Arrange var controller = new CatalogController(); var book = new Book { Title = new string('*', 101), Author = "David Chelimsky", Price = Convert.ToDecimal(17.50) }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, book); //Act var viewResult = controller.Create(book) as ViewResult; //Assert Assert.IsNotNull(viewResult); Assert.IsFalse(viewResult.ViewData.ModelState.IsValid); Assert.AreEqual(1, validationResults.Count); Assert.IsTrue(validationResults[0].ErrorMessage.Equals("The field Title must be a string with a maximum length of 100.")); }
public void ValidateRegisterAccountModel_WithValidModel() { //Arrange using (ppcrental3119Entities db = new ppcrental3119Entities()) { var controller = new UserController(); Random random = new Random(); string address = string.Format("qa{0:0000}@test.com", random.Next(10000)); string password = "******"; USERMetadata user = new USERMetadata { Email = address, Password = password, ConfirmPassword = password, FullName = "Nguyen Van A", Phone = "0903771612", Address = "Tp. HCM", SecretQuestion_ID = 1, Answer = "AbcXyz", }; var validationResults = TestModelHelper.ValidateModel(controller, user); //Act //var redirectRoute = controller.Register(user) as RedirectToRouteResult; ////Assert //Assert.IsNotNull(redirectRoute); //Assert.AreEqual("Index", redirectRoute.RouteValues["action"]); //Assert.AreEqual("Catalog", redirectRoute.RouteValues["controller"]); var result = controller.Register(user) as ViewResult; Assert.AreEqual(0, validationResults.Count); Assert.AreEqual("Successful Register", result.ViewBag.SuccessMessage); } }
public void ValidateCreateBookModel_WithTitleContainsSpaceOnly_ExpectValidationError() { //Setup a fake HttpRequest Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(x => x.Request).Returns(moqRequest.Object); //Arrange var controller = new CatalogController(); var book = new Book { Title = " ", Author = "David Chelimsky", Price = Convert.ToDecimal(17.50) }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, book); //Act var viewResult = controller.Create(book) as ViewResult; //Assert Assert.IsNotNull(viewResult); //Assert.AreEqual(string.Empty, viewResult.ViewName); Assert.IsFalse(viewResult.ViewData.ModelState.IsValid); Assert.AreEqual(1, validationResults.Count); Assert.IsTrue(validationResults[0].ErrorMessage.Equals("The Title field is required.")); }
public void ValidateRegisterAccountModel_InvalidPassword() { //Arrange using (ppcrental3119Entities db = new ppcrental3119Entities()) { var controller = new UserController(); Random random = new Random(); string address = string.Format("qa{0:0000}@test.com", random.Next(10000)); string password = "******"; USERMetadata user = new USERMetadata { Email = address, Password = password, ConfirmPassword = password, FullName = "Nguyen Van A", Phone = "0903771612", Address = "Tp. HCM", SecretQuestion_ID = 1, Answer = "AbcXyz", }; var validationResults = TestModelHelper.ValidateModel(controller, user); //Act //var redirectRoute = controller.Register(user) as RedirectToRouteResult; ////Assert var result = controller.Register(user) as ViewResult; Assert.AreEqual(1, validationResults.Count); Assert.AreEqual("Minimum four characters and maximun twenty characters, at least one uppercase letter, one lowercase letter and one number.", validationResults[0].ErrorMessage); } }
public void DeleteWorkSpace(WorkSpace ws) { //Setup a fake HttpRequest Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(x => x.Request).Returns(moqRequest.Object); //arrange var controller = new HomeController(); PMSEntities db = new PMSEntities(); ws.ID = 1; var work_id = ws.ID; WorkSpace workspace = db.WorkSpaces.Find(work_id); db.WorkSpaces.Remove(workspace); controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, workspace); //act var redirectRoute = controller.Index() as RedirectToRouteResult; //assert Assert.IsNotNull(redirectRoute); Assert.AreEqual("Index", redirectRoute.RouteValues["action"]); //Assert.AreEqual("Home", redirectRoute.RouteValues["controller"]); Assert.AreEqual(0, validationResults.Count); }
public void TestThatUserUnsuccessfullyLoginBecauseDontHaveAccount() { Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(x => x.Request).Returns(moqRequest.Object); var controller = new HomeController(); var user = new LoginModels() { UserName = "******", Password = "******" }; var validationResults = TestModelHelper.ValidateModel(controller, user); controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var viewResult = controller.Login(user) as ViewResult; //moqContext.SetupGet(x => x.Session["ID"]).Returns(1); //moqContext.SetupGet(x => x.Session["Role"]).Returns(1); var result = controller.Login("t1555501", "123456789"); Assert.IsFalse(viewResult.ViewData.ModelState.IsValid); Assert.AreEqual(0, validationResults.Count); Assert.AreEqual(0, result); }
public void CreateWorkSpace_WithWorkSpaceNameIsNull_ExpectValidationError() { Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpPostedFileBase> moqPostedFile = new Mock <HttpPostedFileBase>(); moqRequest.Setup(r => r.Files.Count).Returns(0); moqContext.Setup(x => x.Request).Returns(moqRequest.Object); //arrange var controller = new HomeController(); var workspace = new WorkSpace() { WorkSpaceName = "", Bilimail = "*****@*****.**", Description = "Demo test is correct", ImageWS = "name.jpg" }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, workspace); //act var viewResult = controller.CreateWorkSpace(workspace) as ViewResult; //Assert Assert.IsNull(viewResult); Assert.IsTrue(viewResult.ViewData.ModelState.IsValid); Assert.AreEqual(1, validationResults.Count); Assert.IsTrue(validationResults[0].ErrorMessage.Equals("The WorkSpaceName field is required.")); }
public void ParentLogin_WithValidInput() { //Arrange Mock <HttpContextBase> moqContext = new Mock <HttpContextBase>(); Mock <HttpRequestBase> moqRequest = new Mock <HttpRequestBase>(); Mock <HttpSessionStateBase> moqSession = new Mock <HttpSessionStateBase>(); moqContext.Setup(ctx => ctx.Session).Returns(moqSession.Object); moqContext.Setup(r => r.Request).Returns(moqRequest.Object); var controller = new UserController(); var parentAccount = new tutor { email = "*****@*****.**", password = "******", }; controller.ControllerContext = new ControllerContext(moqContext.Object, new RouteData(), controller); var validationResults = TestModelHelper.ValidateModel(controller, parentAccount); //Action var redirectRoute = controller.Login(parentAccount.email, parentAccount.password, null) as JsonResult; //Assert Assert.IsNotNull(redirectRoute.Data); }
public void EmployeePayslipTestInvalidPersonModel() { PersonModel personModel = new PersonModel(); var results = TestModelHelper.Validate(personModel); Assert.AreEqual(results[0].ErrorMessage, "First Name is required"); Assert.AreEqual(results[1].ErrorMessage, "Last Name is required"); }
public void EmployeePayslipTestInvalidEmployeeModel() { EmployeeModel employeeModel = new EmployeeModel(); var results = TestModelHelper.Validate(employeeModel); Assert.AreEqual(results[0].ErrorMessage, "Annual Salary is required"); Assert.AreEqual(results[1].ErrorMessage, "Super Rate is required"); Assert.AreEqual(results[2].ErrorMessage, "Payment Start Date is required"); }
public void Validate_Model_Playlist_ExpectNoValidationErrors() { var model = new PlaylistsModel() { P_name = "EZY" }; var results = TestModelHelper.Validate(model); Assert.AreEqual(0, results.Count); }