Skip to content

Commit c3f6b51

Browse files
committed
Chore: Evaluation Context must only contain unique values
open-feature/spec#120 Signed-off-by: Benjamin Evenson <[email protected]>
1 parent 0146a5e commit c3f6b51

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test/OpenFeature.Tests/OpenFeatureEvaluationContextTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public void Should_Merge_Two_Contexts()
2727
}
2828

2929
[Fact]
30+
[Specification("3.2.2", "Duplicate values being overwritten.")]
3031
public void Should_Merge_TwoContexts_And_Override_Duplicates_With_RightHand_Context()
3132
{
3233
var context1 = new EvaluationContext();
@@ -77,5 +78,15 @@ public void EvaluationContext_Should_All_Types()
7778
context.Get<DateTime>("key4").Should().Be(now);
7879
context.Get<TestStructure>("key5").Should().Be(structure);
7980
}
81+
82+
[Fact]
83+
[Specification("3.1.4", "The evaluation context fields MUST have an unique key.")]
84+
public void When_Duplicate_Key_Throw_Unique_Constraint()
85+
{
86+
var context = new EvaluationContext { { "key", "value" } };
87+
var exception = Assert.Throws<ArgumentException>(() =>
88+
context.Add("key", "overriden_value"));
89+
exception.Message.Should().Be("An item with the same key has already been added. Key: key");
90+
}
8091
}
8192
}

0 commit comments

Comments
 (0)