-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added IReadOnlyDictionary to HttpRequestOptions (#86983)
* Added IReadOnlyDictionary to HttpRequestOptions Closes #68149 * Added test for new methods * Added negative scenario to HttpRequestOptionsTest Co-authored-by: Stephen Toub <[email protected]> --------- Co-authored-by: Stephen Toub <[email protected]>
- Loading branch information
1 parent
eccc410
commit 19a088e
Showing
4 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpRequestOptionsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace System.Net.Http.Tests | ||
{ | ||
public class HttpRequestOptionsTest | ||
{ | ||
[Fact] | ||
public void HttpRequestOptionsIReadOnlyDictionaryMethods_Should_WorkSameAsIDictionary() | ||
{ | ||
const string ExpectedKey = "WebAssemblyEnableStreamingResponse"; | ||
const bool ExpectedValue = true; | ||
const string UnexpectedKey = "hello"; | ||
|
||
var requestOptions = new HttpRequestOptions(); | ||
requestOptions.Set(new HttpRequestOptionsKey<bool>(ExpectedKey), ExpectedValue); | ||
|
||
IReadOnlyDictionary<string, object?> readOnlyDictionary = requestOptions; | ||
IDictionary<string, object?> dictionary = requestOptions; | ||
|
||
Assert.Equal(1, readOnlyDictionary.Count); | ||
Assert.Equal(1, dictionary.Count); | ||
|
||
Assert.True(readOnlyDictionary.ContainsKey(ExpectedKey)); | ||
Assert.True(dictionary.ContainsKey(ExpectedKey)); | ||
Assert.False(readOnlyDictionary.ContainsKey(UnexpectedKey)); | ||
Assert.False(dictionary.ContainsKey(UnexpectedKey)); | ||
|
||
Assert.True(readOnlyDictionary.TryGetValue(ExpectedKey, out object? getValueFromReadOnlyDictionary)); | ||
Assert.True(dictionary.TryGetValue(ExpectedKey, out object? getValueFromDictionary)); | ||
Assert.Equal(ExpectedValue, getValueFromReadOnlyDictionary); | ||
Assert.Equal(ExpectedValue, getValueFromDictionary); | ||
|
||
Assert.Equal(ExpectedValue, readOnlyDictionary[ExpectedKey]); | ||
Assert.Equal(ExpectedValue, dictionary[ExpectedKey]); | ||
Assert.Throws<KeyNotFoundException>(() => readOnlyDictionary[UnexpectedKey]); | ||
Assert.Throws<KeyNotFoundException>(() => dictionary[UnexpectedKey]); | ||
|
||
Assert.Collection(readOnlyDictionary.Keys, item => Assert.Equal(ExpectedKey, item)); | ||
Assert.Collection(dictionary.Keys, item => Assert.Equal(ExpectedKey, item)); | ||
|
||
Assert.Collection(readOnlyDictionary.Values, item => Assert.Equal(ExpectedValue, item)); | ||
Assert.Collection(dictionary.Values, item => Assert.Equal(ExpectedValue, item)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters