From 291455429faa3ef714420ced0ffc1ec44da507de Mon Sep 17 00:00:00 2001 From: Benjamin Evenson <2031163+benjiro@users.noreply.github.com> Date: Thu, 4 Aug 2022 23:27:44 +1000 Subject: [PATCH] Chore: Evaluation Context must only contain unique values https://github.com/open-feature/spec/pull/120 Signed-off-by: Benjamin Evenson <2031163+benjiro@users.noreply.github.com> --- .../OpenFeatureEvaluationContextTests.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/OpenFeature.Tests/OpenFeatureEvaluationContextTests.cs b/test/OpenFeature.Tests/OpenFeatureEvaluationContextTests.cs index 82dc034b..5973aa09 100644 --- a/test/OpenFeature.Tests/OpenFeatureEvaluationContextTests.cs +++ b/test/OpenFeature.Tests/OpenFeatureEvaluationContextTests.cs @@ -27,6 +27,7 @@ public void Should_Merge_Two_Contexts() } [Fact] + [Specification("3.2.2", "Duplicate values being overwritten.")] public void Should_Merge_TwoContexts_And_Override_Duplicates_With_RightHand_Context() { var context1 = new EvaluationContext(); @@ -77,5 +78,15 @@ public void EvaluationContext_Should_All_Types() context.Get("key4").Should().Be(now); context.Get("key5").Should().Be(structure); } + + [Fact] + [Specification("3.1.4", "The evaluation context fields MUST have an unique key.")] + public void When_Duplicate_Key_Throw_Unique_Constraint() + { + var context = new EvaluationContext { { "key", "value" } }; + var exception = Assert.Throws(() => + context.Add("key", "overriden_value")); + exception.Message.Should().StartWith("An item with the same key has already been added."); + } } }