public void CreateParentCategoryWhithNullParameterShouldNotCreateMainCategory() { var options = new DbContextOptionsBuilder <XeonDbContext>() .UseInMemoryDatabase(databaseName: "CreateParentCategory_ParentCategories_Database") .Options; var dbContext = new XeonDbContext(options); var parentCategoryService = new ParentCategoriesService(dbContext); parentCategoryService.CreateParentCategory(null); Assert.Equal(0, dbContext.ParentCategories.Count()); }
public void CreateParentCategoryShouldCreateMainCategory() { var options = new DbContextOptionsBuilder <XeonDbContext>() .UseInMemoryDatabase(databaseName: "CreateParentCategory_ParentCategories_Database") .Options; var dbContext = new XeonDbContext(options); var parentCategoryService = new ParentCategoriesService(dbContext); parentCategoryService.CreateParentCategory("Computers"); parentCategoryService.CreateParentCategory("Phones"); Assert.Equal(2, dbContext.ParentCategories.Count()); }
public void EditParentCategoryByIdWhithInvalidParentCategoryIdShouldReturnFalse() { var options = new DbContextOptionsBuilder <XeonDbContext>() .UseInMemoryDatabase(databaseName: "EditParentCategory_ParentCategories_Database") .Options; var dbContext = new XeonDbContext(options); var parentCategoryService = new ParentCategoriesService(dbContext); var invalidParentCategoryId = 123; var newParentCategoryName = "Computers"; var isParentCategoryEdit = parentCategoryService.EditParentCategory(invalidParentCategoryId, newParentCategoryName); Assert.False(isParentCategoryEdit); }
public void DeleteParentCategoryShouldReturnTrueAndDeleteParentCategory() { var options = new DbContextOptionsBuilder <XeonDbContext>() .UseInMemoryDatabase(databaseName: "DeleteParentCategoryCorrect_ParentCategories_Database") .Options; var dbContext = new XeonDbContext(options); var parentCategoryService = new ParentCategoriesService(dbContext); var parentCategory = parentCategoryService.CreateParentCategory("Computers"); var isParentCategoryDeleted = parentCategoryService.DeleteParentCategory(parentCategory.Id); Assert.Equal(0, dbContext.ParentCategories.Count()); Assert.True(isParentCategoryDeleted); }
public void GetParentCategoryByIdShouldReturnParentCategory() { var options = new DbContextOptionsBuilder <XeonDbContext>() .UseInMemoryDatabase(databaseName: "GetParentCategoryById_ParentCategories_Database") .Options; var dbContext = new XeonDbContext(options); var parentCategoryService = new ParentCategoriesService(dbContext); var parentCategoryComputers = parentCategoryService.CreateParentCategory("Computers"); var parentCategoryPhones = parentCategoryService.CreateParentCategory("Phones"); var parentCategory = parentCategoryService.GetParentCategoryById(parentCategoryPhones.Id); Assert.Equal(parentCategoryPhones.Id, parentCategory.Id); Assert.Equal(parentCategoryPhones.Name, parentCategory.Name); }
public void DeleteParentCategoryWhithInvalidParentCategoryIdShouldReturnFalse() { var options = new DbContextOptionsBuilder <XeonDbContext>() .UseInMemoryDatabase(databaseName: "DeleteParentCategoryWhithInvalidParentCategoryId_ParentCategories_Database") .Options; var dbContext = new XeonDbContext(options); var parentCategoryService = new ParentCategoriesService(dbContext); var parentCategory = parentCategoryService.CreateParentCategory("Computers"); var invalidParentCategoryId = 123; var isParentCategoryDeleted = parentCategoryService.DeleteParentCategory(invalidParentCategoryId); Assert.Equal(1, dbContext.ParentCategories.Count()); Assert.False(isParentCategoryDeleted); }
public void EditParentCategoryByIdShouldReturnTrueAndEditParentCategory() { var options = new DbContextOptionsBuilder <XeonDbContext>() .UseInMemoryDatabase(databaseName: "EditParentCategory_ParentCategories_Database") .Options; var dbContext = new XeonDbContext(options); var parentCategoryService = new ParentCategoriesService(dbContext); var parentCategoryComputers = parentCategoryService.CreateParentCategory("Computers"); var parentCategoryPhones = parentCategoryService.CreateParentCategory("Phones"); var newParentCategoryName = "NewComputers"; var isParentCategoryEdit = parentCategoryService.EditParentCategory(parentCategoryComputers.Id, newParentCategoryName); Assert.Equal(newParentCategoryName, parentCategoryComputers.Name); Assert.True(isParentCategoryEdit); }
public void DeleteParentCategoryWhithChildCategoriesShouldReturnFalse() { var options = new DbContextOptionsBuilder <XeonDbContext>() .UseInMemoryDatabase(databaseName: "DeleteParentCategory_ParentCategories_Database") .Options; var dbContext = new XeonDbContext(options); var parentCategoryService = new ParentCategoriesService(dbContext); var parentCategory = parentCategoryService.CreateParentCategory("Computers"); parentCategory.ChildCategories = new List <ChildCategory> { new ChildCategory { Name = "Cabels" } }; dbContext.SaveChanges(); var invalidParentCategoryId = 123; var isParentCategoryDeleted = parentCategoryService.DeleteParentCategory(invalidParentCategoryId); Assert.Equal(1, dbContext.ParentCategories.Count()); Assert.False(isParentCategoryDeleted); }