|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
| 4 | +using System.Collections; |
| 5 | +using Microsoft.AspNetCore.InternalTesting.Tracing; |
4 | 6 | using Microsoft.Extensions.Primitives;
|
5 | 7 |
|
6 | 8 | namespace Microsoft.AspNetCore.Http;
|
@@ -132,4 +134,38 @@ public void ReturnsCorrectStringValuesEmptyForMissingHeaders(bool withStore)
|
132 | 134 | IDictionary<string, StringValues> asIDictionary = emptyHeaders;
|
133 | 135 | Assert.Throws<KeyNotFoundException>(() => asIDictionary["Header1"]);
|
134 | 136 | }
|
| 137 | + |
| 138 | + [Fact] |
| 139 | + public void EnumeratorResetsCorrectly() |
| 140 | + { |
| 141 | + var headers = new HeaderDictionary( |
| 142 | + new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase) |
| 143 | + { |
| 144 | + { "Header1", "Value1" }, |
| 145 | + { "Header2", "Value2" }, |
| 146 | + { "Header3", "Value3" } |
| 147 | + }); |
| 148 | + |
| 149 | + var enumerator = headers.GetEnumerator(); |
| 150 | + var initial = enumerator.Current; |
| 151 | + |
| 152 | + Assert.True(enumerator.MoveNext()); |
| 153 | + |
| 154 | + var first = enumerator.Current; |
| 155 | + var last = enumerator.Current; |
| 156 | + |
| 157 | + while (enumerator.MoveNext()) |
| 158 | + { |
| 159 | + last = enumerator.Current; |
| 160 | + } |
| 161 | + |
| 162 | + Assert.NotEqual(first, initial); |
| 163 | + Assert.NotEqual(first, last); |
| 164 | + |
| 165 | + ((IEnumerator)enumerator).Reset(); |
| 166 | + |
| 167 | + Assert.Equal(enumerator.Current, initial); |
| 168 | + Assert.True(enumerator.MoveNext()); |
| 169 | + Assert.Equal(enumerator.Current, first); |
| 170 | + } |
135 | 171 | }
|
0 commit comments