コード例 #1
0
        public void Login_Get_View_If_Guid_Is_NotNull()
        {
            var userManager = new UserManager<ApplicationUser>(new TestUserStore());
            //mocking QueryString
            var querystring = new NameValueCollection { { "guid", "got_value" } };
            var querystring1 = new NameValueCollection { { "reg", "value" } };
            Guid goalIdToken = Guid.NewGuid();
            // Guid 
            controllerContext.SetupGet(p => p.HttpContext.Request.QueryString).Returns(querystring);
            //controllerContext.SetupGet(p => p.HttpContext.Request.QueryString).Returns(querystring1);
            controllerContext.SetupGet(p => p.HttpContext.Session).Returns(httpSession.Object);
            AccountController controller = new AccountController(userService, userProfileService, goalService, updateService, commentService, followRequestService, followUserService, securityTokenService, userManager);
            controller.ControllerContext = controllerContext.Object;

            var httprequest = new HttpRequest("", "http://localhost/", "");
            var stringWriter = new StringWriter();
            var httpResponce = new HttpResponse(stringWriter);
            var httpContext = new HttpContext(httprequest, httpResponce);
            // Mocking HttpContext.Current
            var sessionContainer = new HttpSessionStateContainer("id",
                                    new SessionStateItemCollection(),
                                    new HttpStaticObjectsCollection(),
                                    10,
                                    true,
                                    HttpCookieMode.AutoDetect,
                                    SessionStateMode.InProc,
                                    false);

            httpContext.Items["AspSession"] = typeof(HttpSessionState).GetConstructor(
                        BindingFlags.NonPublic | BindingFlags.Instance,
                        null, CallingConventions.Standard,
                        new[] { typeof(HttpSessionStateContainer) },
                        null)
                        .Invoke(new object[] { sessionContainer });

            HttpContext.Current = httpContext;

            ViewResult rslt = controller.Login("abcd") as ViewResult;
            Assert.IsNotNull(rslt);
        }
コード例 #2
0
        public void LoginTest()
        {
            var userManager = new UserManager<ApplicationUser>(new TestUserStore());

            AccountController controller = new AccountController(userService, userProfileService, goalService, updateService, commentService, followRequestService, followUserService, securityTokenService, userManager);
            var mockAuthenticationManager = new Mock<IAuthenticationManager>();
            mockAuthenticationManager.Setup(am => am.SignOut());
            mockAuthenticationManager.Setup(am => am.SignIn());
            controller.AuthenticationManager = mockAuthenticationManager.Object;
            ApplicationUser user=new ApplicationUser()
            {
                UserName="******"
            };
            userManager.CreateAsync(user, "123456");
            var result = controller.Login(new LoginViewModel { Email = "adarsh", Password = "******", RememberMe = false }, "abcd").Result;
            Assert.IsNotNull(result);
            var addedUser = userManager.FindByName("adarsh");
            Assert.IsNotNull(addedUser);
            Assert.AreEqual("adarsh", addedUser.UserName);
        }
コード例 #3
0
        public void Login_Get_View_If_Guid_Is_Null()
        {
            var userManager = new UserManager<ApplicationUser>(new TestUserStore());
            Guid goalIdToken = Guid.NewGuid();
            controllerContext.SetupGet(p => p.HttpContext.Request.QueryString).Returns(new NameValueCollection());
            AccountController controller = new AccountController(userService, userProfileService, goalService, updateService, commentService, followRequestService, followUserService, securityTokenService, userManager);
            controller.ControllerContext = controllerContext.Object;
            ViewResult rslt = controller.Login("abcd") as ViewResult;
            Assert.IsNotNull(rslt);

        }