Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 6d93e0e

Browse files
committed
Merge pull request #2408 from pgavlin/SNWebHeaderCollection
Fix WebHeaderCollection.GetEnumerator().
2 parents 07f8c0f + d6bd148 commit 6d93e0e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/System.Net.WebHeaderCollection/src/System/Net/WebHeaderCollection.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,11 @@ public override string[] AllKeys
589589
}
590590

591591
IEnumerator IEnumerable.GetEnumerator()
592+
{
593+
return GetEnumerator();
594+
}
595+
596+
public override IEnumerator GetEnumerator()
592597
{
593598
return InnerCollection.Keys.GetEnumerator();
594599
}

src/System.Net.WebHeaderCollection/tests/WebHeaderCollectionTest.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,5 +250,38 @@ public void ToString_Success()
250250
"Accept: text/plain\r\nContent-Length: 123\r\n\r\n",
251251
w.ToString());
252252
}
253+
254+
[Fact]
255+
public void IterateCollection_Success()
256+
{
257+
WebHeaderCollection w = new WebHeaderCollection();
258+
w["Accept"] = "text/plain";
259+
w["Content-Length"] = "123";
260+
261+
string result = "";
262+
foreach (var item in w)
263+
{
264+
result += item;
265+
}
266+
267+
Assert.Equal("AcceptContent-Length", result);
268+
}
269+
270+
[Fact]
271+
public void IterateIEnumerable_Success()
272+
{
273+
WebHeaderCollection w = new WebHeaderCollection();
274+
w["Accept"] = "text/plain";
275+
w["Content-Length"] = "123";
276+
277+
string result = "";
278+
foreach (var item in (System.Collections.IEnumerable)w)
279+
{
280+
result += item;
281+
}
282+
283+
Assert.Equal("AcceptContent-Length", result);
284+
}
285+
253286
}
254287
}

0 commit comments

Comments
 (0)