Skip to content

Commit ab17ee9

Browse files
committed
Adding initial tests.
1 parent dd4774f commit ab17ee9

File tree

2 files changed

+110
-7
lines changed

2 files changed

+110
-7
lines changed

src/OpenFeature/Model/FlagMetadata.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,10 @@ public FlagMetadata() : this([])
3030

3131
public double? GetDouble(string key)
3232
{
33-
return this.GetValue<int>(key);
34-
}
35-
36-
public decimal? GetDecimal(string key)
37-
{
38-
return this.GetValue<decimal>(key);
33+
return this.GetValue<double>(key);
3934
}
4035

41-
public T? GetValue<T>(string key) where T : struct
36+
private T? GetValue<T>(string key) where T : struct
4237
{
4338
var hasValue = this._metadata.TryGetValue(key, out var value);
4439
if (!hasValue)
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using System.Collections.Generic;
2+
using OpenFeature.Model;
3+
using Xunit;
4+
5+
namespace OpenFeature.Tests
6+
{
7+
public class FlagMetadataTest
8+
{
9+
[Fact]
10+
public void GetBool_Should_Return_Null_If_Key_Not_Found()
11+
{
12+
// Arrange
13+
var metadata = new Dictionary<string, object>();
14+
var flagMetadata = new FlagMetadata(metadata);
15+
16+
// Act
17+
var result = flagMetadata.GetBool("nonexistentKey");
18+
19+
// Assert
20+
Assert.Null(result);
21+
}
22+
23+
[Fact]
24+
public void GetBool_Should_Return_Value_If_Key_Found()
25+
{
26+
// Arrange
27+
var metadata = new Dictionary<string, object>
28+
{
29+
{ "boolKey", true }
30+
};
31+
var flagMetadata = new FlagMetadata(metadata);
32+
33+
// Act
34+
var result = flagMetadata.GetBool("boolKey");
35+
36+
// Assert
37+
Assert.True(result);
38+
}
39+
40+
[Fact]
41+
public void GetInt_Should_Return_Null_If_Key_Not_Found()
42+
{
43+
// Arrange
44+
var metadata = new Dictionary<string, object>();
45+
var flagMetadata = new FlagMetadata(metadata);
46+
47+
// Act
48+
var result = flagMetadata.GetInt("nonexistentKey");
49+
50+
// Assert
51+
Assert.Null(result);
52+
}
53+
54+
[Fact]
55+
public void GetInt_Should_Return_Value_If_Key_Found()
56+
{
57+
// Arrange
58+
var metadata = new Dictionary<string, object>
59+
{
60+
{
61+
"intKey", 1
62+
}
63+
};
64+
var flagMetadata = new FlagMetadata(metadata);
65+
66+
// Act
67+
var result = flagMetadata.GetInt("intKey");
68+
69+
// Assert
70+
Assert.NotNull(result);
71+
Assert.Equal(1, result);
72+
}
73+
74+
[Fact]
75+
public void GetDouble_Should_Return_Null_If_Key_Not_Found()
76+
{
77+
// Arrange
78+
var metadata = new Dictionary<string, object>();
79+
var flagMetadata = new FlagMetadata(metadata);
80+
81+
// Act
82+
var result = flagMetadata.GetDouble("nonexistentKey");
83+
84+
// Assert
85+
Assert.Null(result);
86+
}
87+
88+
[Fact]
89+
public void GetDouble_Should_Return_Value_If_Key_Found()
90+
{
91+
// Arrange
92+
var metadata = new Dictionary<string, object>
93+
{
94+
{
95+
"doubleKey", 1.2
96+
}
97+
};
98+
var flagMetadata = new FlagMetadata(metadata);
99+
100+
// Act
101+
var result = flagMetadata.GetDouble("doubleKey");
102+
103+
// Assert
104+
Assert.NotNull(result);
105+
Assert.Equal(1.2, result);
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)