本文整理汇总了C#中HttpHeaders.Count方法的典型用法代码示例。如果您正苦于以下问题:C# HttpHeaders.Count方法的具体用法?C# HttpHeaders.Count怎么用?C# HttpHeaders.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders.Count方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AreEqual
/// <summary>
/// Asserts that the expected <see cref="HttpHeaders"/> instance is equal to the actual <see cref="actualHeaders"/> instance.
/// </summary>
/// <param name="expectedHeaders">The expected <see cref="HttpHeaders"/> instance. Should not be <c>null</c>.</param>
/// <param name="actualHeaders">The actual <see cref="HttpHeaders"/> instance. Should not be <c>null</c>.</param>
public static void AreEqual(HttpHeaders expectedHeaders, HttpHeaders actualHeaders)
{
Assert.IsNotNull(expectedHeaders, "The 'expectedHeaders' parameter should not be null.");
Assert.IsNotNull(actualHeaders, "The 'actualHeaders' parameter should not be null.");
Assert.AreEqual(expectedHeaders.Count(), actualHeaders.Count(), "The number of headers should have been the same.");
foreach (KeyValuePair<string, IEnumerable<string>> expectedHeader in expectedHeaders)
{
KeyValuePair<string, IEnumerable<string>> actualHeader = actualHeaders.FirstOrDefault(h => h.Key == expectedHeader.Key);
Assert.IsNotNull(actualHeader, string.Format("The '{0}' header was expected but not found.", expectedHeader.Key));
if (expectedHeader.Key == "Date")
{
HandleDateHeader(expectedHeader.Value.ToArray(), actualHeader.Value.ToArray());
}
else
{
string expectedHeaderStr = string.Join(CommaSeperator, expectedHeader.Value);
string actualHeaderStr = string.Join(CommaSeperator, actualHeader.Value);
Assert.AreEqual(expectedHeaderStr, actualHeaderStr, string.Format("The '{0}' header disagreed with the expected header value.", expectedHeader.Key));
}
}
}
示例2: Equal
/// <summary>
/// Asserts that the expected <see cref="HttpHeaders"/> instance is equal to the actual <see cref="actualHeaders"/> instance.
/// </summary>
/// <param name="expectedHeaders">The expected <see cref="HttpHeaders"/> instance. Should not be <c>null</c>.</param>
/// <param name="actualHeaders">The actual <see cref="HttpHeaders"/> instance. Should not be <c>null</c>.</param>
public void Equal(HttpHeaders expectedHeaders, HttpHeaders actualHeaders)
{
Assert.NotNull(expectedHeaders);
Assert.NotNull(actualHeaders);
Assert.Equal(expectedHeaders.Count(), actualHeaders.Count());
foreach (KeyValuePair<string, IEnumerable<string>> expectedHeader in expectedHeaders)
{
KeyValuePair<string, IEnumerable<string>> actualHeader = actualHeaders.FirstOrDefault(h => h.Key == expectedHeader.Key);
Assert.NotNull(actualHeader);
if (expectedHeader.Key == "Date")
{
HandleDateHeader(expectedHeader.Value.ToArray(), actualHeader.Value.ToArray());
}
else
{
string expectedHeaderStr = string.Join(CommaSeperator, expectedHeader.Value);
string actualHeaderStr = string.Join(CommaSeperator, actualHeader.Value);
Assert.Equal(expectedHeaderStr, actualHeaderStr);
}
}
}
示例3: HttpHeadersAddTest
public void HttpHeadersAddTest()
{
var HttpHeaders = new HttpHeaders();
Assert.AreEqual("[]", HttpHeaders.AsEnumerable<HttpHeader>().ToJsonString());
HttpHeaders.Add("Content-Type", "text/html");
HttpHeaders.Set("Content-Type", "text/plain");
HttpHeaders.Set("cOntEnt-type", "text/plain");
Assert.AreEqual(1, HttpHeaders.Count());
Assert.AreEqual("cOntEnt-type: text/plain", String.Join("|", HttpHeaders.AsEnumerable()));
}