Example #1
0
        public void ByParent_Should_Throw_ArgumentNullException_If_Categories_Is_Null()
        {
            IQueryable<Category> categories = null;
            Guid parentId = Guid.NewGuid();

            var ex = Assert.Throws<ArgumentNullException>(() => CategoryExtensions.ByParent(categories, parentId));
            Assert.Equal(nameof(categories), ex.ParamName);
        }
Example #2
0
        public void ByParent_Should_Throw_ArgumentException_If_ParentId_Is_Empty()
        {
            var c1 = Category.Create("c1", "c1", "c1");
            var c2 = Category.Create("c2", "c2", "c2");
            var c3 = Category.Create("c3", "c3", "c3");

            IQueryable<Category> categories = new Category[]
            {
                c1, c2, c3
            }.AsQueryable();
            Guid parentId = Guid.Empty;

            var ex = Assert.Throws<ArgumentException>(() => CategoryExtensions.ByParent(categories, parentId));
            Assert.Equal(nameof(parentId), ex.ParamName);
        }
Example #3
0
        public void ByParent_Should_Return_Only_Categories_With_The_Specified_Parent()
        {
            var c1 = Category.Create("c1", "c1", "c1");
            var c2 = Category.Create("c2", "c2", "c2");
            var c3 = Category.Create("c3", "c3", "c3");

            c2.SetParentCategory(c3);

            IQueryable<Category> categories = new Category[]
            {
                c1, c2
            }.AsQueryable();
            Guid parentId = c3.Id;

            var categoriesWithParent = CategoryExtensions.ByParent(categories, parentId).ToArray();

            Assert.True(categoriesWithParent.All(c => c.Parent.Id == parentId));
        }