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 = MockRepository.GenerateMock <ISecurityHandler>(); securityHandler.Expect(x => x.HandleSecurityFor(typeof(BlogController).FullName, "Index")).Repeat.Once().Return(expectedResult); securityHandler.Replay(); var handleSecurityAttribute = new HandleSecurityAttribute(securityHandler); var filterContext = MvcHelpers.GetFilterContextFor <BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnActionExecuting(filterContext); // Assert Assert.That(filterContext.Result, Is.EqualTo(expectedResult)); securityHandler.VerifyAllExpectations(); }
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_have_SecurityHandler_set() { SecurityConfigurator.Configure(config => config.GetAuthenticationStatusFrom(() => true)); // Act var attribute = new HandleSecurityAttribute(); // Assert Assert.That(attribute.Handler, Is.TypeOf<SecurityHandler>()); }
public void Should_have_SecurityHandler_set() { SecurityConfigurator.Configure(config => config.GetAuthenticationStatusFrom(() => true)); // Act var attribute = new HandleSecurityAttribute(); // Assert Assert.That(attribute.Handler, Is.TypeOf <SecurityHandler>()); }
public void Should_have_SecurityHandler_set() { SecurityConfigurator.Configure(config => {}); // Act var attribute = new HandleSecurityAttribute(); // Assert Assert.That(attribute.SecurityHandler, Is.AssignableTo(typeof(ISecurityHandler))); Assert.That(attribute.SecurityHandler, Is.Not.Null); }
public void Should_have_SecurityHandler_set() { // Arrange var securityHandler = new Mock<ISecurityHandler>(); // Act var attribute = new HandleSecurityAttribute(securityHandler.Object); // Assert Assert.That(attribute.Handler, Is.EqualTo(securityHandler.Object)); }
public void Should_have_SecurityHandler_set() { // Arrange var securityHandler = new Mock <ISecurityHandler>(); // Act var attribute = new HandleSecurityAttribute(securityHandler.Object); // Assert Assert.That(attribute.Handler, Is.EqualTo(securityHandler.Object)); }
public void Should_have_SecurityHandler_set() { // Arrange var mockSecurityHandler = MockRepository.GenerateMock <ISecurityHandler>(); // Act var attribute = new HandleSecurityAttribute(mockSecurityHandler); // Assert Assert.That(attribute.SecurityHandler, Is.AssignableTo(typeof(ISecurityHandler))); Assert.That(attribute.SecurityHandler, Is.EqualTo(mockSecurityHandler)); }
public void Should_have_SecurityHandler_set() { // Arrange var mockSecurityHandler = MockRepository.GenerateMock<ISecurityHandler>(); // Act var attribute = new HandleSecurityAttribute(mockSecurityHandler); // Assert Assert.That(attribute.SecurityHandler, Is.AssignableTo(typeof(ISecurityHandler))); Assert.That(attribute.SecurityHandler, Is.EqualTo(mockSecurityHandler)); }
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.GetFilterContextFor <BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnActionExecuting(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.GetFilterContextFor <BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnActionExecuting(filterContext); // Assert Assert.That(filterContext.Result, Is.Null); securityHandler.Verify(x => x.HandleSecurityFor(typeof(BlogController).FullName, "Index", _securityContext), Times.Exactly(1)); }
public void Should_call_HandleSecurityFor_with_the_controllername_Blog_and_actionname_Index() { // Arrange SecurityConfigurator.Configure(policy => { policy.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsTrue); policy.For<BlogController>(x => x.Index()).DenyAnonymousAccess(); }); var securityHandler = MockRepository.GenerateMock<ISecurityHandler>(); securityHandler.Expect(x => x.HandleSecurityFor(typeof(BlogController).FullName, "Index")).Repeat.Once().Return(null); securityHandler.Replay(); var handleSecurityAttribute = new HandleSecurityAttribute(securityHandler); var filterContext = MvcHelpers.GetFilterContextFor<BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnActionExecuting(filterContext); // Assert Assert.That(filterContext.Result, Is.Null); securityHandler.VerifyAllExpectations(); }
public void Should_call_HandleSecurityFor_with_the_controllername_Blog_and_actionname_Index() { // Arrange SecurityConfigurator.Configure(policy => { policy.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsTrue); policy.For <BlogController>(x => x.Index()).DenyAnonymousAccess(); }); var securityHandler = MockRepository.GenerateMock <ISecurityHandler>(); securityHandler.Expect(x => x.HandleSecurityFor(typeof(BlogController).FullName, "Index")).Repeat.Once().Return(null); securityHandler.Replay(); var handleSecurityAttribute = new HandleSecurityAttribute(securityHandler); var filterContext = MvcHelpers.GetFilterContextFor <BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnActionExecuting(filterContext); // Assert Assert.That(filterContext.Result, Is.Null); securityHandler.VerifyAllExpectations(); }
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.GetFilterContextFor<BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnActionExecuting(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.GetFilterContextFor<BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnActionExecuting(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.GetFilterContextFor<BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnActionExecuting(filterContext); // Assert Assert.That(filterContext.Result, Is.EqualTo(expectedResult)); }
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 = MockRepository.GenerateMock<ISecurityHandler>(); securityHandler.Expect(x => x.HandleSecurityFor("Blog", "Index")).Repeat.Once().Return(expectedResult); securityHandler.Replay(); var handleSecurityAttribute = new HandleSecurityAttribute(securityHandler); var filterContext = MvcHelpers.GetFilterContextFor<BlogController>(x => x.Index()); // Act handleSecurityAttribute.OnActionExecuting(filterContext); // Assert Assert.That(filterContext.Result, Is.EqualTo(expectedResult)); securityHandler.VerifyAllExpectations(); }