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


C# MockHeaders.AddHeaders方法代码示例

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


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

示例1: AddHeaders_SourceHasInvalidHeaderValues_InvalidHeadersRemovedFromSourceAndNotCopiedToDestination

        public void AddHeaders_SourceHasInvalidHeaderValues_InvalidHeadersRemovedFromSourceAndNotCopiedToDestination()
        {
            Dictionary<string, HttpHeaderParser> parserStore = new Dictionary<string, HttpHeaderParser>();
            parserStore.Add("known", new MockHeaderParser());

            MockHeaders source = new MockHeaders(parserStore);
            source.TryAddWithoutValidation("known", invalidHeaderValue + "\r\ninvalid");
            source.TryAddWithoutValidation("custom", "invalid\r\nvalue");

            MockHeaders destination = new MockHeaders(parserStore);
            destination.AddHeaders(source);

            Assert.Equal(0, source.Count());
            Assert.False(source.Contains("known"), "source contains 'known' header.");
            Assert.False(source.Contains("custom"), "source contains 'custom' header.");
            Assert.Equal(0, destination.Count());
            Assert.False(destination.Contains("known"), "destination contains 'known' header.");
            Assert.False(destination.Contains("custom"), "destination contains 'custom' header.");
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:19,代码来源:HttpHeadersTest.cs

示例2: AddHeaders_SourceHasEmptyHeaderStore_DestinationRemainsUnchanged

        public void AddHeaders_SourceHasEmptyHeaderStore_DestinationRemainsUnchanged()
        {
            Dictionary<string, HttpHeaderParser> parserStore = new Dictionary<string, HttpHeaderParser>();
            parserStore.Add("known1", new MockHeaderParser());

            MockHeaders source = new MockHeaders(parserStore);

            MockHeaders destination = new MockHeaders(parserStore);
            destination.Add("known1", rawPrefix);

            destination.AddHeaders(source);

            Assert.Equal(1, destination.Count());
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:14,代码来源:HttpHeadersTest.cs

示例3: AddHeaders_DestinationHasEmptyHeaderStore_DestinationHeaderStoreGetsCreatedAndValuesAdded

        public void AddHeaders_DestinationHasEmptyHeaderStore_DestinationHeaderStoreGetsCreatedAndValuesAdded()
        {
            Dictionary<string, HttpHeaderParser> parserStore = new Dictionary<string, HttpHeaderParser>();
            parserStore.Add("known1", new MockHeaderParser());

            MockHeaders source = new MockHeaders(parserStore);
            source.Add("known1", rawPrefix);

            MockHeaders destination = new MockHeaders(parserStore);

            destination.AddHeaders(source);

            Assert.Equal(1, destination.Count());
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:14,代码来源:HttpHeadersTest.cs

示例4: MockHeaderParser

        public void AddHeaders_SourceAndDestinationStoreHaveMultipleHeaders_OnlyHeadersNotInDestinationAreCopiedFromSource()
        {
            Dictionary<string, HttpHeaderParser> parserStore = new Dictionary<string, HttpHeaderParser>();
            parserStore.Add("known1", new MockHeaderParser());
            parserStore.Add("known2", new MockHeaderParser());
            parserStore.Add("known3", new MockHeaderParser());
            parserStore.Add("known4", new CustomTypeHeaderParser());

            // Add header values to the source store.
            MockHeaders source = new MockHeaders(parserStore);
            source.Add("custom1", "source10");
            source.Add("custom1", "source11");

            source.TryAddWithoutValidation("custom2", "source2");

            source.Add("known1", rawPrefix + "3");
            source.TryAddWithoutValidation("known1", rawPrefix + "4");

            source.TryAddWithoutValidation("known2", rawPrefix + "5");
            source.TryAddWithoutValidation("known2", invalidHeaderValue);
            source.TryAddWithoutValidation("known2", rawPrefix + "7");

            // this header value gets removed when it gets parsed.
            source.TryAddWithoutValidation("known3", (string)null);
            source.Add("known3", string.Empty);

            DateTimeOffset known4Value1 = new DateTimeOffset(2010, 6, 15, 18, 31, 34, TimeSpan.Zero);
            DateTimeOffset known4Value2 = new DateTimeOffset(2010, 4, 8, 11, 21, 04, TimeSpan.Zero);
            source.AddParsedValue("known4", known4Value1);
            source.AddParsedValue("known4", known4Value2);

            source.Add("custom5", "source5");
            source.TryAddWithoutValidation("custom6", (string)null);

            // This header value gets added even though it doesn't have values. But since this is a custom header we
            // assume it supports empty values.
            source.TryAddWithoutValidation("custom7", (string)null);
            source.Add("custom7", string.Empty);

            // Add header values to the destination store.
            MockHeaders destination = new MockHeaders(parserStore);
            destination.Add("custom2", "destination1");
            destination.Add("known1", rawPrefix + "9");

            // Now add all headers that are in source but not destination to destination.
            destination.AddHeaders(source);

            Assert.Equal(8, destination.Count());

            Assert.Equal(2, destination.GetValues("custom1").Count());
            Assert.Equal("source10", destination.GetValues("custom1").ElementAt(0));
            Assert.Equal("source11", destination.GetValues("custom1").ElementAt(1));

            // This value was set in destination. The header in source was ignored.
            Assert.Equal(1, destination.GetValues("custom2").Count());
            Assert.Equal("destination1", destination.GetValues("custom2").First());

            // This value was set in destination. The header in source was ignored.
            Assert.Equal(1, destination.GetValues("known1").Count());
            Assert.Equal(parsedPrefix + "9", destination.GetValues("known1").First());

            // The header in source gets first parsed and then copied to destination. Note that here we have one
            // invalid value.
            Assert.Equal(3, destination.GetValues("known2").Count());
            Assert.Equal(parsedPrefix + "5", destination.GetValues("known2").ElementAt(0));
            Assert.Equal(parsedPrefix + "7", destination.GetValues("known2").ElementAt(1));
            Assert.Equal(invalidHeaderValue, destination.GetValues("known2").ElementAt(2));

            // Header 'known3' should not be copied, since it doesn't contain any values.
            Assert.False(destination.Contains("known3"), "'known3' header value count.");

            Assert.Equal(2, destination.GetValues("known4").Count());
            Assert.Equal(known4Value1.ToString(), destination.GetValues("known4").ElementAt(0));
            Assert.Equal(known4Value2.ToString(), destination.GetValues("known4").ElementAt(1));

            Assert.Equal("source5", destination.GetValues("custom5").First());

            Assert.Equal(string.Empty, destination.GetValues("custom6").First());

            // Unlike 'known3', 'custom7' was added even though it only had empty values. The reason is that 'custom7'
            // is a custom header so we just add whatever value we get passed in.
            Assert.Equal(2, destination.GetValues("custom7").Count());
            Assert.Equal("", destination.GetValues("custom7").ElementAt(0));
            Assert.Equal("", destination.GetValues("custom7").ElementAt(1));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:85,代码来源:HttpHeadersTest.cs


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