public void Ensure_That_The_Failure_Manager_Assigns_A_404_Result_To_An_Unauthorizer_Activity_Registered_By_Name_With_A_404_Handler() { var conf = BuilderHelper.BuildConfigurationBuilder(); conf.Register(a => a.Name("Test").AuthorizedBy <UnauthorizedAuthorizer>().HandleFailureWith <HttpNotFoundResult>()); var context = FilterContextHelper.ContextFromExpression <TestController>(c => c.ControllerAction("test")); var manager = new AuthorizationFailureManager(conf.ActivityRegistrations); manager.HandleFailedAuthorization(new NamedActivity("Test"), context); Assert.That(context.Result.GetType(), Is.EqualTo(typeof(HttpNotFoundResult))); }
Ensure_When_We_Call_The_Authorize_Method_And_Handle_Failures_With_An_Unauthorized_ActionExecutingContext_The_Context_Result_Is_Set_To_The_Registered_Failure_Manager () { //arrange var conf = BuilderHelper.BuildConfigurationBuilder(); var context = FilterContextHelper.ContextFromExpression <TestController>(c => c.ControllerAction("test")); conf.Register(a => a.Method <TestController>(c => c.ControllerAction(default(string))).AuthorizedBy <UnauthorizedAuthorizer>().HandleFailureWith <HttpNotFoundResult>()); var service = BuilderHelper.ServiceBuilder(conf); //act service.Authorize(context, new TestPrincipal(), true); //assert Assert.That(context.Result.GetType(), Is.EqualTo(typeof(HttpNotFoundResult))); }
public void Ensure_When_We_Call_The_Authorize_Method_With_An_Authorized_ActionExecutingContext_It_Returns_True() { //arrange var context = FilterContextHelper.ContextFromExpression <TestController>(c => c.ControllerAction("test")); var authresolver = Mock.Of <IAuthorizerResolver>(); Mock.Get(authresolver).Setup(r => r.GetAuthorizers(It.IsAny <LambdaExpression>())).Returns(new IActivityAuthorizer[] { new AllowAnonymous() }); var activityResolver = Mock.Of <IActivityResolver>(); Mock.Get(activityResolver).Setup(s => s.GetActivity(It.IsAny <LambdaExpression>())).Returns(new TestActivity()); var failureManager = Mock.Of <IAuthorizationFailureManager>(); var service = new MvcAuthorizationService(authresolver, activityResolver, failureManager); //act var result = service.Authorize(context, new TestPrincipal()); //assert Assert.That(result, Is.True); }