Beispiel #1
0
        public void CreateControllerModel_AuthorizeAttributeAddsAuthorizeFilter()
        {
            // Arrange
            var provider        = new AuthorizationApplicationModelProvider(new TestOptionsManager <AuthorizationOptions>());
            var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager <MvcOptions>());

            var context = new ApplicationModelProviderContext(new[] { typeof(AccountController).GetTypeInfo() });

            defaultProvider.OnProvidersExecuting(context);

            // Act
            provider.OnProvidersExecuting(context);

            // Assert
            var controller = Assert.Single(context.Result.Controllers);

            Assert.Single(controller.Filters, f => f is AuthorizeFilter);
        }
Beispiel #2
0
        public void CreateControllerModel_DisableCorsAttributeAddsDisableCorsAuthorizationFilter()
        {
            // Arrange
            var corsProvider    = new CorsApplicationModelProvider();
            var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager <MvcOptions>());

            var context = new ApplicationModelProviderContext(new[] { typeof(DisableCorsController).GetTypeInfo() });

            defaultProvider.OnProvidersExecuting(context);

            // Act
            corsProvider.OnProvidersExecuting(context);

            // Assert
            var model = Assert.Single(context.Result.Controllers);

            Assert.Single(model.Filters, f => f is DisableCorsAuthorizationFilter);
        }
        public void CreateControllerModel_EnableCorsAttributeAddsCorsAuthorizationFilterFactory()
        {
            // Arrange
            var corsProvider    = new CorsApplicationModelProvider();
            var defaultProvider = new DefaultApplicationModelProvider(new MockMvcOptionsAccessor());

            var context = new ApplicationModelProviderContext(new [] { typeof(CorsController).GetTypeInfo() });

            defaultProvider.OnProvidersExecuting(context);

            // Act
            corsProvider.OnProvidersExecuting(context);

            // Assert
            var model = Assert.Single(context.Result.Controllers);

            Assert.Single(model.Filters, f => f is CorsAuthorizationFilterFactory);
        }
Beispiel #4
0
        public void BuildActionModel_EnableCorsAttributeAddsCorsAuthorizationFilterFactory()
        {
            // Arrange
            var corsProvider    = new CorsApplicationModelProvider();
            var defaultProvider = new DefaultApplicationModelProvider(new TestOptionsManager <MvcOptions>());

            var context = new ApplicationModelProviderContext(new[] { typeof(EnableCorsController).GetTypeInfo() });

            defaultProvider.OnProvidersExecuting(context);

            // Act
            corsProvider.OnProvidersExecuting(context);

            // Assert
            var controller = Assert.Single(context.Result.Controllers);
            var action     = Assert.Single(controller.Actions);

            Assert.Single(action.Filters, f => f is CorsAuthorizationFilterFactory);
        }
        public void BuildActionModel_DisableCorsAttributeAddsDisableCorsAuthorizationFilter()
        {
            // Arrange
            var corsProvider    = new CorsApplicationModelProvider();
            var defaultProvider = new DefaultApplicationModelProvider(new MockMvcOptionsAccessor());

            var context = new ApplicationModelProviderContext(new[] { typeof(DisableCorsActionController).GetTypeInfo() });

            defaultProvider.OnProvidersExecuting(context);

            // Act
            corsProvider.OnProvidersExecuting(context);

            // Assert
            var controller = Assert.Single(context.Result.Controllers);
            var action     = Assert.Single(controller.Actions);

            Assert.True(action.Filters.Any(f => f is DisableCorsAuthorizationFilter));
        }