Skip to content

Commit 2768d4c

Browse files
authored
Merge pull request #55 from open-feature/client-setcontext
undefined
2 parents 01c0f34 + acce643 commit 2768d4c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/OpenFeature.SDK/OpenFeatureClient.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@ public sealed class FeatureClient : IFeatureClient
2020
private readonly FeatureProvider _featureProvider;
2121
private readonly List<Hook> _hooks = new List<Hook>();
2222
private readonly ILogger _logger;
23-
private readonly EvaluationContext _evaluationContext;
23+
private EvaluationContext _evaluationContext;
2424

2525
/// <summary>
26-
/// Gets the client <see cref="EvaluationContext"/>
26+
/// Gets the EvaluationContext of this client<see cref="EvaluationContext"/>
2727
/// </summary>
28-
/// <returns></returns>
28+
/// <returns><see cref="EvaluationContext"/>of this client</returns>
2929
public EvaluationContext GetContext() => this._evaluationContext;
3030

31+
/// <summary>
32+
/// Sets the EvaluationContext of the client<see cref="EvaluationContext"/>
33+
/// </summary>
34+
public void SetContext(EvaluationContext evaluationContext) => this._evaluationContext = evaluationContext;
35+
3136
/// <summary>
3237
/// Initializes a new instance of the <see cref="FeatureClient"/> class.
3338
/// </summary>

test/OpenFeature.SDK.Tests/OpenFeatureClientTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,5 +354,15 @@ public void Should_Throw_ArgumentNullException_When_Provider_Is_Null()
354354
TestProvider provider = null;
355355
Assert.Throws<ArgumentNullException>(() => new FeatureClient(provider, "test", "test"));
356356
}
357+
358+
[Fact]
359+
public void Should_Get_And_Set_Context()
360+
{
361+
var KEY = "key";
362+
var VAL = 1;
363+
FeatureClient client = OpenFeature.Instance.GetClient();
364+
client.SetContext(new EvaluationContext().Add(KEY, VAL));
365+
Assert.Equal(VAL, client.GetContext().GetValue(KEY).AsInteger());
366+
}
357367
}
358368
}

0 commit comments

Comments
 (0)