示例#1
0
        public void Should_Filter_List_Correctly_2_products_have_Identical_Names()
        {
            //Given
            Feature firstFeature = new Feature {
                Id = 2
            };
            Feature secondFeature = new Feature {
                Id = 3
            };

            ProductType apples = new ProductType
            {
                Name     = "apples",
                Features = new List <Feature> {
                    firstFeature
                }
            };
            ProductType pears = new ProductType
            {
                Name     = "apples",
                Features = new List <Feature> {
                    secondFeature
                }
            };
            ProductType nuts = new ProductType
            {
                Name     = "nuts",
                Features = new List <Feature> {
                    new Feature {
                        Id = 4
                    }, secondFeature
                }
            };
            ProductType watermelons = new ProductType
            {
                Name     = "watermelons",
                Features = new List <Feature> {
                    new Feature {
                        Id = 4
                    }
                }
            };

            var productList = new List <ProductType> {
                apples, pears, nuts, watermelons
            };

            //When
            var filteringCriteria = new List <Feature> {
                new Feature {
                    Id = 5
                }, secondFeature
            };
            var filter       = new ListFilter(productList, filteringCriteria);
            var filteredList = filter.AnyFeatureFilter();

            //Then
            Assert.Equal(2, filteredList.Count());
            Assert.Equal(pears, filteredList.First());
        }
示例#2
0
        public void Should_Filter_List_For_More_Elements_And_More_Given_Features()
        {
            //Given
            Feature firstFeature = new Feature {
                Id = 2
            };
            Feature secondFeature = new Feature {
                Id = 3
            };

            ProductType apples = new ProductType
            {
                Name     = "apples",
                Features = new List <Feature> {
                    firstFeature
                }
            };
            ProductType pears = new ProductType
            {
                Name     = "pears",
                Features = new List <Feature> {
                    firstFeature
                }
            };
            ProductType nuts = new ProductType
            {
                Name     = "nuts",
                Features = new List <Feature> {
                    firstFeature, secondFeature
                }
            };
            ProductType watermelons = new ProductType
            {
                Name     = "watermelons",
                Features = new List <Feature> {
                    new Feature {
                        Id = 4
                    }
                }
            };

            var productList = new List <ProductType> {
                apples, pears, nuts, watermelons
            };

            //When
            var filteringCriteria = new List <Feature> {
                firstFeature, secondFeature
            };
            var filter       = new ListFilter(productList, filteringCriteria);
            var filteredList = filter.AnyFeatureFilter();

            //Then
            Assert.Equal(3, filteredList.Count());
        }
示例#3
0
        public void Test_AnyFeatureFilter()
        {
            ProductType prod1 = new ProductType
            {
                Name     = "prod1",
                Features = new List <Feature> {
                    new Feature {
                        Id = 1
                    }
                }
            };

            ProductType prod2 = new ProductType
            {
                Name     = "prod2",
                Features = new List <Feature> {
                    new Feature {
                        Id = 2
                    },
                    new Feature {
                        Id = 3
                    }
                }
            };

            ProductType prod3 = new ProductType
            {
                Name     = "prod3",
                Features = new List <Feature> {
                    new Feature {
                        Id = 4
                    },
                    new Feature {
                        Id = 1
                    }
                }
            };

            var productList = new List <ProductType> {
                prod1, prod2, prod3
            };

            var filteringCriteria = new List <Feature> {
                new Feature {
                    Id = 1
                }
            };
            var filter       = new ListFilter(productList, filteringCriteria);
            var filteredList = filter.AnyFeatureFilter();

            Assert.Equal(2, filteredList.Count());
            Assert.Equal(prod1, filteredList.First());
            Assert.Equal(prod3, filteredList.Last());
        }
示例#4
0
        public void Should_Filter_List_For_One_Element_And_One_Given_Feature()
        {
            //Given
            Feature askedFeature = new Feature {
                Id = 1
            };

            ProductType apples = new ProductType
            {
                Name     = "apples",
                Features = new List <Feature> {
                    askedFeature
                }
            };
            ProductType pears = new ProductType
            {
                Name     = "pears",
                Features = new List <Feature> {
                    new Feature {
                        Id = 2
                    }
                }
            };

            var productList = new List <ProductType> {
                apples, pears
            };

            //When
            var filteringCriteria = new List <Feature> {
                askedFeature
            };
            var filter       = new ListFilter(productList, filteringCriteria);
            var filteredList = filter.AnyFeatureFilter();

            //Then
            Assert.Single(filteredList);
        }