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


C# MockHeaders.GetValues方法代码示例

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


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

示例1: RemoveSpecialValue_AddTwoValuesAndSpecialValueThenRemoveSpecialValue_SpecialValueGetsRemoved

        public void RemoveSpecialValue_AddTwoValuesAndSpecialValueThenRemoveSpecialValue_SpecialValueGetsRemoved()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers,
                specialValue);

            collection.Add(new Uri("http://www.example.org/1/"));
            collection.Add(new Uri("http://www.example.org/2/"));
            collection.SetSpecialValue();
            Assert.True(collection.IsSpecialValueSet, "Special value not set.");
            Assert.Equal(3, headers.GetValues(knownHeader).Count());

            // The difference between this test and the previous one is that HttpHeaders in this case will use
            // a List<T> to store the two remaining values, whereas in the previous case it will just store
            // the remaining value (no list).
            collection.RemoveSpecialValue();
            Assert.False(collection.IsSpecialValueSet, "Special value is set.");
            Assert.Equal(2, headers.GetValues(knownHeader).Count());
        }
开发者ID:dotnet,项目名称:corefx,代码行数:19,代码来源:HttpHeaderValueCollectionTest.cs

示例2: RemoveSpecialValue_AddRemoveSpecialValue_SpecialValueGetsRemoved

        public void RemoveSpecialValue_AddRemoveSpecialValue_SpecialValueGetsRemoved()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers,
                specialValue);

            collection.SetSpecialValue();
            Assert.True(collection.IsSpecialValueSet, "Special value not set.");
            Assert.Equal(1, headers.GetValues(knownHeader).Count());

            collection.RemoveSpecialValue();
            Assert.False(collection.IsSpecialValueSet, "Special value is set.");

            // Since the only header value was the "special value", removing it will remove the whole header
            // from the collection.
            Assert.False(headers.Contains(knownHeader));
        }
开发者ID:dotnet,项目名称:corefx,代码行数:17,代码来源:HttpHeaderValueCollectionTest.cs

示例3: RemoveSpecialValue_AddValueAndSpecialValueThenRemoveSpecialValue_SpecialValueGetsRemoved

        public void RemoveSpecialValue_AddValueAndSpecialValueThenRemoveSpecialValue_SpecialValueGetsRemoved()
        {
            MockHeaders headers = new MockHeaders(knownHeader, new MockHeaderParser(typeof(Uri)));
            HttpHeaderValueCollection<Uri> collection = new HttpHeaderValueCollection<Uri>(knownHeader, headers,
                specialValue);

            collection.Add(new Uri("http://www.example.org/"));
            collection.SetSpecialValue();
            Assert.True(collection.IsSpecialValueSet, "Special value not set.");
            Assert.Equal(2, headers.GetValues(knownHeader).Count());

            collection.RemoveSpecialValue();
            Assert.False(collection.IsSpecialValueSet, "Special value is set.");
            Assert.Equal(1, headers.GetValues(knownHeader).Count());
        }
开发者ID:dotnet,项目名称:corefx,代码行数:15,代码来源:HttpHeaderValueCollectionTest.cs

示例4: RemoveParsedValue_AddInvalidValueAndRemoveValidValue_InvalidValueRemains

        public void RemoveParsedValue_AddInvalidValueAndRemoveValidValue_InvalidValueRemains()
        {
            MockHeaders headers = new MockHeaders();
            headers.TryAddWithoutValidation(knownHeader, invalidHeaderValue);

            // Remove a valid value which is not in the store.
            Assert.False(headers.RemoveParsedValue(knownHeader, parsedPrefix));

            Assert.Equal(1, headers.Parser.TryParseValueCallCount);

            // Note that when the last value of a header gets removed, the whole header gets removed.
            Assert.Equal(1, headers.Count());
            Assert.Equal(invalidHeaderValue, headers.GetValues(knownHeader).First());

            Assert.Equal(1, headers.Parser.TryParseValueCallCount);

            // Remove the value again: It shouldn't be found in the store.
            Assert.False(headers.RemoveParsedValue(knownHeader, parsedPrefix + "1"));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:19,代码来源:HttpHeadersTest.cs

示例5: MockHeaders

        public void RemoveParsedValue_AddTwoValuesToKnownHeaderAndCompareWithValueThatDiffersInCase_CustomComparerUsedForComparison()
        {
            MockHeaders headers = new MockHeaders();
            headers.AddParsedValue(knownHeader, "differentvalue");
            headers.AddParsedValue(knownHeader, "value");

            // Our custom comparer (MockComparer) does case-insensitive value comparison. Verify that our custom
            // comparer is used to compare the header value.
            // Note that since we added 2 values a different code path than in the previous test is used. In this
            // case we have stored the values as List<string> internally.
            Assert.True(headers.RemoveParsedValue(knownHeader, "VALUE"));
            Assert.Equal(1, headers.GetValues(knownHeader).Count());
            Assert.Equal(2, headers.Parser.MockComparer.EqualsCount);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:14,代码来源:HttpHeadersTest.cs

示例6: 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

示例7: Add_SingleAddHeadersWithDifferentCasing_ConsideredTheSameHeader

        public void Add_SingleAddHeadersWithDifferentCasing_ConsideredTheSameHeader()
        {
            MockHeaders headers = new MockHeaders();
            headers.Add("custom-header", "value1");
            headers.Add("Custom-Header", "value2");
            headers.Add("CUSTOM-HEADER", "value2");

            Assert.Equal(3, headers.GetValues("custom-header").Count());
            Assert.Equal(3, headers.GetValues("Custom-Header").Count());
            Assert.Equal(3, headers.GetValues("CUSTOM-HEADER").Count());
            Assert.Equal(3, headers.GetValues("CuStOm-HeAdEr").Count());
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:12,代码来源:HttpHeadersTest.cs

示例8: SetParsedValue_SetValueAfterAddingMultipleValues_SetValueReplacesOtherValues

        public void SetParsedValue_SetValueAfterAddingMultipleValues_SetValueReplacesOtherValues()
        {
            MockHeaders headers = new MockHeaders();
            headers.Add(knownHeader, rawPrefix + "1");
            headers.TryAddWithoutValidation(knownHeader, rawPrefix + "2");

            Assert.Equal(1, headers.Parser.TryParseValueCallCount);

            headers.SetParsedValue(knownHeader, parsedPrefix + "3");

            // Adding a parsed value, will trigger all raw values to be parsed.
            Assert.Equal(2, headers.Parser.TryParseValueCallCount);

            Assert.Equal(1, headers.GetValues(knownHeader).Count());
            Assert.Equal(parsedPrefix + "3", headers.First().Value.ElementAt(0));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:16,代码来源:HttpHeadersTest.cs

示例9: TryAddWithoutValidation_AddEmptyValueString_HeaderWithNoValueAfterParsing

        public void TryAddWithoutValidation_AddEmptyValueString_HeaderWithNoValueAfterParsing()
        {
            MockHeaders headers = new MockHeaders();

            // The parser returns 'true' to indicate that it could parse the value (empty values allowed) and an 
            // value of 'null'. HttpHeaders will remove the header from the collection since the known header doesn't
            // have a value.
            headers.TryAddWithoutValidation(knownHeader, string.Empty);
            Assert.Equal(0, headers.Parser.TryParseValueCallCount);
            Assert.Equal(0, headers.Count());

            headers.Clear();
            headers.TryAddWithoutValidation("custom", (string)null);
            Assert.Equal(1, headers.Count());
            Assert.Equal(1, headers.First().Value.Count());
            Assert.Equal(string.Empty, headers.GetValues("custom").First());
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:17,代码来源:HttpHeadersTest.cs

示例10: AddParsedValue_UseDifferentAddMethods_AllValuesAddedCorrectly

        public void AddParsedValue_UseDifferentAddMethods_AllValuesAddedCorrectly()
        {
            MockHeaders headers = new MockHeaders();
            headers.Add(knownHeader, rawPrefix + "1");
            headers.TryAddWithoutValidation(knownHeader, rawPrefix + "2");

            Assert.Equal(1, headers.Parser.TryParseValueCallCount);

            headers.AddParsedValue(knownHeader, parsedPrefix + "3");

            // Adding a parsed value, will trigger all raw values to be parsed.
            Assert.Equal(2, headers.Parser.TryParseValueCallCount);

            Assert.Equal(3, headers.GetValues(knownHeader).Count());
            Assert.Equal(parsedPrefix + "1", headers.First().Value.ElementAt(0));
            Assert.Equal(parsedPrefix + "2", headers.First().Value.ElementAt(1));
            Assert.Equal(parsedPrefix + "3", headers.First().Value.ElementAt(2));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:18,代码来源:HttpHeadersTest.cs

示例11: GetValues_HeadersWithEmptyValues_ReturnsEmptyArray

        public void GetValues_HeadersWithEmptyValues_ReturnsEmptyArray()
        {
            MockHeaders headers = new MockHeaders();
            headers.TryAddWithoutValidation(customHeader, (string)null);
            headers.Add(knownHeader, string.Empty);

            // In the known header case, the MockParser accepts empty values but tells the store to not add the value.
            // Since no value is added for 'knownHeader', HttpHeaders removes the header from the store. This is only
            // done for known headers. Custom headers are allowed to have empty/null values as shown by 
            // 'valuesForCustomHeaders' below
            Assert.False(headers.Contains(knownHeader));

            // In the custom header case, we add whatever the users adds (besides that we add string.Empty if the
            // user adds null). So here we do have 1 value: string.Empty.
            IEnumerable<string> valuesForCustomHeader = headers.GetValues(customHeader);
            Assert.NotNull(valuesForCustomHeader);
            Assert.Equal(1, valuesForCustomHeader.Count());
            Assert.Equal(string.Empty, valuesForCustomHeader.First());
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:19,代码来源:HttpHeadersTest.cs

示例12: GetValues_GetValuesForExistingHeader_ReturnsTrueAndListOfValues

        public void GetValues_GetValuesForExistingHeader_ReturnsTrueAndListOfValues()
        {
            MockHeaders headers = new MockHeaders();
            headers.TryAddWithoutValidation("custom", rawPrefix + "0"); // this must not influence the result.
            headers.Add(knownHeader, rawPrefix + "1");
            headers.TryAddWithoutValidation(knownHeader, rawPrefix + "2");

            // Only 1 value should get parsed (call to Add() with known header value).
            Assert.Equal(1, headers.Parser.TryParseValueCallCount);

            IEnumerable<string> values = headers.GetValues(knownHeader);
            Assert.NotNull(values);

            // GetValues() should trigger parsing of values added with TryAddWithoutValidation()
            Assert.Equal(2, headers.Parser.TryParseValueCallCount);

            Assert.Equal(2, values.Count());

            // Check returned values
            Assert.Equal(parsedPrefix + "1", values.ElementAt(0));
            Assert.Equal(parsedPrefix + "2", values.ElementAt(1));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:22,代码来源:HttpHeadersTest.cs

示例13: GetValues_GetValuesForNonExistingHeader_Throw

        public void GetValues_GetValuesForNonExistingHeader_Throw()
        {
            MockHeaders headers = new MockHeaders();
            headers.Add("custom1", "customValue1");

            // Get header values for non-existing header (but other headers exist in the store).
            Assert.Throws<InvalidOperationException>(() => { headers.GetValues("doesntexist"); });
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:8,代码来源:HttpHeadersTest.cs

示例14: GetValues_GetValuesFromUninitializedHeaderStore_Throw

        public void GetValues_GetValuesFromUninitializedHeaderStore_Throw()
        {
            MockHeaders headers = new MockHeaders();

            // Get header values from uninitialized store (store collection is null). This will throw.
            Assert.Throws<InvalidOperationException>(() => { headers.GetValues("doesntexist"); });
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:7,代码来源:HttpHeadersTest.cs

示例15: GetValues_UseNullHeader_Throw

 public void GetValues_UseNullHeader_Throw()
 {
     MockHeaders headers = new MockHeaders();
     
     Assert.Throws<ArgumentException>(() => { headers.GetValues(null); });
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:6,代码来源:HttpHeadersTest.cs


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