예제 #1
0
        public async Task HTTP_GET_RedirectedTo_Login()
        {
            var browser = new TestServerBrowser(_testServer);

            var frontPageResponse = await browser.Get("/");

            Assert.AreEqual(frontPageResponse.StatusCode, HttpStatusCode.Found);
            Assert.IsTrue(frontPageResponse.Headers.Location.ToString().Contains("/Account/Login?ReturnUrl=%2F"));
        }
예제 #2
0
        public async Task HTTP_GET_Admin()
        {
            var browser      = new TestServerBrowser(_testServer);
            var expectedName = "rr1980";
            var credentials  = new Dictionary <string, string>
            {
                { "username", expectedName },
                { "password", "12003" },
                { "ReturnUrl", "/" }
            };

            var signInResponse = await browser.Post("/Account/Login", credentials);

            await browser.FollowRedirect(signInResponse);

            var frontPageResponse = await browser.Get("/Admin");

            Assert.AreEqual(HttpStatusCode.OK, frontPageResponse.StatusCode);
            Assert.AreEqual(frontPageResponse.RequestMessage.RequestUri.AbsolutePath, "/Admin");

            var user = _httpContexts.Last().User;

            Assert.IsNotNull(user);

            var roles = user.Claims.Where(c => c.Type == ClaimTypes.Role);

            Assert.IsTrue(roles.Count() == 2);

            var role_adnin = roles.FirstOrDefault(r => r.Value == UserRoleType.Admin.ToString());

            Assert.IsNotNull(role_adnin);

            var role_default = roles.FirstOrDefault(r => r.Value == UserRoleType.Default.ToString());

            Assert.IsNotNull(role_default);
        }