public void RulesThatCheckContextValue() { var identity = new Identity("device", "1"); var context = CreateContext(identity, new Tuple <string, JsonValue>("PartnerBrand", JsonValue.NewString("ABC"))); var rulesRepo = RulesRepositoryHelpers .With("path/to/key", FakeRule.Create(ctx => ctx("device.PartnerBrand") == JsonValue.NewString("ABC") ? new ConfigurationValue(JsonValue.NewString("SomeValue")) : Option <ConfigurationValue> .None)); var value = EngineCore.GetRulesEvaluator(new HashSet <Identity> { identity }, context, rulesRepo)("path/to/key").Map(x => x.Value); Assert.Equal(JsonValue.NewString("SomeValue"), value); rulesRepo = rulesRepo .With("path/to/other/key", FakeRule.Create(ctx => ctx("device.OtherProp") == JsonValue.NewString("DEF") ? new ConfigurationValue(JsonValue.NewString("SomeValue")) : Option <ConfigurationValue> .None)); value = EngineCore.GetRulesEvaluator(new HashSet <Identity> { identity }, context, rulesRepo)("path/to/other/key").Map(x => x.Value); Assert.True(value.IsNone); rulesRepo = rulesRepo .With("path/to/other/key", FakeRule.Create(ctx => ctx("device.PartnerBrand") == JsonValue.NewString("ABC") ? new ConfigurationValue(JsonValue.NewString("SomeValue")) : Option <ConfigurationValue> .None)); value = EngineCore.GetRulesEvaluator(new HashSet <Identity> { identity }, context, rulesRepo)("path/to/other/key").Map(x => x.Value); Assert.Equal(JsonValue.NewString("SomeValue"), value); }
public void PathWithNoMatchingRule() { var identity = new Identity("device", "1"); var context = CreateContext(identity); var rulesRepo = RulesRepositoryHelpers.With("path/to/key", FakeRule.Create(ctx => new ConfigurationValue(JsonValue.NewString("SomeValue")))); var missingValue = EngineCore.GetRulesEvaluator(new HashSet <Identity> { identity }, context, rulesRepo)("path/to/key2"); Assert.True(missingValue.IsNone); }
public void ExternalPathRefernceInContext() { var identity = new Identity("device", "1"); var context = CreateContext(identity); var rulesRepo = RulesRepositoryHelpers.With("path/to/key2", FakeRule.Create(ctx => new ConfigurationValue(JsonValue.NewString("SomeValue")))) .With("path/to/key", FakeRule.Create(ctx => ctx("@@key:path/to/key2").Map(x => new ConfigurationValue(x)))); var value = EngineCore.GetRulesEvaluator(new HashSet <Identity> { identity }, context, rulesRepo)("path/to/key").Map(x => x.Value); Assert.Equal(JsonValue.NewString("SomeValue"), value); }
public void PathWithSimpleRule() { var identity = new Identity("device", "1"); var identities = new HashSet <Identity> { identity }; var context = CreateContext(identity); var rulesRepo = RulesRepositoryHelpers.With("path/to/key", FakeRule.Create(ctx => new ConfigurationValue(JsonValue.NewString("SomeValue")))); var value = EngineCore.GetRulesEvaluator(identities, context, rulesRepo)("path/to/key").Map(x => x.Value); Assert.Equal(JsonValue.NewString("SomeValue"), value); }