Skip to content

Commit a1a11dc

Browse files
feat: Add public Count property on ImmutableMetadata (#715)
* Add public Count property on ImmutableMetadata Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com> * Address code review comment Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com> --------- Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
1 parent c07b173 commit a1a11dc

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/OpenFeature/Model/ImmutableMetadata.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public sealed class ImmutableMetadata
1919
/// </value>
2020
public bool IsEmpty => this._metadata.Count == 0;
2121

22+
/// <summary>
23+
/// Gets the number of elements in this collection.
24+
/// </summary>
25+
public int Count => this._metadata.Count;
26+
2227
/// <summary>
2328
/// Constructor for the <see cref="ImmutableMetadata"/> class.
2429
/// </summary>
@@ -104,6 +109,4 @@ public ImmutableMetadata(Dictionary<string, object> metadata)
104109

105110
return value is T tValue ? tValue : null;
106111
}
107-
108-
internal int Count => this._metadata.Count;
109112
}

test/OpenFeature.Tests/ImmutableMetadataTest.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public void IsEmpty_ShouldReturnFalse()
334334
{
335335
// Arrange
336336
var metadata = new Dictionary<string, object>
337-
{
337+
{
338338
{
339339
"wrongKey", new object()
340340
},
@@ -359,4 +359,21 @@ public void IsEmpty_ShouldReturnFalse()
359359
// Assert
360360
Assert.False(result);
361361
}
362+
363+
[Theory]
364+
[InlineData(0)]
365+
[InlineData(1)]
366+
[InlineData(1000)]
367+
public void Count_ShouldReturnCorrectNumber(int numberOfItems)
368+
{
369+
var metadata = Enumerable.Range(0, numberOfItems)
370+
.ToDictionary(i => $"key{i}", i => (object)$"value{i}");
371+
var flagMetadata = new ImmutableMetadata(metadata);
372+
373+
// Act
374+
var count = flagMetadata.Count;
375+
376+
// Assert
377+
Assert.Equal(numberOfItems, count);
378+
}
362379
}

0 commit comments

Comments
 (0)