Exemplo n.º 1
0
        public void ShouldAuthoriseIfNotAuthenticated()
        {
            // arrange
            AuthoriseAttribute attr = new AuthoriseAttribute { RedirectTo = "/here", DoAuthorise = true };

            // act
            attr.OnAuthorization(m_context);

            // assert
            Assert.IsTrue(m_context.Result is HttpUnauthorizedResult);
        }
Exemplo n.º 2
0
        public void ShouldRedirectIfNotAuthenticated()
        {
            // arrange
            AuthoriseAttribute attr = new AuthoriseAttribute { RedirectTo = "/here" };

            // act
            attr.OnAuthorization(m_context);

            // assert
            Assert.IsTrue(m_context.Result is RedirectResult);
            RedirectResult redirect = m_context.Result as RedirectResult;
            Assert.AreEqual("/here", redirect.Url);
        }
Exemplo n.º 3
0
        public void ShouldDoNothingIfAuthenticated()
        {
            // arrange
            m_httpContext.WithUser(MockHelpers.User().WithIdentity(MockHelpers.Identity().WithAuthenticationStatus(true)));

            AuthoriseAttribute attr = new AuthoriseAttribute();

            // act
            attr.OnAuthorization(m_context);

            // assert
            Assert.AreEqual(null, m_context.Result);
        }