public async Task TestIfCreateJSONLaptopWorksAsExpected(string category)
        {
            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 laptopsJson = await
                              File.ReadAllTextAsync(
                @"C:\Users\velis\source\repos\PCHUBStore\PCHUBStore.Tests\AdminServicesTests\JSONLaptops\laptops.json");

            var laptops = JsonConvert.DeserializeObject <List <JsonProductModel> >(laptopsJson);

            await adminProductServices.CreateCategoryAsync(category);

            foreach (var laptop in laptops)
            {
                var jsonBasic = JsonConvert.SerializeObject(laptop.BasicChars);

                var jsonAdvanced = JsonConvert.SerializeObject(laptop.AdvancedChars);
                model.Category             = category;
                model.BasicCharacteristics = jsonBasic;
                model.FullCharacteristics  = jsonAdvanced;

                await adminProductServices.CreateLaptopFromJSONAsync(model);
            }

            var result = await context.Products.ToListAsync();

            Assert.Equal(2, result.Count);

            Assert.Contains(result, x => x.Make == "Acer");
            Assert.Contains(result, x => x.Price == 878);
        }
예제 #2
0
        public async Task TestIfUpdateCategoryWorksAccordinglyForLaptops(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 laptopsJson = await
                              File.ReadAllTextAsync(
                @"C:\Users\velis\source\repos\PCHUBStore\PCHUBStore.Tests\AdminServicesTests\JSONLaptops\laptops.json");

            var laptops = JsonConvert.DeserializeObject <List <JsonProductModel> >(laptopsJson);

            await adminProductServices.CreateCategoryAsync(category);

            foreach (var laptop in laptops)
            {
                var jsonBasic = JsonConvert.SerializeObject(laptop.BasicChars);

                var jsonAdvanced = JsonConvert.SerializeObject(laptop.AdvancedChars);
                model.Category             = category;
                model.BasicCharacteristics = jsonBasic;
                model.FullCharacteristics  = jsonAdvanced;

                await adminProductServices.CreateLaptopFromJSONAsync(model);
            }

            var listOfSubNames = new List <string>
            {
                "Make", "Model", "OS", "Video Card", "Processor", "RAM",
            };

            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);
            }
        }
예제 #3
0
        public async Task TestIfQueryLaptopsReturnsCorrectResults(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 laptopsJson = await
                              File.ReadAllTextAsync(
                @"C:\Users\velis\source\repos\PCHUBStore\PCHUBStore.Tests\AdminServicesTests\JSONLaptops\laptops.json");

            var laptops = JsonConvert.DeserializeObject <List <JsonProductModel> >(laptopsJson);

            await adminProductServices.CreateCategoryAsync(category);

            foreach (var laptop in laptops)
            {
                var jsonBasic = JsonConvert.SerializeObject(laptop.BasicChars);

                var jsonAdvanced = JsonConvert.SerializeObject(laptop.AdvancedChars);
                model.Category             = category;
                model.BasicCharacteristics = jsonBasic;
                model.FullCharacteristics  = jsonAdvanced;

                await adminProductServices.CreateLaptopFromJSONAsync(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.QueryLaptopsAsync(filters, 400, 1000);



            Assert.Equal(2, result.Count());

            Assert.Contains(result, x => x.Title.Contains("Acer"));

            filters.Make = new string[]
            {
                "Acer",
            };

            filters.MinPrice = "700";
            filters.MaxPrice = "750";

            var secondResultTest = await productService.QueryLaptopsAsync(filters, 700, 750);

            Assert.Equal(1, secondResultTest.Count());

            Assert.Contains(secondResultTest, x => x.ArticleNumber.Contains("83366"));


            filters.Make = new string[]
            {
                "Dell",
            };
            filters.MinPrice = "800";
            filters.MaxPrice = "900";

            var thirdResultTest = await productService.QueryLaptopsAsync(filters, 800, 900);

            Assert.Empty(thirdResultTest);
        }