Skip to content

Commit d2577cd

Browse files
committed
Add a couple of tests for fromdictionary
1 parent 780955a commit d2577cd

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/Components/src/Microsoft.AspNetCore.Components/ParameterCollection.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ internal void CaptureSnapshot(ArrayBuilder<RenderTreeFrame> builder)
199199
}
200200

201201
/// <summary>
202-
///
202+
/// Creates a new <see cref="ParameterCollection"/> from the given <see cref="IDictionary{TKey, TValue}"/>.
203203
/// </summary>
204-
/// <param name="parameters"></param>
205-
/// <returns></returns>
204+
/// <param name="parameters">The <see cref="IDictionary{TKey, TValue}"/> with the parameters.</param>
205+
/// <returns>A <see cref="ParameterCollection"/>.</returns>
206206
public static ParameterCollection FromDictionary(Dictionary<string, object> parameters)
207207
{
208208
var frames = new RenderTreeFrame[parameters.Count + 1];

src/Components/test/Microsoft.AspNetCore.Components.Test/ParameterCollectionTest.cs

+33-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using Microsoft.AspNetCore.Components;
5-
using Microsoft.AspNetCore.Components.Rendering;
6-
using Microsoft.AspNetCore.Components.RenderTree;
74
using System;
85
using System.Collections.Generic;
96
using System.Threading.Tasks;
7+
using Microsoft.AspNetCore.Components.Rendering;
8+
using Microsoft.AspNetCore.Components.RenderTree;
109
using Xunit;
1110

1211
namespace Microsoft.AspNetCore.Components.Test
@@ -240,6 +239,37 @@ public void ThrowsIfTryGetExistingValueWithIncorrectType()
240239
});
241240
}
242241

242+
[Fact]
243+
public void FromDictionary_CanBeInitializedWithEmptyDictionary()
244+
{
245+
// Arrange
246+
var dictionary = new Dictionary<string, object>();
247+
248+
// Act
249+
var collection = ParameterCollection.FromDictionary(dictionary);
250+
251+
// Assert
252+
Assert.Empty(collection.ToDictionary());
253+
}
254+
255+
[Fact]
256+
public void FromDictionary_RoundTrips()
257+
{
258+
// Arrange
259+
var dictionary = new Dictionary<string, object>
260+
{
261+
["IntValue"] = 1,
262+
["StringValue"] = "String"
263+
};
264+
265+
// Act
266+
var collection = ParameterCollection.FromDictionary(dictionary);
267+
268+
// Assert
269+
Assert.Equal(dictionary, collection.ToDictionary());
270+
}
271+
272+
243273
[Fact]
244274
public void CanConvertToReadOnlyDictionary()
245275
{

0 commit comments

Comments
 (0)