public void RegisterTest2() { // Setup var formsAuthenticationMock = new Mock<IFormsAuthentication>(); var membershipProviderMock = new Mock<MembershipProvider>(); AccountController target = new AccountController(formsAuthenticationMock.Object, membershipProviderMock.Object); target.SetFakeControllerContext(); target.HttpContext.Request.SetHttpMethodResult("POST"); // Execute string username = ""; string email = "*****@*****.**"; string password = "******"; string confirmPassword = "******"; ViewResult result = target.Register(username, email, password, confirmPassword) as ViewResult; // Verify ViewDataDictionary viewData = result.ViewData; Assert.AreEqual("Register", viewData["Title"]); Assert.IsFalse(viewData.ModelState.IsValid); Assert.AreEqual(1, viewData.ModelState.Count); }
public void RegisterTest3() { // Setup var formsAuthenticationMock = new Mock<IFormsAuthentication>(); var membershipProviderMock = new Mock<MembershipProvider>(); MembershipCreateStatus status = MembershipCreateStatus.Success; membershipProviderMock .Expect(m => m.CreateUser(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), true, It.IsAny<object>(), out status)) .Returns(new MembershipUser("AspNetSqlMembershipProvider", "", null, "", "", "", true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.MinValue)); AccountController target = new AccountController(formsAuthenticationMock.Object, membershipProviderMock.Object); target.SetFakeControllerContext(); target.HttpContext.Request.SetHttpMethodResult("POST"); // Execute string username = "******"; string email = "*****@*****.**"; string password = "******"; string confirmPassword = "******"; RedirectToRouteResult result = target.Register(username, email, password, confirmPassword) as RedirectToRouteResult; }
public void RegisterTest1() { // Setup var formsAuthenticationMock = new Mock<IFormsAuthentication>(); var membershipProviderMock = new Mock<MembershipProvider>(); AccountController target = new AccountController(formsAuthenticationMock.Object, membershipProviderMock.Object); target.SetFakeControllerContext(); // Execute ViewResult result = target.Register(null, null, null, null) as ViewResult; // Verify ViewDataDictionary viewData = result.ViewData; Assert.AreEqual("Register", viewData["Title"]); Assert.AreEqual(2, viewData.Count); }