public void Should_set_the_result_of_the_filtercontext() { // Arrange SecurityConfigurator.Configure(policy => { policy.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsTrue); policy.For <BlogController>(x => x.Index()).DenyAnonymousAccess(); }); var expectedResult = new ViewResult { ViewName = "SomeViewName" }; var securityHandler = new Mock <ISecurityHandler>(); securityHandler.Setup(x => x.HandleSecurityFor(typeof(BlogController).FullName, "Index", It.IsAny <ISecurityContext>())).Returns(expectedResult); var handleSecurityAttribute = new HandleSecurityAttribute(securityHandler.Object); var filterContext = MvcHelpers.GetAuthorizationContextFor <BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnAuthorization(filterContext); // Assert Assert.That(filterContext.Result, Is.EqualTo(expectedResult)); }
public void Should_add_route_values_to_current_security_context() { // Arrange var securityHandler = new Mock <ISecurityHandler>(); var handleSecurityAttribute = new HandleSecurityAttribute(securityHandler.Object); var filterContext = MvcHelpers.GetAuthorizationContextFor <BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnAuthorization(filterContext); // Assert Assert.That(_securityContext.Data.RouteValues, Is.Not.Null); Assert.That(_securityContext.Data.RouteValues, Is.EqualTo(filterContext.RouteData.Values)); }
public void Should_call_HandleSecurityFor_with_the_controllername_Blog_and_actionname_Index_passing_the_current_security_context() { // Arrange var securityHandler = new Mock <ISecurityHandler>(); var handleSecurityAttribute = new HandleSecurityAttribute(securityHandler.Object); var filterContext = MvcHelpers.GetAuthorizationContextFor <BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnAuthorization(filterContext); // Assert Assert.That(filterContext.Result, Is.Null); securityHandler.Verify(x => x.HandleSecurityFor(typeof(BlogController).FullName, "Index", _securityContext), Times.Exactly(1)); }
public void Should_add_route_values_to_current_security_context() { // Arrange var securityHandler = new Mock<ISecurityHandler>(); var handleSecurityAttribute = new HandleSecurityAttribute(securityHandler.Object); var filterContext = MvcHelpers.GetAuthorizationContextFor<BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnAuthorization(filterContext); // Assert Assert.That(_securityContext.Data.RouteValues, Is.Not.Null); Assert.That(_securityContext.Data.RouteValues, Is.EqualTo(filterContext.RouteData.Values)); }
public void Should_set_the_result_of_the_filtercontext() { // Arrange SecurityConfigurator.Configure(policy => { policy.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsTrue); policy.For<BlogController>(x => x.Index()).DenyAnonymousAccess(); }); var expectedResult = new ViewResult { ViewName = "SomeViewName" }; var securityHandler = new Mock<ISecurityHandler>(); securityHandler.Setup(x => x.HandleSecurityFor(typeof(BlogController).FullName, "Index", It.IsAny<ISecurityContext>())).Returns(expectedResult); var handleSecurityAttribute = new HandleSecurityAttribute(securityHandler.Object); var filterContext = MvcHelpers.GetAuthorizationContextFor<BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnAuthorization(filterContext); // Assert Assert.That(filterContext.Result, Is.EqualTo(expectedResult)); }
public void Should_call_HandleSecurityFor_with_the_controllername_Blog_and_actionname_Index_passing_the_current_security_context() { // Arrange var securityHandler = new Mock<ISecurityHandler>(); var handleSecurityAttribute = new HandleSecurityAttribute(securityHandler.Object); var filterContext = MvcHelpers.GetAuthorizationContextFor<BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnAuthorization(filterContext); // Assert Assert.That(filterContext.Result, Is.Null); securityHandler.Verify(x => x.HandleSecurityFor(typeof(BlogController).FullName, "Index", _securityContext), Times.Exactly(1)); }