当前位置: 首页>>代码示例>>C#>>正文


C# MessageHeaders.Contains方法代码示例

本文整理汇总了C#中MessageHeaders.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# MessageHeaders.Contains方法的具体用法?C# MessageHeaders.Contains怎么用?C# MessageHeaders.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MessageHeaders的用法示例。


在下文中一共展示了MessageHeaders.Contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BeforeSendRequestTest

        public void BeforeSendRequestTest()
        {
            // Arrange.
            const string HeaderName1 = "Header1";
            const string HeaderName2 = "Header2";
            const string HeaderNamespace = "TestNamespace";
            const string Actor = "TestActor";

            var oldHeader1 = MessageHeader.CreateHeader(HeaderName1, HeaderNamespace, "Test Value 1");
            var oldHeader2 = MessageHeader.CreateHeader(HeaderName2, HeaderNamespace, "Test Value 2");

            var operationContext = Mock.Create<OperationContext>();
            Mock.Arrange(() => OperationContext.Current).Returns(operationContext);

            var headerAttributes = new SoapHeaderAttributes
                                       {
                                           HeaderName = HeaderName2,
                                           HeaderNamespace = HeaderNamespace,
                                           MustUnderstand = true,
                                           Actor = Actor,
                                           Relay = true
                                       };

            var integrationExtension = new IntegrationServiceOperationContextExtension();
            integrationExtension.HeaderAttributes.Add(headerAttributes);

            var extensions = new ExtensionCollection<OperationContext>(operationContext) { integrationExtension };
            Mock.Arrange(() => operationContext.Extensions).Returns(extensions);

            var message = Mock.Create<Message>();
            var messageHeaders = new MessageHeaders(MessageVersion.Soap11) { oldHeader1, oldHeader2 };
            Mock.Arrange(() => message.Headers).Returns(messageHeaders);

            var inspector = new IntegrationServiceMessageInspector();
            
            // Act.
            var newMessage = message;
            inspector.BeforeSendRequest(ref newMessage, Mock.Create<IClientChannel>());

            // Assert.
            Assert.AreSame(message, newMessage);

            Assert.AreEqual(2, messageHeaders.Count);
            Assert.IsTrue(messageHeaders.Contains(oldHeader1));
            Assert.IsFalse(messageHeaders.Contains(oldHeader2));

            var index = messageHeaders.FindHeader(HeaderName2, HeaderNamespace, Actor);
            var newHeader2 = (XmlElementMessageHeader)messageHeaders[index];

            Assert.IsTrue(newHeader2.MustUnderstand);
            Assert.AreEqual(Actor, newHeader2.Actor);
            Assert.IsTrue(newHeader2.Relay);

            // Exceptions.
            Message nullMessage = null;

            TestsHelper.VerifyThrow<ArgumentNullException>(() => inspector.BeforeSendRequest(ref nullMessage, Mock.Create<IClientChannel>()));

            var message2 = Mock.Create<Message>();
            TestsHelper.VerifyThrow<ArgumentNullException>(() => inspector.BeforeSendRequest(ref message2, null));
        }
开发者ID:mparsin,项目名称:Elements,代码行数:61,代码来源:IntegrationServiceMessageInspectorTests.cs


注:本文中的MessageHeaders.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。