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

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

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

            var childCategoriesService = new ChildCategoriesService(dbContext);

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

            var isImageUrlCreated = childCategoriesService.AddImageUrl(childCategory.Id);

            var childCategoryExpectedImageUrl = string.Format(GlobalConstants.CHILD_CATEGORY_PATH_TEMPLATE, childCategory.Id);

            Assert.Equal(childCategoryExpectedImageUrl, childCategory.ImageUrl);
            Assert.True(isImageUrlCreated);
        }
        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 EditChildCategoryWhithInvaliParentCategoryIdShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "EditChildCategory_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 newChildCategoryName        = "Monitors";
            var newChildCategoryDescription = "17''";
            var invalidParentCategoryId     = 121;
            var isChildCategoryEdit         = childCategoriesService.EditChildCategory(childCategory.Id, newChildCategoryName, newChildCategoryDescription, invalidParentCategoryId);

            Assert.False(isChildCategoryEdit);
        }
        public void EditChildCategoryShouldReturnTrueAndEditCorrectlyChildCategory()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "EditChildCategory_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 newChildCategoryName        = "Monitors";
            var newChildCategoryDescription = "17''";
            var isChildCategoryEdit         = childCategoriesService.EditChildCategory(childCategory.Id, newChildCategoryName, newChildCategoryDescription, parentCategory.Id);

            var childCategoryExpectedImageUrl = string.Format(GlobalConstants.CHILD_CATEGORY_PATH_TEMPLATE, childCategory.Id);

            Assert.Equal(newChildCategoryName, childCategory.Name);
            Assert.Equal(newChildCategoryDescription, childCategory.Description);
            Assert.True(isChildCategoryEdit);
        }
        public void CreateChildCategoryShouldCreateChildCategory()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateChildCategory_ChildCategories_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

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

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

            var childCategoriesService = new ChildCategoriesService(dbContext);

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

            Assert.Equal(1, dbContext.ChildCategories.Count());
            Assert.Equal(childCategoryName, childCategory.Name);
        }