public void IsAccessibleToUser_should_return_true_if_AuthorizationContext_Result_is_null() { Mock <AuthorizeAttribute> decoratedActionAttribute = new Mock <AuthorizeAttribute>(); Mock <AuthorizeAttribute> decoratedControllerAttribute = new Mock <AuthorizeAttribute>(); IList <AuthorizeAttribute> attributes = new List <AuthorizeAttribute> { decoratedActionAttribute.Object, decoratedControllerAttribute.Object }; _authorizeAttributeCache.Setup(c => c.GetAuthorizeAttributes(It.IsAny <RequestContext>(), It.IsAny <string>(), It.IsAny <string>(), null)).Returns(attributes); _authorizationContextCache.Setup(c => c.GetAuthorizationContext(It.IsAny <RequestContext>(), It.IsAny <string>(), It.IsAny <string>(), null)).Returns(_authorizationContext.Object); Assert.True(_controllerAuthorization.IsAccessibleToUser(TestHelper.CreateRequestContext(), "Default")); }
public void IsAccessibleToUser_for_action_should_use_reflected_attribute_when_decorated_with_custom_attribute() { Mock <AuthorizeAttribute> decoratedActionAttribute = new Mock <AuthorizeAttribute>(); Mock <AuthorizeAttribute> decoratedControllerAttribute = new Mock <AuthorizeAttribute>(); IList <AuthorizeAttribute> attributes = new List <AuthorizeAttribute> { decoratedActionAttribute.Object, decoratedControllerAttribute.Object }; _authorizeAttributeCache.Setup(c => c.GetAuthorizeAttributes(It.IsAny <RequestContext>(), It.IsAny <string>(), It.IsAny <string>(), null)).Returns(attributes); Mock <IAuthorizeAttribute> reflectedAttribute = new Mock <IAuthorizeAttribute>(); reflectedAttribute.Setup(a => a.IsAuthorized(It.IsAny <HttpContextBase>())).Returns(true); _reflectedAuthorizeAttributeCache.Setup(c => c.GetAttribute(It.IsAny <Type>())).Returns(reflectedAttribute.Object); Assert.True(_controllerAuthorization.IsAccessibleToUser(TestHelper.CreateRequestContext(), "Default")); }