public ArticleController() { _categoryService = new CategoryService(); _subCategoryService = new SubCategoryService(); _appUserService = new AppUserService(); _articleService = new ArticleService(); }
public HomeController(MenuItemService menuItemService, CategoryService categoryService, SubCategoryService subCategoryService, CouponService couponService) { _menuItemService = menuItemService; _categoryService = categoryService; _subCategoryService = subCategoryService; _couponService = couponService; }
public void UpdateSubCategoryOfMainCategoryDescriptionSuccess() { var config = new HttpConfiguration(); var request = new HttpRequestMessage(HttpMethod.Put, "http://localhost/api/user/44300"); var route = config.Routes.MapHttpRoute("Default", "api/{controller}/UpdateDescription/"); var controller = new CategoryController { Request = request, }; controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config; MainCategoryService.AddMainCategory("unit test", "unit test"); SubCategoryService.AddSubCategory("unit test", "unit_test"); SwapDbConnection db = new SwapDbConnection(); main_category test_main = db.main_category.Where(x => x.name == "unit test").FirstOrDefault(); sub_category test_sub = db.sub_category.Where(x => x.name == "unit test").FirstOrDefault(); CategoryService.AddMainAndSubRelationship(test_main.main_id, test_sub.sub_id, "unit test", "unit test"); Assert.AreEqual(controller.UpdateSubCategoryOfMainCategoryDescription(new MainAndSubRelationshipDTO() { main_id = test_main.main_id, sub_id = test_sub.sub_id, descrition = "test" }).StatusCode, HttpStatusCode.OK); delete_main_category.DeleteMainCategorySuccess(); delete_sub_category.DeleteSubCategorySuccess(); }
public async Task DeleteSubCategory_ThrowsExceptionIfTheIdIsNull() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); await Assert.ThrowsAsync <ArgumentNullException>(async() => { await subCategoryService.DeleteSubCategory(null); }); }
public BaseController() { _advertisementService = new AdvertisementService(); _sellerService = new SellerService(); _buyerService = new BuyerService(); _locationService = new LocationService(); _userService = new UserService(); UserId = GetSession <UserSessionInfo>(USER_SESSION)?.Id ?? 0; _categoryService = new CategoryService(); _subCategoryService = new SubCategoryService(); }
public async Task DeleteSubCategory_ReturnsTrue_WhenTheIdISCorect() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); var subCategoryTestSeeder = new SubCategoryTestSeeder(); await subCategoryTestSeeder.SeedSubCategories(context); var shouldBeTrue = await subCategoryService.DeleteSubCategory("1"); Assert.True(shouldBeTrue); }
public ManageCategoryController ( MainCategoryService _mainCategoryService, SubCategoryService _subCategoryService, TrackService _trackService, Services.CourseService _courseService ) { mainCategoryService = _mainCategoryService; subCategoryService = _subCategoryService; trackService = _trackService; courseService = _courseService; }
public async Task DeleteSubCategory_WithNonExistingCategory_ShouldReturnFalse() { string onTrueErrorMessage = "The method returned true upon valid category input."; var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryService = new SubCategoryService(context); string invalidSubCategoryId = "FakeCategoryId"; var methodResult = await subCategoryService.DeleteSubCategory(invalidSubCategoryId); Assert.False(methodResult, onTrueErrorMessage); }
public async Task SetUp() { var options = new DbContextOptionsBuilder <ShoplifyDbContext>() .UseInMemoryDatabase(databaseName: "categories") .Options; this.context = new ShoplifyDbContext(options); await context.Database.EnsureDeletedAsync(); await context.Database.EnsureCreatedAsync(); this.service = new SubCategoryService(context, new CategoryService(context)); }
public async Task GetDeletableSubCategories_WithNoSubCategories_ShouldReturnAnEmptyCollection() { string onCountDiferenceErrorMessage = "The method did not return an empty collection."; var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryService = new SubCategoryService(context); var methodResult = await subCategoryService.GetDeletableSubCategories(); var expectedCount = 0; AssertExtensions.EqualCountWithMessage(expectedCount, methodResult.Count(), onCountDiferenceErrorMessage); }
public async Task SubCategoryExists_OnNonExistingSubCategory_ShouldReturnTrue() { string onTrueErrorMessage = "The method returned true on non-existing sub-category."; var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryService = new SubCategoryService(context); string nonExistingSubCategoryName = "fakeSubCategoryId"; var methodResult = await subCategoryService.SubCategoryExists(nonExistingSubCategoryName); Assert.False(methodResult, onTrueErrorMessage); }
// GET api/<controller> public IHttpActionResult Get() { IHttpActionResult result = null; SubCategoryService service = new SubCategoryService(); IEnumerable <SubCategory> subCategories = service.GetSubCategories(); if (subCategories.Count() > 0) { result = Ok(subCategories); } else { result = NotFound(); } return(result); }
public async Task GetDeletableSubCategories_WithDeletableSubCategories_ShouldReturnCorrectCollection() { string onCountDiferenceErrorMessage = "The method did not return the expected collection with elements."; var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryService = new SubCategoryService(context); await this.SeedAndGetSubCategoriesWithCategories(context); var methodResult = await subCategoryService.GetDeletableSubCategories(); var expectedCount = 6; AssertExtensions.EqualCountWithMessage(expectedCount, methodResult.Count(), onCountDiferenceErrorMessage); }
public IHttpActionResult Post(SubCategory subCategory) { IHttpActionResult result = null; SubCategoryService service = new SubCategoryService(); SubCategory newSubCategory = service.InsertSubCategory(subCategory); if (newSubCategory != null) { result = Created <SubCategory>(Request.RequestUri + newSubCategory.ID.ToString(), newSubCategory); } else { result = NotFound(); } return(result); }
public async Task CreateCategoryAsync_ReturnsTrueAndCreates_IfNameIsUnique() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); var subCategoryCreateInputModel = new SubCategoryCreateInputModel() { Name = "SubCategory1", CategoryId = "categoryId1", }; var shouldReturnTrue = await subCategoryService.CreateAsync(subCategoryCreateInputModel); Assert.True(shouldReturnTrue); }
public async Task SubCategoryExists_OnExistingSubCategory_ShouldReturnTrue() { string onFalseErrorMessage = "The method returned false on existing sub-category."; var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryService = new SubCategoryService(context); // Seeding multiple categories with sub-categories var expectedSubCategories = await this.SeedAndGetSubCategoriesWithCategories(context); string existingSubCategoryName = "A-SubCategory-forSecond"; var methodResult = await subCategoryService.SubCategoryExists(existingSubCategoryName); Assert.True(methodResult, onFalseErrorMessage); }
// PUT api/<controller>/5 public IHttpActionResult Put(SubCategory subCategory) { IHttpActionResult result = null; SubCategoryService service = new SubCategoryService(); if (service.GetSubCategory(subCategory.ID) != null) { service.UpdateSubCategory(subCategory); result = Ok(subCategory); } else { result = NotFound(); } return(result); }
public async Task CreateAsync_ThrowsException_IfNameIsNullOrWhiteSpace() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); var subcategoryCreateInputModel = new SubCategoryCreateInputModel() { Name = null, CategoryId = null, }; await Assert.ThrowsAsync <ArgumentNullException>(async() => { await subCategoryService.CreateAsync(subcategoryCreateInputModel); }); }
public async Task AddSubCategory_WithNonExistingMainCategory_ShouldReturnFalse() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryService = new SubCategoryService(context); string categoryId = "fakeCategoryId"; SubCategoryBindingModel model = new SubCategoryBindingModel { CategoryId = categoryId, Name = "NewSubCategory", }; var methodResult = await subCategoryService.AddSubCategory(model); Assert.False(methodResult, "The method did not return false upon wrong data input for creation."); }
public async Task GetNameByIdAsync_ReturnsTheNameOrThrowsException() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); var subCategoryTestSeeder = new SubCategoryTestSeeder(); await subCategoryTestSeeder.SeedSubCategories(context); var actualName = await subCategoryService.GetNameByIdAsync("1"); Assert.Equal("SubCategory1", actualName); await Assert.ThrowsAsync <ArgumentNullException>(async() => { await subCategoryService.GetNameByIdAsync("invalid"); }); }
public async Task CreateAsync_ReturnsFalse_IfNameIsNotUnique() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); var subCategoryTestSeeder = new SubCategoryTestSeeder(); await subCategoryTestSeeder.SeedSubCategories(context); var subCategoryCreateInputModel = new SubCategoryCreateInputModel() { Name = "SubCategory1", CategoryId = "categoryId1", }; var shouldReturnfalse = await subCategoryService.CreateAsync(subCategoryCreateInputModel); Assert.False(shouldReturnfalse); }
public HomeController ( MainCategoryService _mainCategoryService, SubCategoryService _subCategoryService, TrackService _trackService, CourseService _courseService, UserTrackService _userTrackService, UserService _userService ) { mainCategoryService = _mainCategoryService; subCategoryService = _subCategoryService; trackService = _trackService; courseService = _courseService; userTrackService = _userTrackService; userService = _userService; Hub = GlobalHost.ConnectionManager.GetHubContext <WhatsLearnHub>(); }
public async Task EditSubCategory_ReturnsTrue_IfNameIsUnique() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); var subCategoryTestSeeder = new SubCategoryTestSeeder(); await subCategoryTestSeeder.SeedSubCategories(context); var subCategoryEditInputModel = new SubCategoryEditInputModel() { Id = "1", Name = "Unique", }; var shouldBetrue = await subCategoryService.EditSubCategory(subCategoryEditInputModel); Assert.True(shouldBetrue); }
// GET api/<controller>/5 public IHttpActionResult Get(int id) { IHttpActionResult result = null; SubCategoryService service = new SubCategoryService(); SubCategory subCategory = service.GetSubCategory(id); if (subCategory != null) { result = Ok(subCategory); } else { result = NotFound(); } return(result); }
// DELETE api/<controller>/5 public IHttpActionResult Delete(int id) { IHttpActionResult result = null; SubCategoryService service = new SubCategoryService(); SubCategory subCategory = service.GetSubCategory(id); if (subCategory != null) { service.RemoveSubCategory(id); result = Ok(true); } else { result = NotFound(); } return(result); }
public async Task EditSubCategory_ThrowsExceotion_IfMOdelIsIncorect() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); var subCategoryTestSeeder = new SubCategoryTestSeeder(); await subCategoryTestSeeder.SeedSubCategories(context); var subCategoryEditInputModel = new SubCategoryEditInputModel() { Id = "Incorrect", Name = "SubCategory2", }; await Assert.ThrowsAsync <ArgumentNullException>(async() => { await subCategoryService.EditSubCategory(subCategoryEditInputModel); }); }
public override IActionResult Edit(int id) { try { var model = Service.GetByIdWithInclude(id); var categories = CategoryService.GetAll().ToList(); ViewBag.Categories = categories; var subCategories = SubCategoryService.GetSubCategoriesByRootCategoryId(model.SubCategory.RootCategoryId); ViewBag.SubCategories = subCategories; var brands = BrandService.GetAll().ToList(); ViewBag.Brands = brands; return(View(model)); } catch (Exception ex) { Logger.LogError($"Error occured at ProductController at [HttpGet] Edit(int id) method with parameter: {id} --> {ex}"); } return(View()); }
public async Task GetSubCategories_WithSeededSubCategories_ShouldReturnCorrectResult() { string onFalseErrorMessage = "The returned sub-categories are not correct."; var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryService = new SubCategoryService(context); // Seeding multiple categories with sub-categories var expectedSubCategories = await this.SeedAndGetSubCategoriesWithCategories(context); var actualSubCategories = await subCategoryService.GetSubCategories(); // The returned names contains the following format -> "SubCategoryName(MainCategoryName)" foreach (var ctg in actualSubCategories) { Assert.True( expectedSubCategories.Any(c => c.Name + $"({c.Category.Name})" == ctg.Text && c.Id == ctg.Value), onFalseErrorMessage); } }
public HttpResponseMessage UpdateSubCategoryOfMainCategory([FromBody] MainAndSubRelationshipDTO req) { try { bool success; if (req.main_id == null || req.sub_id == null || req.sub_name == null || req.google_value == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "missing parameters")); } success = SubCategoryService.updateSubCategory(req.sub_id, req.google_value, req.sub_name); success &= CategoryService.UpdateDescription(req.main_id, req.sub_id, req.descrition); if (success) { return(Request.CreateResponse(HttpStatusCode.OK, true)); } return(Request.CreateResponse(HttpStatusCode.BadRequest, "Bad request")); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "There was an InternalServerError: " + e)); } }
public async Task DeleteSubCategory_WithExistingCategory_ShouldDeleteCategorySuccessfully() { string onFalseErrorMessage = "The method returned false upon valid sub-category input."; string onNotNullErrorMessage = "The sub-category is not deleted from the database."; var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryService = new SubCategoryService(context); await this.SeedAndGetSubCategoriesWithCategories(context); string validSubCategoryId = "A-SubCategoryId-forFirst"; var methodResult = await subCategoryService.DeleteSubCategory(validSubCategoryId); Assert.True(methodResult, onFalseErrorMessage); var categoriesFromDb = await context .Categories .FirstOrDefaultAsync(c => c.Id == validSubCategoryId); AssertExtensions.NullWithMessage(categoriesFromDb, onNotNullErrorMessage); }