Example #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);
        }
Example #2
0
        public void TestExceptExceptions()
        {
            var products1 = new ProductsList().GetProducts();

            List <ProductsList.Product> products2 = null;

            var distinctComparer = new ProductListComparer();

            var exception = Assert.Throws <ArgumentNullException>(() => LinqFunctions.Except(products1, products2, distinctComparer));

            Assert.Equal("source", exception.ParamName);
        }
Example #3
0
        public void TestExcept()
        {
            var products1 = new List <ProductsList.Product>()
            {
                new ProductsList.Product//default
                {
                    ID          = 2,
                    Name        = "Dero",
                    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        = "Dero",
                    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 products2 = new ProductsList().GetProducts();

            var comparer = new ProductListComparer();

            var intersect = LinqFunctions.Except(products1, products2, comparer);

            Assert.Equal(2, intersect.Count());
        }
Example #4
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());
        }