Skip to content

Commit

Permalink
add test for EvaluationContext using
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Petrusevici <[email protected]>
  • Loading branch information
vpetrusevici committed Oct 18, 2023
1 parent 5224c39 commit a2a0dc4
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OpenFeature.Model;
using System.Linq;
using OpenFeature.Error;
using System.Collections.Generic;

namespace OpenFeature.Contrib.Providers.Flagsmith.Test
{
Expand All @@ -22,7 +23,8 @@ public class UnitTestFlagsmithProvider
EnableAnalytics = false,
Retries = 1
};
[Fact]

[Fact]
public void CreateFlagmithProvider_WithValidCredetials_CreatesInstanceSuccessfully()
{
// Arrange
Expand Down Expand Up @@ -50,6 +52,36 @@ public void CreateFlagmithProvider_WithValidCredetialsAndCustomHttpClient_Create
Assert.NotNull(flagsmithProvider._flagsmithClient);
}

[Fact]
public async Task GetValue_ForEnabledFeatureWithEvaluationContext_ReturnCorrectValue()
{
// Arrange
var flagsmithClient = Substitute.For<IFlagsmithClient>();
var flags = Substitute.For<IFlags>();
var date = DateTime.Now;
flags.GetFeatureValue("example-feature").Returns("true");
flags.IsFeatureEnabled("example-feature").Returns(true);
flagsmithClient.GetIdentityFlags("233", Arg.Is<List<ITrait>>(x => x.Count == 7 && x[3].GetTraitKey() == "key4")).Returns(flags);
var flagsmithProvider = new FlagsmithProvider(flagsmithClient);

var contextBuilder = ((EvaluationContextBuilder)Activator.CreateInstance(typeof(EvaluationContextBuilder), true))
.Set("key1", "value")
.Set("key2", 1)
.Set("key3", true)
.Set("key4", date)
.Set("key5", Structure.Empty)
.Set("key6", 1.0)
.Set("targetingKey", "233");
// Act
var result = await flagsmithProvider.ResolveBooleanValue("example-feature", false, contextBuilder.Build());

// Assert
Assert.True(result.Value);
Assert.Equal("example-feature", result.FlagKey);
Assert.Null(result.Reason);
Assert.Equal(ErrorType.None, result.ErrorType);
}

[Fact]
public async Task GetBooleanValue_ForEnabledFeatureWithValidFormat_ReturnCorrectValue()
{
Expand Down

0 comments on commit a2a0dc4

Please sign in to comment.