public async Task TestIfCreateJSONMonitorWorksAsExpected(string category, string articleNumber) { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); 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 monitorsJson = await File.ReadAllTextAsync( @"C:\Users\velis\source\repos\PCHUBStore\PCHUBStore.Tests\AdminServicesTests\JSONMonitors\monitors.json"); var monitors = JsonConvert.DeserializeObject <List <JsonProductModel> >(monitorsJson); await adminProductServices.CreateCategoryAsync(category); foreach (var monitor in monitors) { var jsonBasic = JsonConvert.SerializeObject(monitor.BasicChars); var jsonAdvanced = JsonConvert.SerializeObject(monitor.AdvancedChars); model.Category = category; model.BasicCharacteristics = jsonBasic; model.FullCharacteristics = jsonAdvanced; await adminProductServices.CreateMonitorFromJSONAsync(model); } var result = await context.Products.ToListAsync(); Assert.Equal(4, result.Count); Assert.Contains(result, x => x.ArticleNumber.Contains(articleNumber)); }
public async Task TestIfUpdateCategoryWorksAccordinglyForMonitors(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 monitorsJson = await File.ReadAllTextAsync( @"C:\Users\velis\source\repos\PCHUBStore\PCHUBStore.Tests\AdminServicesTests\JSONMonitors\monitors.json"); var monitors = JsonConvert.DeserializeObject <List <JsonProductModel> >(monitorsJson); await adminProductServices.CreateCategoryAsync(category); foreach (var monitor in monitors) { var jsonBasic = JsonConvert.SerializeObject(monitor.BasicChars); var jsonAdvanced = JsonConvert.SerializeObject(monitor.AdvancedChars); model.Category = category; model.BasicCharacteristics = jsonBasic; model.FullCharacteristics = jsonAdvanced; await adminProductServices.CreateMonitorFromJSONAsync(model); } var listOfSubNames = new List <string> { "Make", "Resolution", "FPS", "Reaction Time", "Matrix Type", "Display Size" }; 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); } }
public async Task TestIfQueryMonitorsReturnsCorrectResults(string category) { var context = PCHUBDbContextInMemoryInitializer.InitializeContext(); var productService = new ProductServices(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 monitorsJson = await File.ReadAllTextAsync( @"C:\Users\velis\source\repos\PCHUBStore\PCHUBStore.Tests\AdminServicesTests\JSONMonitors\monitors.json"); var monitors = JsonConvert.DeserializeObject <List <JsonProductModel> >(monitorsJson); await adminProductServices.CreateCategoryAsync(category); foreach (var monitor in monitors) { var jsonBasic = JsonConvert.SerializeObject(monitor.BasicChars); var jsonAdvanced = JsonConvert.SerializeObject(monitor.AdvancedChars); model.Category = category; model.BasicCharacteristics = jsonBasic; model.FullCharacteristics = jsonAdvanced; await adminProductServices.CreateMonitorFromJSONAsync(model); } var filters = new ProductFiltersUrlModel(); if (filters.Make == null) { filters.Make = new string[] { "All" }; } if (filters.Model == null) { filters.Model = new string[] { "All" }; } if (filters.OrderBy == null) { filters.OrderBy = "Default"; } if (filters.Processor == null) { filters.Processor = new string[] { "All" }; } if (filters.VideoCard == null) { filters.VideoCard = new string[] { "All" }; } if (filters.OS == null) { filters.OS = new string[] { "All" }; } if (filters.RAM == null) { filters.RAM = new string[] { "All" }; } if (filters.Resolution == null) { filters.Resolution = new string[] { "All" }; } if (filters.FPS == null) { filters.FPS = new string[] { "All" }; } if (filters.ReactionTime == null) { filters.ReactionTime = new string[] { "All" }; } if (filters.MatrixType == null) { filters.MatrixType = new string[] { "All" }; } if (filters.DisplaySize == null) { filters.DisplaySize = new string[] { "All" }; } if (filters.Gaming == null) { filters.Gaming = new string[] { "All" }; } if (filters.Interface == null) { filters.Interface = new string[] { "All" }; } if (filters.Connectivity == null) { filters.Connectivity = new string[] { "All" }; } if (filters.Type == null) { filters.Type = new string[] { "All" }; } if (filters.Mechanical == null) { filters.Mechanical = new string[] { "All" }; } var result = await productService.QueryMonitorsAsync(filters, 400, 1000); Assert.Equal(4, result.Count()); Assert.Contains(result, x => x.Make.Contains("BenQ")); filters.Make = new string[] { "BenQ", }; var secondResultTest = await productService.QueryMonitorsAsync(filters, 700, 800); Assert.Equal(1, secondResultTest.Count()); Assert.Contains(secondResultTest, x => x.ArticleNumber.Contains("97773")); filters.Make = new string[] { "Dell", }; filters.MinPrice = "800"; filters.MaxPrice = "900"; var thirdResultTest = await productService.QueryMonitorsAsync(filters, 800, 900); Assert.Empty(thirdResultTest); }