Beispiel #1
0
        public void GetCorsPolicyProvider_ReturnsPolicyProvider_OnController()
        {
            AttributeBasedPolicyProviderFactory providerFactory =
                new AttributeBasedPolicyProviderFactory();
            HttpRequestMessage       request = new HttpRequestMessage();
            Func <string>            action  = new SampleController().Get;
            HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor
            {
                ControllerName = "Sample",
                ControllerType = typeof(SampleController)
            };

            request.SetActionDescriptor(
                new ReflectedHttpActionDescriptor
            {
                MethodInfo           = action.Method,
                ControllerDescriptor = controllerDescriptor
            }
                );
            request.Headers.Add("Origin", "http://example.com");

            ICorsPolicyProvider policyProvider = providerFactory.GetCorsPolicyProvider(request);

            Assert.NotNull(policyProvider);
            Assert.IsType <EnableCorsAttribute>(policyProvider);
        }
        public void GetCorsPolicyProvider_ReturnsPolicyProvider_OnAction()
        {
            AttributeBasedPolicyProviderFactory providerFactory = new AttributeBasedPolicyProviderFactory();
            HttpRequestMessage request = new HttpRequestMessage();
            Func <string>      action  = new SampleController().Post;

            request.SetActionDescriptor(new ReflectedHttpActionDescriptor
            {
                MethodInfo = action.Method
            });
            request.Headers.Add("Origin", "http://example.com");

            ICorsPolicyProvider policyProvider = providerFactory.GetCorsPolicyProvider(request);

            Assert.NotNull(policyProvider);
            Assert.IsType(typeof(DisableCorsAttribute), policyProvider);
        }
        public void GetCorsPolicyProvider_ReturnsPolicyProvider_OnAction()
        {
            AttributeBasedPolicyProviderFactory providerFactory = new AttributeBasedPolicyProviderFactory();
            HttpRequestMessage request = new HttpRequestMessage();
            Func<string> action = new SampleController().Post;
            request.Properties[HttpPropertyKeys.HttpActionDescriptorKey] = new ReflectedHttpActionDescriptor
            {
                MethodInfo = action.Method
            };
            request.Headers.Add("Origin", "http://example.com");

            ICorsPolicyProvider policyProvider = providerFactory.GetCorsPolicyProvider(request);

            Assert.NotNull(policyProvider);
            Assert.IsType(typeof(DisableCorsAttribute), policyProvider);
        }
        public void GetCorsPolicyProvider_ReturnsPolicyProvider_OnController()
        {
            AttributeBasedPolicyProviderFactory providerFactory = new AttributeBasedPolicyProviderFactory();
            HttpRequestMessage request = new HttpRequestMessage();
            Func<string> action = new SampleController().Get;
            HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor
            {
                ControllerName = "Sample",
                ControllerType = typeof(SampleController)
            };
            request.SetActionDescriptor(new ReflectedHttpActionDescriptor
            {
                MethodInfo = action.Method,
                ControllerDescriptor = controllerDescriptor
            });
            request.Headers.Add("Origin", "http://example.com");

            ICorsPolicyProvider policyProvider = providerFactory.GetCorsPolicyProvider(request);

            Assert.NotNull(policyProvider);
            Assert.IsType(typeof(EnableCorsAttribute), policyProvider);
        }