Esempio n. 1
0
        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 IdentityHashSet {
                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 IdentityHashSet {
                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 IdentityHashSet {
                identity
            }, context, rulesRepo)("path/to/other/key").Map(x => x.Value);

            Assert.Equal(JsonValue.NewString("SomeValue"), value);
        }
Esempio n. 2
0
        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 IdentityHashSet {
                identity
            }, context, rulesRepo)("path/to/key2");

            Assert.True(missingValue.IsNone);
        }
Esempio n. 3
0
        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 IdentityHashSet {
                identity
            }, context, rulesRepo)("path/to/key").Map(x => x.Value);

            Assert.Equal(JsonValue.NewString("SomeValue"), value);
        }
Esempio n. 4
0
        public void PathWithSimpleRule()
        {
            var identity   = new Identity("device", "1");
            var identities = new IdentityHashSet {
                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);
        }