コード例 #1
0
 public void Cannot_Login_With_Empty_UserCrdential()
 {
     //Arrange
        LogOnFormModel logon = new LogOnFormModel();
        logon.UserName = string.Empty;
        logon.Password = string.Empty;
        AccountController controller = new AccountController(commandBus.Object, userRepository.Object, formsAuthentication.Object);
        // The MVC pipeline doesn't run, so binding and validation don't run.
        controller.ModelState.AddModelError("", "UserName and Password Should Provide");
        //Act
        var result = controller.Login(logon, "http://localhost:50521") as ViewResult;
        //Assert
        Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        Assert.AreEqual("Login", result.ViewName);
 }
コード例 #2
0
        public void Login_Success_Redirects_To_Home()
        {
            //Arrange
               var routes = new RouteCollection();
               MvcApplication.RegisterRoutes(routes);
               var returnUrl = new Uri("http://efmvc.codeplex.com");

               Mock<HttpRequestBase> request = new Mock<HttpRequestBase>();
               Mock<HttpResponseBase> response = new Mock<HttpResponseBase>();
               Mock<HttpContextBase> context = new Mock<HttpContextBase>();

               context.SetupGet(x => x.Request).Returns(request.Object);
               context.SetupGet(x => x.Response).Returns(response.Object);
               request.Setup(x => x.Url).Returns(new Uri("http://*****:*****@gmail.com",
               UserId = 1,
               FirstName = "Shiju",
               LastName = "Var",
               DateCreated = DateTime.Now,
               Password = "******",
               RoleId = 2
               };
               userRepository.Setup(x => x.Get(It.IsAny<Expression<Func<User, bool>>>())).Returns(user);
               LogOnFormModel logon = new LogOnFormModel();
               logon.UserName = user.Email;
               logon.Password = "******";
               AccountController controller = new AccountController(commandBus.Object, userRepository.Object, formsAuthentication.Object);
               //Act
               controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);
               controller.Url = new UrlHelper(new RequestContext(context.Object, new RouteData()), routes);
               var actual = controller.Login(logon, returnUrl.AbsoluteUri);
               //Assert
               Assert.IsInstanceOfType(typeof(RedirectToRouteResult), actual ,"Wrong Type");
               var result = (RedirectToRouteResult)actual;
               Assert.AreEqual("Home", result.RouteValues["controller"]);
               Assert.AreEqual("Index", result.RouteValues["action"]);
        }
コード例 #3
0
 public void Cannot_Login_With_Wrong_UserCrdential()
 {
     //Arrange
        userRepository.Setup(x => x.Get(It.IsAny<Expression<Func<User, bool>>>())).Returns((User)null);
        LogOnFormModel logon = new LogOnFormModel();
        logon.UserName = "******";
        logon.Password = "******";
        AccountController controller = new AccountController(commandBus.Object, userRepository.Object, formsAuthentication.Object);
        //Act
        var result = controller.Login(logon, "http://localhost:50521") as ViewResult;
        //Assert
        Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
        Assert.AreEqual("Login", result.ViewName);
 }