public void Create_WithCorrectData_ShouldSuccessfullyCreate() { string errorMessagePrefix = "ChildCategoriesService Create() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.childCategoriesService = new ChildCategoriesService(context, new ParentCategoriesService(context)); int parentCategoryId = context.ParentCategories.First().Id; ChildCategoryServiceModel testChildCategory = new ChildCategoryServiceModel { Name = "Настолни компютри", ParentCategoryId = parentCategoryId }; int expectedCount = context.ChildCategories.Count() + 1; bool actualResult = this.childCategoriesService.Create(testChildCategory); int actualCount = context.ChildCategories.Count(); Assert.True(actualResult, errorMessagePrefix); Assert.Equal(expectedCount, actualCount); }
public ProductsController(IProductsService productService, IChildCategoriesService childCategoriesService, IImagesService imageService, IMapper mapper) { this.productService = productService; this.childCategoriesService = childCategoriesService; this.imageService = imageService; this.mapper = mapper; }
public ChildCategoriesController(IChildCategoriesService childCategoryService, IParentCategoriesService parentCategoryService, IImagesService imageService, IMapper mapper) { this.childCategoryService = childCategoryService; this.parentCategoryService = parentCategoryService; this.imageService = imageService; this.mapper = mapper; }
public void GetAllChildCategories_WithZeroData_ShouldReturnEmptyResults() { var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.childCategoriesService = new ChildCategoriesService(context, new ParentCategoriesService(context)); List <ChildCategoryServiceModel> actualResults = this.childCategoriesService.GetAllChildCategories().ToList(); int expectedResults = 0; Assert.Equal(expectedResults, actualResults.Count()); }
public HomeController(IChildCategoriesService childCategoryService, IParentCategoriesService parentCategoryService, IProductsService productService, IUserRequestsService userRequestService, IMapper mapper) { this.childCategoryService = childCategoryService; this.parentCategoryService = parentCategoryService; this.productService = productService; this.userRequestService = userRequestService; this.mapper = mapper; }
public void IsHaveChildCategoryWhitId_WithExistentId_ShouldReturnCorrectResults() { string errorMessagePrefix = "ChildCategoriesService IsHaveChildCategoryWhitId() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.childCategoriesService = new ChildCategoriesService(context, new ParentCategoriesService(context)); int testId = context.ChildCategories.First().Id; bool actualResults = this.childCategoriesService.IsHaveChildCategoryWhitId(testId); Assert.True(actualResults, errorMessagePrefix); }
public void GetChildCategoryById_WithNonExistentId_ShouldReturnNull() { string errorMessagePrefix = "ChildCategoriesService GetChildCategoryById() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.childCategoriesService = new ChildCategoriesService(context, new ParentCategoriesService(context)); int nonExistentId = 5; ChildCategoryServiceModel actualResults = this.childCategoriesService.GetChildCategoryById(nonExistentId); Assert.True(actualResults == null, errorMessagePrefix); }
public void Delete_WithNonExistentId_ShouldReturnFalse() { string errorMessagePrefix = "ChildCategoriesService Delete() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.childCategoriesService = new ChildCategoriesService(context, new ParentCategoriesService(context)); int testId = context.ChildCategories.Last().Id + 1; int expectedCount = context.ChildCategories.Count(); bool actualResult = this.childCategoriesService.Delete(testId); int actualCount = context.ChildCategories.Count(); Assert.False(actualResult, errorMessagePrefix); Assert.Equal(expectedCount, actualCount); }
public void GetChildCategoryById_WithExistentId_ShouldReturnCorrectResults() { string errorMessagePrefix = "ChildCategoriesService GetChildCategoryById() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.childCategoriesService = new ChildCategoriesService(context, new ParentCategoriesService(context)); ChildCategoryServiceModel expectedResults = context.ChildCategories.First().To <ChildCategoryServiceModel>(); ChildCategoryServiceModel actualResults = this.childCategoriesService.GetChildCategoryById(expectedResults.Id); Assert.True(expectedResults.Id == actualResults.Id, errorMessagePrefix + " " + "Id is not returned properly."); Assert.True(expectedResults.Name == actualResults.Name, errorMessagePrefix + " " + "Name is not returned properly."); Assert.True(expectedResults.Products.Count() == actualResults.Products.Count(), errorMessagePrefix + " " + "Products Count is not returned properly."); Assert.True(expectedResults.ParentCategoryId == actualResults.ParentCategoryId, errorMessagePrefix + " " + "ParentCategoryId is not returned properly."); }
public void Edit_WithNonExistentId_ShouldReturnFalse() { string errorMessagePrefix = "ChildCategoriesService Edit() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.childCategoriesService = new ChildCategoriesService(context, new ParentCategoriesService(context)); ChildCategoryServiceModel childCategoryFromDb = context.ChildCategories.First().To <ChildCategoryServiceModel>(); ChildCategoryServiceModel NonExistrentId = childCategoryFromDb; NonExistrentId.Id = 1000; bool actualResult = this.childCategoriesService.Edit(NonExistrentId); Assert.False(actualResult, errorMessagePrefix); }
public void Edit_WithCorrectData_ShouldPassSuccessfully() { string errorMessagePrefix = "ChildCategoriesService Edit() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.childCategoriesService = new ChildCategoriesService(context, new ParentCategoriesService(context)); ChildCategoryServiceModel childCategoryFromDb = context.ChildCategories.First().To <ChildCategoryServiceModel>(); ChildCategoryServiceModel expectedChildCategory = childCategoryFromDb; expectedChildCategory.Name = "Edit"; bool actualResult = this.childCategoriesService.Edit(expectedChildCategory); ChildCategoryServiceModel actualChildCategory = context.ChildCategories.FirstOrDefault(p => p.Id == childCategoryFromDb.Id).To <ChildCategoryServiceModel>(); Assert.True(actualChildCategory.Name == expectedChildCategory.Name, errorMessagePrefix + " " + "Name not editted properly."); Assert.True(actualResult, errorMessagePrefix); }
public void Create_WithNonExistentParentCategory_ShouldReturnFalse() { string errorMessagePrefix = "ChildCategoriesService Create() method does not work properly."; var context = UniShopDbContextInMemoryFactory.InitializeContext(); this.SeedData(context); this.childCategoriesService = new ChildCategoriesService(context, new ParentCategoriesService(context)); ChildCategoryServiceModel testChildCategory = new ChildCategoryServiceModel { Name = "Настолни компютри", ParentCategoryId = 10 }; int expectedCount = context.ChildCategories.Count(); bool actualResult = this.childCategoriesService.Create(testChildCategory); int actualCount = context.ChildCategories.Count(); Assert.False(actualResult, errorMessagePrefix); Assert.Equal(expectedCount, actualCount); }
public ChildCategoriesController(IChildCategoriesService childCategoriesService, IParentCategoriesService parentCategoriesService) { this.childCategoriesService = childCategoriesService; this.parentCategoriesService = parentCategoriesService; }
public ProductsController(IChildCategoriesService childCategoriesService, ICloudinaryService cloudinaryService, IProductsService productsService) { this.childCategoriesService = childCategoriesService; this.cloudinaryService = cloudinaryService; this.productsService = productsService; }
public ProductsService(UniShopDbContext context, IChildCategoriesService childCategoriesService) { this.context = context; this.childCategoriesService = childCategoriesService; }