예제 #1
0
        public void TestDistinctExceptions()
        {
            List <ProductsList.Product> products = null;

            var distinctComparer = new ProductListComparer();

            var exception = Assert.Throws <ArgumentNullException>(() => LinqFunctions.Distinct(products, distinctComparer));

            Assert.Equal("source", exception.ParamName);
        }
예제 #2
0
        public void TestDistinct()
        {
            var products = new List <ProductsList.Product>()
            {
                new ProductsList.Product//default
                {
                    ID          = 2,
                    Name        = "Detergent",
                    Price       = 10,
                    Ingredients = new List <ProductsList.Ingredient> {
                        new ProductsList.Ingredient {
                            Name = "Lamaie"
                        }, new ProductsList.Ingredient {
                            Name = "Parfum1"
                        }
                    }
                },

                new ProductsList.Product//same as default
                {
                    ID          = 2,
                    Name        = "Detergent",
                    Price       = 10,
                    Ingredients = new List <ProductsList.Ingredient> {
                        new ProductsList.Ingredient {
                            Name = "Lamaie"
                        }, new ProductsList.Ingredient {
                            Name = "Parfum1"
                        }
                    }
                },

                new ProductsList.Product//totally different
                {
                    ID          = 6,
                    Name        = "Sampon",
                    Price       = 10,
                    Ingredients = new List <ProductsList.Ingredient> {
                        new ProductsList.Ingredient {
                            Name = "Menta"
                        }, new ProductsList.Ingredient {
                            Name = "Parfum3"
                        }
                    }
                },

                new ProductsList.Product//different price
                {
                    ID          = 2,
                    Name        = "Detergent",
                    Price       = 11,
                    Ingredients = new List <ProductsList.Ingredient> {
                        new ProductsList.Ingredient {
                            Name = "Lamaie"
                        }, new ProductsList.Ingredient {
                            Name = "Parfum1"
                        }
                    }
                },
            };

            var distinctEqualityComparer = new ProductListComparer();

            var result = LinqFunctions.Distinct(products, distinctEqualityComparer);

            Assert.Equal(3, result.Count());
        }