コード例 #1
0
 public void Behavior_Bad_HttpOperationHandlerFactory_Throws()
 {
     HttpBehaviorElement el = new HttpBehaviorElement();
     ExceptionAssert.Throws<ConfigurationErrorsException>(
         "Setting HttpOperationHandlerFactory to wrong type throws",
         Http.SR.HttpMessageConfigurationPropertyTypeMismatch(typeof(string).FullName, "operationHandlerFactory", typeof(HttpOperationHandlerFactory)),
         () => HttpBehaviorElement.GetHttpOperationHandlerFactory(typeof(string).FullName));
 }
コード例 #2
0
        public void Behavior_Bad_HttpOperationHandlerFactory_Throws()
        {
            HttpBehaviorElement el = new HttpBehaviorElement();

            ExceptionAssert.Throws <ConfigurationErrorsException>(
                "Setting HttpOperationHandlerFactory to wrong type throws",
                Http.SR.HttpMessageConfigurationPropertyTypeMismatch(typeof(string).FullName, "operationHandlerFactory", typeof(HttpOperationHandlerFactory)),
                () => HttpBehaviorElement.GetHttpOperationHandlerFactory(typeof(string).FullName));
        }
コード例 #3
0
        public void HttpBehaviorElement_Ctor_Initializes_All_Properties()
        {
            HttpBehaviorElement el = new HttpBehaviorElement();

            Assert.AreEqual(HttpBehavior.DefaultHelpEnabled, el.HelpEnabled, "HelpEnabled wrong");
            Assert.AreEqual(HttpBehavior.DefaultTrailingSlashMode, el.TrailingSlashMode, "TrailingSlashMode wrong");
            Assert.AreEqual(string.Empty, el.OperationHandlerFactory, "HttpOperationHandlerFactory should default to empty");

            Assert.AreEqual(typeof(HttpBehavior), el.BehaviorType, "BehaviorType wrong");
        }
コード例 #4
0
        private void InternalOnApplyConfiguration(ServiceEndpoint endpoint)
        {
            HttpEndpoint httpEndpoint = endpoint as HttpEndpoint;

            Fx.Assert(httpEndpoint != null, "The endpoint should be of type httpEndpoint since this is what was returned with CreateServiceEndpoint().");

            if (this.IsSet(HttpConfigurationStrings.HelpEnabled))
            {
                httpEndpoint.HelpEnabled = this.HelpEnabled;
            }

            if (this.IsSet(HttpConfigurationStrings.TrailingSlashMode))
            {
                httpEndpoint.TrailingSlashMode = this.TrailingSlashMode;
            }

            if (this.IsSet(HttpConfigurationStrings.OperationHandlerFactory))
            {
                httpEndpoint.OperationHandlerFactory = HttpBehaviorElement.GetHttpOperationHandlerFactory(this.OperationHandlerFactory);
            }

            if (this.IsSet(ConfigurationStrings.HostNameComparisonMode))
            {
                httpEndpoint.HostNameComparisonMode = this.HostNameComparisonMode;
            }

            if (this.IsSet(ConfigurationStrings.MaxBufferPoolSize))
            {
                httpEndpoint.MaxBufferPoolSize = this.MaxBufferPoolSize;
            }

            if (this.IsSet(ConfigurationStrings.MaxBufferSize))
            {
                httpEndpoint.MaxBufferSize = this.MaxBufferSize;
            }

            if (this.IsSet(ConfigurationStrings.MaxReceivedMessageSize))
            {
                httpEndpoint.MaxReceivedMessageSize = this.MaxReceivedMessageSize;
            }

            if (this.IsSet(ConfigurationStrings.TransferMode))
            {
                httpEndpoint.TransferMode = this.TransferMode;
            }

            this.Security.ApplyConfiguration(httpEndpoint.Security);
        }
コード例 #5
0
        public void Behavior_Element_From_Config_Directly()
        {
            ConfigAssert.Execute("Microsoft.ApplicationServer.Http.CIT.Unit.ConfiguredHttpBehaviorTest.config", () =>
            {
                Configuration config             = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                ServiceModelSectionGroup section = ServiceModelSectionGroup.GetSectionGroup(config);
                BehaviorsSection behaviors       = section.Behaviors;

                Assert.AreEqual(2, behaviors.EndpointBehaviors.Count, "Wrong number of behaviors");

                HttpBehaviorElement namedElement = behaviors.EndpointBehaviors[0].FirstOrDefault() as HttpBehaviorElement;
                Assert.AreEqual(TrailingSlashMode.Ignore, namedElement.TrailingSlashMode, "TrailingSlash wrong");
                Assert.IsFalse(namedElement.HelpEnabled, "HelpEnabled wrong");

                HttpBehaviorElement defaultElement = behaviors.EndpointBehaviors[1].FirstOrDefault() as HttpBehaviorElement;
                Assert.AreEqual(TrailingSlashMode.Ignore, defaultElement.TrailingSlashMode, "TrailingSlash wrong");
                Assert.IsFalse(defaultElement.HelpEnabled, "HelpEnabled wrong");
            });
        }
コード例 #6
0
        public void HttpBehaviorElement_Set_Properties()
        {
            HttpBehaviorElement el = new HttpBehaviorElement();

            el.HelpEnabled = false;
            Assert.IsFalse(el.HelpEnabled, "HelpEnabled false");
            el.HelpEnabled = true;
            Assert.IsTrue(el.HelpEnabled, "HelpEnabled true");

            el.TrailingSlashMode = TrailingSlashMode.AutoRedirect;
            Assert.AreEqual(TrailingSlashMode.AutoRedirect, el.TrailingSlashMode, "Autoredirect failed");
            el.TrailingSlashMode = TrailingSlashMode.Ignore;
            Assert.AreEqual(TrailingSlashMode.Ignore, el.TrailingSlashMode, "Ignore failed");

            el.OperationHandlerFactory = "hello";
            Assert.AreEqual("hello", el.OperationHandlerFactory, "OperationHandlerFactory failed");
            el.OperationHandlerFactory = null;
            Assert.AreEqual(string.Empty, el.OperationHandlerFactory, "Null handler provider failed");
            el.OperationHandlerFactory = "  ";
            Assert.AreEqual(string.Empty, el.OperationHandlerFactory, "whitespace handler provider failed");
        }
コード例 #7
0
ファイル: HttpBehaviorElement.cs プロジェクト: nuxleus/WCFWeb
        /// <summary>
        /// Creates the <see cref="HttpBehavior"/> instance.
        /// </summary>
        /// <returns>A new <see cref="HttpBehavior"/> instance.</returns>
        protected override object CreateBehavior()
        {
            HttpBehavior httpBehavior = new HttpBehavior();

            if (this.IsSet(HttpConfigurationStrings.HelpEnabled))
            {
                httpBehavior.HelpEnabled = this.HelpEnabled;
            }

            if (this.IsSet(HttpConfigurationStrings.TrailingSlashMode))
            {
                httpBehavior.TrailingSlashMode = this.TrailingSlashMode;
            }

            if (this.IsSet(HttpConfigurationStrings.OperationHandlerFactory))
            {
                httpBehavior.OperationHandlerFactory = HttpBehaviorElement.GetHttpOperationHandlerFactory(this.OperationHandlerFactory);
            }

            return(httpBehavior);
        }
コード例 #8
0
        public void HttpBehaviorElement_Ctor_Initializes_All_Properties()
        {
            HttpBehaviorElement el = new HttpBehaviorElement();

            Assert.AreEqual(HttpBehavior.DefaultHelpEnabled, el.HelpEnabled, "HelpEnabled wrong");
            Assert.AreEqual(HttpBehavior.DefaultTrailingSlashMode, el.TrailingSlashMode, "TrailingSlashMode wrong");
            Assert.AreEqual(string.Empty, el.OperationHandlerFactory, "HttpOperationHandlerFactory should default to empty");

            Assert.AreEqual(typeof(HttpBehavior), el.BehaviorType, "BehaviorType wrong");
        }
コード例 #9
0
        public void HttpBehaviorElement_Set_Properties()
        {
            HttpBehaviorElement el = new HttpBehaviorElement();

            el.HelpEnabled = false;
            Assert.IsFalse(el.HelpEnabled, "HelpEnabled false");
            el.HelpEnabled = true;
            Assert.IsTrue(el.HelpEnabled, "HelpEnabled true");

            el.TrailingSlashMode = TrailingSlashMode.AutoRedirect;
            Assert.AreEqual(TrailingSlashMode.AutoRedirect, el.TrailingSlashMode, "Autoredirect failed");
            el.TrailingSlashMode = TrailingSlashMode.Ignore;
            Assert.AreEqual(TrailingSlashMode.Ignore, el.TrailingSlashMode, "Ignore failed");

            el.OperationHandlerFactory = "hello";
            Assert.AreEqual("hello", el.OperationHandlerFactory, "OperationHandlerFactory failed");
            el.OperationHandlerFactory = null;
            Assert.AreEqual(string.Empty, el.OperationHandlerFactory, "Null handler provider failed");
            el.OperationHandlerFactory = "  ";
            Assert.AreEqual(string.Empty, el.OperationHandlerFactory, "whitespace handler provider failed");
        }