コード例 #1
0
        public void Filter_WhenSeveralNegateValuesFromDiffrentSubject_GetRelevantValue()
        {
            // The uniquness of the context is A+B, I would like to filter both of them and only one
            var context = new Dictionary<string, string>
                              {
                                  {"A", "1"},
                                  {"B", "3"},
                              };

            var items = new[]
                            {
                                new Item(1,new TextMatchCondition("A","1",true),new TextMatchCondition("B","2",true))
                            };

            var evaluationResult = new FilterConditionsEvaluator().Evaluate(context, items);
            var result = new BestMatchFilterPolicy().Filter(evaluationResult).Select(x => x.Item).OfType<Item>();

            CollectionAssert.IsNotEmpty(result.ToList());
        }
コード例 #2
0
ファイル: ContextWithTwoItems.cs プロジェクト: nvaron/NConfig
        public void SelectSingleItemWhenOneItemHasOneSpecificReferenceAndTheOtherHasTwoSpecificReferences()
        {
            var context = new Dictionary<string, string>
                              {
                                  {"A", "2"},
                                  {"B", "2"},
                              };

            var items = new[]
                            {
                                new Item(1,new TextMatchCondition("A","2")),
                                new Item(2,new TextMatchCondition("B","2"),new TextMatchCondition("A","2")),
                            };

            var evaluationResult = new FilterConditionsEvaluator().Evaluate(context, items);
            var result = new BestMatchFilterPolicy().Filter(evaluationResult).Select(x => x.Item).OfType<Item>();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.Any(x => x.Id == 2));
        }
コード例 #3
0
ファイル: ContextWithOneItem.cs プロジェクト: nvaron/NConfig
        public void SelectSingleItemWhenOneMatchIsNegatedAndTheOtherWithoutAReference()
        {
            var context = new Dictionary<string, string>
                              {
                                  {"A", "2"},
                              };

            var items = new[]
                            {
                                new Item(1,new TextMatchCondition("A","1")),
                                new Item(2,new TextMatchCondition("A","2",true)),
                                new Item(3),
                                new Item(4,new TextMatchCondition("A","1")),
                            };

            var evaluationResult = new FilterConditionsEvaluator().Evaluate(context, items);
            var result = new BestMatchFilterPolicy().Filter(evaluationResult).Select(x => x.Item).OfType<Item>();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.Any(x => x.Id == 3));
        }
コード例 #4
0
ファイル: ContextWithTwoItems.cs プロジェクト: nvaron/NConfig
        public void when_two_negated_conditions_evaluates_to_true_select_them_over_the_default()
        {
            var context = new Dictionary<string, string>
                {
                    {"B", "2"},
                };

            var items = new[]
                {
                    new Item(1, new TextMatchCondition("B", "5")),

                    new Item(2, new TextMatchCondition("B", "3",true), new TextMatchCondition("B", "4",true)),
                };

            var evaluationResult = new FilterConditionsEvaluator().Evaluate(context, items);
            var result = new BestMatchFilterPolicy().Filter(evaluationResult).Select(x => x.Item).OfType<Item>();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.Any(x => x.Id == 2));
        }
コード例 #5
0
ファイル: ContextWithTwoItems.cs プロジェクト: nvaron/NConfig
        public void when_an_Item_has_no_references_prefer_it_over_other_items_with_nutral_references()
        {
            var context = new Dictionary<string, string>
                {
                    {"B", "3"},
                };

            var items = new[]
                {
                    new Item(1),

                    new Item(2, new TextMatchCondition("A", "3",true)),
                    new Item(2, new TextMatchCondition("A", "5")),
                };

            var evaluationResult = new FilterConditionsEvaluator().Evaluate(context, items);
            var result = new BestMatchFilterPolicy().Filter(evaluationResult).Select(x => x.Item).OfType<Item>();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.Any(x => x.Id == 1));
        }
コード例 #6
0
ファイル: ContextWithTwoItems.cs プロジェクト: nvaron/NConfig
        public void SelectSingleWhenValueHasTwoReferencesToSameSubjectAndOnlyOneMatch2()
        {
            var context = new Dictionary<string, string>
                {
                    {"B", "3"},
                };

            var items = new[]
                {
                    new Item(1),

                    new Item(2, new TextMatchCondition("B", "3",true), new TextMatchCondition("B", "4",true)),
                };

            var evaluationResult = new FilterConditionsEvaluator().Evaluate(context, items);
            var result = new BestMatchFilterPolicy().Filter(evaluationResult).Select(x => x.Item).OfType<Item>();

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.Any(x => x.Id == 1));
        }