public async Task TestIfCreateJSONComputerWorksAsExpected(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 computersJson = await File.ReadAllTextAsync( @"C:\Users\velis\source\repos\PCHUBStore\PCHUBStore.Tests\AdminServicesTests\JSONComputers\computers.json"); var computers = JsonConvert.DeserializeObject <List <JsonProductModel> >(computersJson); await adminProductServices.CreateCategoryAsync(category); foreach (var computer in computers) { var jsonBasic = JsonConvert.SerializeObject(computer.BasicChars); var jsonAdvanced = JsonConvert.SerializeObject(computer.AdvancedChars); model.Category = category; model.BasicCharacteristics = jsonBasic; model.FullCharacteristics = jsonAdvanced; await adminProductServices.CreateComputerFromJSONAsync(model); } var result = await context.Products.ToListAsync(); Assert.Equal(4, result.Count); Assert.Contains(result, x => x.ArticleNumber.Contains(articleNumber)); }
public async Task TestIfUpdateCategoryWorksAccordinglyForComputers(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 computersJson = await File.ReadAllTextAsync( @"C:\Users\velis\source\repos\PCHUBStore\PCHUBStore.Tests\AdminServicesTests\JSONComputers\computers.json"); var computers = JsonConvert.DeserializeObject <List <JsonProductModel> >(computersJson); await adminProductServices.CreateCategoryAsync(category); foreach (var computer in computers) { var jsonBasic = JsonConvert.SerializeObject(computer.BasicChars); var jsonAdvanced = JsonConvert.SerializeObject(computer.AdvancedChars); model.Category = category; model.BasicCharacteristics = jsonBasic; model.FullCharacteristics = jsonAdvanced; await adminProductServices.CreateComputerFromJSONAsync(model); } var listOfSubNames = new List <string> { "Video Card", "RAM", "OS", "Processor" }; 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 TestIfQueryComputersReturnsCorrectResults(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 computersJson = await File.ReadAllTextAsync( @"C:\Users\velis\source\repos\PCHUBStore\PCHUBStore.Tests\AdminServicesTests\JSONComputers\computers.json"); var computers = JsonConvert.DeserializeObject <List <JsonProductModel> >(computersJson); await adminProductServices.CreateCategoryAsync(category); foreach (var computer in computers) { var jsonBasic = JsonConvert.SerializeObject(computer.BasicChars); var jsonAdvanced = JsonConvert.SerializeObject(computer.AdvancedChars); model.Category = category; model.BasicCharacteristics = jsonBasic; model.FullCharacteristics = jsonAdvanced; await adminProductServices.CreateComputerFromJSONAsync(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.QueryComputersAsync(filters, 1000, 2000); Assert.Equal(4, result.Count()); Assert.Contains(result, x => x.Title.Contains("UPGRADED Компютър Fury (Ryzen 2700, 8GB, 1TB, 120 GB SSD, GTX 1660ti 6GB GDDR6, Win10)")); filters.Processor = new string[] { "AMD", }; var secondResultTest = await productService.QueryComputersAsync(filters, 1800, 1820); Assert.Equal(3, secondResultTest.Count()); Assert.Contains(secondResultTest, x => x.ArticleNumber.Contains("101279_101305")); filters.Make = new string[] { "Dell", }; filters.MinPrice = "800"; filters.MaxPrice = "900"; var thirdResultTest = await productService.QueryComputersAsync(filters, 800, 900); Assert.Empty(thirdResultTest); }