public void DeleteChildCategoryWithProductsShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteChildCategory_ChildCategories_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var parentCategoryName = "Computers";

            dbContext.ParentCategories.Add(new ParentCategory {
                Name = parentCategoryName
            });
            dbContext.SaveChanges();

            var parentCategory = dbContext.ParentCategories.FirstOrDefault(x => x.Name == parentCategoryName);

            var childCategoriesService = new ChildCategoriesService(dbContext);

            var childCategoryName        = "Cables";
            var childCategoryDescription = "USB";
            var childCategory            = childCategoriesService.CreateChildCategory(childCategoryName, childCategoryDescription, parentCategory.Id);

            childCategory.Products = new List <Product> {
                new Product {
                    Name = "Headsets"
                }
            };
            dbContext.SaveChanges();

            var isChildCategoryDeleted = childCategoriesService.DeleteChildCategory(childCategory.Id);

            Assert.False(isChildCategoryDeleted);
            Assert.Equal(1, dbContext.ChildCategories.Count());
        }
        public void DeleteChildCategoryShouldReturnTrueAndDeleteChildCategory()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteChildCategoryCorrect_ChildCategories_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var parentCategoryName = "Computers";

            dbContext.ParentCategories.Add(new ParentCategory {
                Name = parentCategoryName
            });
            dbContext.SaveChanges();

            var parentCategory = dbContext.ParentCategories.FirstOrDefault(x => x.Name == parentCategoryName);

            var childCategoriesService = new ChildCategoriesService(dbContext);

            var childCategoryName        = "Cables";
            var childCategoryDescription = "USB";
            var childCategory            = childCategoriesService.CreateChildCategory(childCategoryName, childCategoryDescription, parentCategory.Id);

            var isChildCategoryDeleted = childCategoriesService.DeleteChildCategory(childCategory.Id);

            Assert.Equal(0, dbContext.ChildCategories.Count());
            Assert.True(isChildCategoryDeleted);
        }
        public void DeleteChildCategoryWithInvalidChildCategoryIdShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteChildCategory_ChildCategories_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var childCategoriesService = new ChildCategoriesService(dbContext);

            var invalidChildCategory   = 132;
            var isChildCategoryDeleted = childCategoriesService.DeleteChildCategory(invalidChildCategory);

            Assert.False(isChildCategoryDeleted);
        }