|
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 Microsoft.AspNetCore.InternalTesting.Tracing; |
4 | 5 | using Microsoft.Extensions.Primitives;
|
5 | 6 |
|
6 | 7 | namespace Microsoft.AspNetCore.Http;
|
@@ -132,4 +133,38 @@ public void ReturnsCorrectStringValuesEmptyForMissingHeaders(bool withStore)
|
132 | 133 | IDictionary<string, StringValues> asIDictionary = emptyHeaders;
|
133 | 134 | Assert.Throws<KeyNotFoundException>(() => asIDictionary["Header1"]);
|
134 | 135 | }
|
| 136 | + |
| 137 | + [Theory] |
| 138 | + public void EnumeratorResetsCorrectly() |
| 139 | + { |
| 140 | + var headers = new HeaderDictionary( |
| 141 | + new Dictionary<string, StringValues>(StringComparer.OrdinalIgnoreCase) |
| 142 | + { |
| 143 | + { "Header1", "Value1" }, |
| 144 | + { "Header2", "Value2" }, |
| 145 | + { "Header3", "Value3" } |
| 146 | + }); |
| 147 | + |
| 148 | + var enumerator = headers.GetEnumerator(); |
| 149 | + var initial = enumerator.Current; |
| 150 | + |
| 151 | + Assert.True(enumerator.MoveNext()); |
| 152 | + |
| 153 | + var first = enumerator.Current; |
| 154 | + var last = enumerator.Current; |
| 155 | + |
| 156 | + while (enumerator.MoveNext()) |
| 157 | + { |
| 158 | + last = enumerator.Current; |
| 159 | + } |
| 160 | + |
| 161 | + Assert.NotEqual(first, initial); |
| 162 | + Assert.NotEqual(first, last); |
| 163 | + |
| 164 | + ((IEnumerator)enumerator).Reset(); |
| 165 | + |
| 166 | + Assert.Equal(enumerator.Current, initial); |
| 167 | + Assert.True(enumerator.MoveNext()); |
| 168 | + Assert.Equal(enumerator.Current, first); |
| 169 | + } |
135 | 170 | }
|
0 commit comments