public async Task TestIfFilterForCategoryExistsReturnsTrue(string category, string subName) { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var filtersService = new Areas.Administration.Services.AdminFiltersServices(context); var form = new InserFilterCategoryViewModel(); form.Category = category; form.CategoryViewSubName = subName; await filtersService.CreateFilterCategoryAsync(form); Assert.True(await filtersService.FilterForCategoryExistsAsync(category, subName)); }
public async Task TestIfCreateFilterCategoryWorksAccordingly(string category, string subName) { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var filtersService = new Areas.Administration.Services.AdminFiltersServices(context); var form = new InserFilterCategoryViewModel(); form.Category = category; form.CategoryViewSubName = subName; await filtersService.CreateFilterCategoryAsync(form); var result = await context.FilterCategories.FirstOrDefaultAsync(x => x.CategoryName == category); Assert.Equal(subName, result.ViewSubCategoryName); }
public async Task TestIfUpdateCategoryWorksAccordinglyForKeyboards(string category) { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var filtersService = new Areas.Administration.Services.AdminFiltersServices(context); Account cloudinaryCredentials = new Account( CloudinaryAccountTests.CloudName, CloudinaryAccountTests.ApiKey, CloudinaryAccountTests.ApiSecret); var cloudinaryUtility = new Cloudinary(cloudinaryCredentials); var cloudinary = new CloudinaryServices(cloudinaryUtility); var adminProductServices = new Areas.Administration.Services.AdminProductsServices(context, cloudinary); var model = new InsertJsonProductViewModel(); var keyboardsJson = await File.ReadAllTextAsync( @"C:\Users\velis\source\repos\PCHUBStore\PCHUBStore.Tests\AdminServicesTests\JSONKeyboards\keyboards.json"); var keyboards = JsonConvert.DeserializeObject <List <JsonProductModel> >(keyboardsJson); await adminProductServices.CreateCategoryAsync(category); foreach (var keyboard in keyboards) { var jsonBasic = JsonConvert.SerializeObject(keyboard.BasicChars); var jsonAdvanced = JsonConvert.SerializeObject(keyboard.AdvancedChars); model.Category = category; model.BasicCharacteristics = jsonBasic; model.FullCharacteristics = jsonAdvanced; await adminProductServices.CreateKeyboardFromJSONAsync(model); } var listOfSubNames = new List <string> { "Make", "Type", "Interface", "Mechanical", }; for (int i = 0; i < listOfSubNames.Count; i++) { var formFilterCategory = new InserFilterCategoryViewModel(); formFilterCategory.CategoryViewSubName = listOfSubNames[i]; formFilterCategory.Category = category; await filtersService.CreateFilterCategoryAsync(formFilterCategory); } await filtersService.UpdateCategoryAsync(category); for (int i = 0; i < listOfSubNames.Count; i++) { var result = await context.FilterCategories.FirstOrDefaultAsync(x => x.CategoryName == category && x.ViewSubCategoryName == listOfSubNames[i]); Assert.NotNull(result); Assert.NotEmpty(result.Filters); } }