private AuthorizationContext CreateAuthorizationContextWithExpectations(string expectedUserKey, User expectedUser) { MockHttpContext.User = CreateClaimsPrincipal(expectedUserKey); AuthorizationContext filterContext = ControllerContextFactory.CreateAuthorizationContext(MockHttpContextBase); MockAccountManager.Expect(m => m.EnsureUserEntity(filterContext.HttpContext.User.Identity as System.Security.Claims.ClaimsIdentity)).Return(expectedUser); return(filterContext); }
public void GivenPrincipalIsNotClaimsPrincipal_WhenMapFrom_ThenReturnNull() { MockHttpContext.User = MockRepository.GenerateMock <IPrincipal>(); AuthorizationContext filterContext = ControllerContextFactory.CreateAuthorizationContext(MockHttpContextBase); EducationSecurityPrincipal actual = UserIdentityMapAttribute.MapFrom(filterContext); Assert.IsNull(actual); }
public void GivenActionInvokedIsAccountLogOff_AndUserIsNotAnEducationSecurityPrincipal_AndEulaNotAccepted_WhenAuthorizing_ThenSucceed() { User expectedUserEntity = new User { UserKey = "whatever" }; MockHttpContext.User = CreateClaimsPrincipal(expectedUserEntity.UserKey); AuthorizationContext filterContext = ControllerContextFactory.CreateAuthorizationContext(MockHttpContextBase, typeof(AccountController), "LogOff"); System.Security.Claims.ClaimsPrincipal claimsPrincipal = MockHttpContext.User as System.Security.Claims.ClaimsPrincipal; filterContext.HttpContext.User = claimsPrincipal; MockAccountManager.Expect(m => m.EnsureUserEntity((System.Security.Claims.ClaimsIdentity)claimsPrincipal.Identity)).Throw(new LicenseAgreementException()); Target.OnAuthorization(filterContext); }
public void GivenLogicManagerThrowsLicenseAgreementException_WhenAuthorizing_ThenRedirectToLicenseAgreement() { string userKey = "whatever"; MockHttpContext.User = CreateClaimsPrincipal(userKey); AuthorizationContext filterContext = ControllerContextFactory.CreateAuthorizationContext(MockHttpContextBase); MockAccountManager.Expect(m => m.EnsureUserEntity(filterContext.HttpContext.User.Identity as System.Security.Claims.ClaimsIdentity)).Throw(new LicenseAgreementException()); Target.OnAuthorization(filterContext); var actual = filterContext.Result as RedirectToRouteResult; actual.AssertActionRedirection("Index", "Agreement"); }
private static AuthorizationContext CreateAuthorizationContext(bool mockableContext, string userKey) { HttpContextBase httpContext = CreateHttpContextBase(mockableContext, userKey); return(ControllerContextFactory.CreateAuthorizationContext(httpContext)); }
public void GivenPrincipalIsNull_WhenMapFrom_ThenReturnNull() { AuthorizationContext filterContext = ControllerContextFactory.CreateAuthorizationContext(MockHttpContextBase); Assert.IsNull(UserIdentityMapAttribute.MapFrom(filterContext)); }