public async Task GetProductReturnsNull(string productId)
        {
            var context        = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var productService = new ProductServices(context);

            Assert.Null(await productService.GetProductAsync(productId));
        }
Beispiel #2
0
        public async Task TestIfBasicFiltersExistForCategoryReturnsFalse(string categoryName)
        {
            var context        = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var filtersService = new Areas.Administration.Services.AdminFiltersServices(context);

            Assert.False(await filtersService.BasicFiltersExistForCategoryAsync(categoryName));
        }
        public async Task TestIfReturnsCorrectPage(string id, string title, string content)
        {
            // Arrange
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var forumService = new ForumServices(context);

            await context.ForumPosts.AddAsync(new Data.Models.ForumPost
            {
                Id        = id,
                Title     = title,
                Content   = content,
                CreatedOn = DateTime.UtcNow,
            });


            await context.SaveChangesAsync();

            //Act
            var result = await forumService.GetForumPostAsync(id);

            // Assert
            Assert.Equal(id, result.Id);
            Assert.Equal(title, result.Title);
            Assert.Equal(content, result.Content);
        }
        public async Task TestIfGetAllCategoryNamesReturnsAllNamesCorrectly(string category, string category1, string category2, string category3)
        {
            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);

            await adminProductServices.CreateCategoryAsync(category);

            await adminProductServices.CreateCategoryAsync(category1);

            await adminProductServices.CreateCategoryAsync(category2);

            await adminProductServices.CreateCategoryAsync(category3);


            var result = await adminProductServices.GetAllCategoryNamesAsync();

            Assert.NotEmpty(result);
            Assert.Contains(result, x => x == category);
            Assert.Contains(result, x => x == category1);
            Assert.Contains(result, x => x == category2);
            Assert.Contains(result, x => x == category3);
        }
        public async Task TestIfGetAllBoxesForPageWorksAccordingly(string pageName, string href, string text,
                                                                   string color)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);

            await context.Pages.AddAsync(new Page
            {
                PageName      = pageName,
                ColorfulBoxes = new List <ColorfulBox>(),
            });

            await context.SaveChangesAsync();

            var model = new AddBoxViewModel();

            model.Color    = color;
            model.Href     = href;
            model.Text     = text;
            model.PageName = pageName;

            await categoryPagesService.AddBoxAsync(model);

            var result = await categoryPagesService.GetAllBoxesForPageAsync(pageName);

            Assert.NotEmpty(result);

            Assert.Contains(result, x => x.Href == href && x.Text == text && x.Color == color);
        }
Beispiel #6
0
        public async Task TestIfQueryShipmentsReturnsCorrectResultAddress()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var shipmentManager = new ShipmentManagerServices(context);

            await context.Shipments.AddAsync(new Shipment
            {
                Id   = 123,
                User = new User
                {
                    FirstName = "Spas",
                    LastName  = "Spas",
                    Address   = "random address"
                }
            });

            await context.SaveChangesAsync();

            var model = new ShipmentManagerIndexModel();

            model.Address = "random address";

            var result = await shipmentManager.QueryShipmentsAsync(model);

            Assert.NotEmpty(result);

            Assert.Contains(result, x => x.Id == 123);
        }
Beispiel #7
0
        public async Task TestIfAddActivityToShipmentReturnsCorrectResult(int shipmentId, string username)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var shipmentManager = new ShipmentManagerServices(context);


            await context.Shipments.AddAsync(new Shipment
            {
                Id         = shipmentId,
                Activities = new List <Activity>(),
            });

            await context.SaveChangesAsync();

            var form = new ActivityViewModel();

            form.OwnerName    = username;
            form.Description  = "Description";
            form.CreationDate = DateTime.UtcNow;
            form.ActivityType = ActivityType.Issue;

            var result = await shipmentManager.AddActivityToShipmentAsync(shipmentId, form, username);

            Assert.NotNull(result);
        }
Beispiel #8
0
        public async Task TestMainSliderPicturesReturnCorrectResult()
        {
            // Arrange
            var context       = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var picturesModel = new List <Picture>();

            for (int i = 0; i < 5; i++)
            {
                picturesModel.Add(new Picture
                {
                    Name = "TestPic" + i,
                    Url  = "TestPic" + 1,
                });
            }
            var homeService = new HomeService(context);

            await context.MainSliders.AddAsync(new MainSlider
            {
                Name = "MainSlider",
                MainSliderPictures = picturesModel,
            });

            await context.SaveChangesAsync();

            var pictures = await homeService.GetMainSliderPicturesAsync();

            Assert.Equal(5, pictures.Count);

            Assert.True(pictures.Exists(x => x.Name.Contains("TestPic")));
        }
        public async Task TestIfGetProductReturnsCorrectResult(string productId)
        {
            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);

            await context.Products.AddAsync(new Product
            {
                Id = productId,
            });

            await context.SaveChangesAsync();

            var result = await adminProductServices.GetProductAsync(productId);

            Assert.NotNull(result);

            Assert.Equal(result.Id, productId);
        }
        public async Task TestIfAddIndexPageCategoryWorksProperly()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var adminPageService = new Areas.Administration.Services.AdminIndexPageServices(context);


            await adminPageService.CreateIndexPageAsync("Index");


            var form = new CreatePageCategoryViewModel();

            form.AllHref      = "AllHref";
            form.AllName      = "AllLaptops";
            form.CategoryName = "Laptops";

            await adminPageService.AddIndexPageCategoryAsync(form, "pictureUrl", "PictureName");

            var result = await context.Pages.FirstOrDefaultAsync(x => x.PageName == "Index");

            Assert.Equal("Index", result.PageName);

            Assert.Contains(result.Categories, (pageCategory) => pageCategory.CategoryName == "Laptops");

            Assert.Contains(result.Categories, (pageCategory) => pageCategory.AllHref == "AllHref");

            Assert.Contains(result.Categories, (pageCategory) => pageCategory.AllName == "AllLaptops");
        }
        public async Task TestIfConnectionIdExistsReturnsTrue()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var chatRequests = new RequestChatServices(context);

            var modelOne = new ChatRequestModel();

            modelOne.Email           = "*****@*****.**";
            modelOne.ConnectionId    = "connectionId";
            modelOne.IsAuthenticated = true;
            modelOne.Subject         = "Help me select laptop";

            await chatRequests.AddToQueueAsync(modelOne);

            var modelTwo = new ChatRequestModel();

            modelOne.Email           = "*****@*****.**";
            modelOne.ConnectionId    = "connectionIdrandom";
            modelOne.IsAuthenticated = true;
            modelOne.Subject         = "Help me select random laptop";

            await chatRequests.AddToQueueAsync(modelOne);


            Assert.True(await chatRequests.ConnectionIdExistsAsync("connectionId"));


            Assert.True(await chatRequests.ConnectionIdExistsAsync("connectionIdrandom"));
        }
        public async Task TestIfEditForumPostWorksAccordingly(string title, string content, string url)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var forumService = new SupportForumServices(context);

            await forumService.CreateForumPost(title, content, url);

            var id = await context.ForumPosts.FirstOrDefaultAsync(x => x.Title == title);

            var form = new EditForumPostViewModel();

            form.Id      = id.Id;
            form.Title   = "new Title";
            form.Content = "new Content";

            await forumService.EditForumPostAsync(form);

            var result = await context.ForumPosts.FirstOrDefaultAsync(x => x.Title == "new Title");

            Assert.NotNull(result);

            Assert.Equal("new Title", result.Title);

            Assert.Equal("new Content", result.Content);
        }
        public async Task TestIfGetAllChatRequestsWorksAccordingly()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var chatRequests = new RequestChatServices(context);

            var modelOne = new ChatRequestModel();

            modelOne.Email           = "*****@*****.**";
            modelOne.ConnectionId    = "connectionId";
            modelOne.IsAuthenticated = true;
            modelOne.Subject         = "Help me select laptop";

            await chatRequests.AddToQueueAsync(modelOne);

            var modelTwo = new ChatRequestModel();

            modelOne.Email           = "*****@*****.**";
            modelOne.ConnectionId    = "connectionIdrandom";
            modelOne.IsAuthenticated = true;
            modelOne.Subject         = "Help me select random laptop";

            await chatRequests.AddToQueueAsync(modelOne);


            var result = await chatRequests.GetAllChatRequestsAsync();

            Assert.NotEmpty(result);

            Assert.Equal(2, result.Count);
        }
        public async Task TestIfUpdateHtmlDescriptionWorksProperly(string productId)
        {
            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 form = new InserHtmlInProductViewModel();

            await context.Products.AddAsync(new Product
            {
                Id = productId,
            });

            await context.SaveChangesAsync();

            form.ProductId = productId;

            form.HtmlContent = "<p>Hello World</p>";

            await adminProductServices.UpdateHtmlDescriptionAsync(form);

            var result = await context.Products.FirstOrDefaultAsync(x => x.Id == productId);

            Assert.NotNull(result.HtmlDescription);

            Assert.Equal("<p>Hello World</p>", result.HtmlDescription);
        }
Beispiel #15
0
        public async Task TestIfCheckoutSignedInUserDetailsNotPresentReturnsFalse(string username, string product1,
                                                                                  string product2, string product3)
        {
            var context        = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var productService = new ProductServices(context);
            var shopService    = new ShopServices(context, productService);


            var productsInsideUserCart = new List <Product>();

            productsInsideUserCart.Add(new Product
            {
                Id        = product1,
                Price     = 300,
                Title     = "Test Product",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });


            productsInsideUserCart.Add(new Product
            {
                Id        = product2,
                Price     = 300,
                Title     = "Test Product1",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });

            productsInsideUserCart.Add(new Product
            {
                Id        = product3,
                Price     = 300,
                Title     = "Test Product2",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });

            await context.Products.AddRangeAsync(productsInsideUserCart);

            await context.Users.AddAsync(new User
            {
                UserName      = username,
                Email         = "*****@*****.**",
                LastLoginDate = DateTime.UtcNow,
            });

            await context.SaveChangesAsync();

            await shopService.BuyProductAsync(username, product1);

            await shopService.BuyProductAsync(username, product2);

            await shopService.BuyProductAsync(username, product3);

            var shippingCompany = ShippingCompany.Econt;

            Assert.False(await shopService.CheckoutSignedInUserAsync(username, shippingCompany));
        }
Beispiel #16
0
        public async Task TestIfReturnsCorrectNumberOfProducts(string username)
        {
            var context        = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var productService = new ProductServices(context);
            var shopService    = new ShopServices(context, productService);


            var productsInsideUserCart = new List <Product>();

            productsInsideUserCart.Add(new Product
            {
                Id        = "Product",
                Price     = 300,
                Title     = "Test Product",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });


            productsInsideUserCart.Add(new Product
            {
                Id        = "Product1",
                Price     = 300,
                Title     = "Test Product1",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });

            productsInsideUserCart.Add(new Product
            {
                Id        = "Product2",
                Price     = 300,
                Title     = "Test Product2",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });

            await context.Products.AddRangeAsync(productsInsideUserCart);

            await context.Users.AddAsync(new User
            {
                UserName      = username,
                Email         = "*****@*****.**",
                LastLoginDate = DateTime.UtcNow,
            });

            await context.SaveChangesAsync();

            await shopService.BuyProductAsync(username, "Product2");

            await shopService.BuyProductAsync(username, "Product");

            await shopService.BuyProductAsync(username, "Product1");


            var numberOfProducts = await shopService.GetNumberOfProductsAsync(username);

            Assert.Equal(3, numberOfProducts);
        }
Beispiel #17
0
        public async Task TestIfReturnsSpecificProductsForUserCart(string username)
        {
            //Arrange
            var context        = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var productService = new ProductServices(context);
            var shopService    = new ShopServices(context, productService);

            var productsInsideUserCart = new List <Product>();

            productsInsideUserCart.Add(new Product
            {
                Id        = "Product",
                Price     = 300,
                Title     = "Test Product",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });


            productsInsideUserCart.Add(new Product
            {
                Id        = "Product1",
                Price     = 300,
                Title     = "Test Product1",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });

            productsInsideUserCart.Add(new Product
            {
                Id        = "Product2",
                Price     = 300,
                Title     = "Test Product2",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });

            await context.Products.AddRangeAsync(productsInsideUserCart);

            await context.Users.AddAsync(new User
            {
                UserName      = username,
                Email         = "*****@*****.**",
                LastLoginDate = DateTime.UtcNow,
            });

            await context.SaveChangesAsync();

            await shopService.BuyProductAsync(username, "Product2");

            await shopService.BuyProductAsync(username, "Product");

            await shopService.BuyProductAsync(username, "Product1");

            var result = await shopService.GetAllCartProductsAsync(username);

            Assert.Equal(3, result.Count);
            Assert.True(result.Any(x => x.Product.Title.Contains("Test Product")));
        }
        public async Task TestIfCharacteristicsExistsReturnsFalse()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var characteristicsService = new Areas.Administration.Services.AdminCharacteristicsServices(context);

            Assert.False(await characteristicsService.CharacteristicsExistsAsync("Laptops"));
        }
        public async Task TestIfPageExistsReturnsFalse(string pageName)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var adminPageService = new Areas.Administration.Services.AdminIndexPageServices(context);

            Assert.False(await adminPageService.PageExistsAsync(pageName));
        }
Beispiel #20
0
        public async Task TestIfGetShipmentsReturnsEmptyCollection(int page)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var shipmentManager = new ShipmentManagerServices(context);

            Assert.Empty(await shipmentManager.GetShipmentsAsync(page));
        }
        public async Task TestIfPageAlreadyExistsReturnsFalse(string category)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var categoryPagesService = new Areas.Administration.Services.AdminCategoryPagesServices(context);

            Assert.False(await categoryPagesService.PageAlreadyExistsAsync(category));
        }
        public async Task TestIfGetMostExpensiveProductsReturnEmptyCollection()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var chartsService = new SupportChartsService(context);

            Assert.Empty(await chartsService.GetMostExpensiveProductsAsync());
        }
        public async Task TestIfGetAllChatRequestsReturnsEmptyCollection()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var chatRequests = new RequestChatServices(context);

            Assert.Empty(await chatRequests.GetAllChatRequestsAsync());
        }
        public async Task TestIfConnectionAlreadyEstablishedReturnsFalse(string connectionId, string subject, string email, string technicianName)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var chatRequests = new RequestChatServices(context);

            Assert.False(await chatRequests.ConnectionAlreadyEstablishedAsync(connectionId, "StoreUser"));
        }
        public async Task TestIfGetAvailableCharacteristicsReturnsEmptyCollection()
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var characteristicsService = new Areas.Administration.Services.AdminCharacteristicsServices(context);

            Assert.Empty(await characteristicsService.GetAvailableCharacteristicsAsync());
        }
        public async Task TestIfCategoryExistsReturnsFalse(string categoryName)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var characteristicsService = new Areas.Administration.Services.AdminCharacteristicsServices(context);

            Assert.False(await characteristicsService.CategoryExistsAsync(categoryName));
        }
        public async Task TestIfConnectionIdExistsReturnsFalse(string connectionId)
        {
            var context = PCHUBDbContextInMemoryInitializer.InitializeContext();

            var chatRequests = new RequestChatServices(context);

            Assert.False(await chatRequests.ConnectionIdExistsAsync(connectionId));
        }
        public async Task TestIfCategoryExistsReturnsFalse()
        {
            var context        = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var productService = new ProductServices(context);


            Assert.False(await productService.CategoryExistsAsync("NonExisting"));
        }
Beispiel #29
0
        public async Task TestWhenAddToFavoritesReturnsFalse(string username, string productId)
        {
            var context            = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var productService     = new ProductServices(context);
            var userProfileService = new UserProfileServices(context, TestUserManager <User>(), productService);

            Assert.False(await userProfileService.AddToFavoritesAsync(username, productId));
        }
Beispiel #30
0
        public async Task TestIfAddToFavoritesThrowsErrorForInvalidUser(string username, string product1,
                                                                        string product2, string product3)
        {
            var context            = PCHUBDbContextInMemoryInitializer.InitializeContext();
            var productService     = new ProductServices(context);
            var userProfileService = new UserProfileServices(context, TestUserManager <User>(), productService);

            var products = new List <Product>();

            products.Add(new Product
            {
                Id        = product1,
                Price     = 300,
                Title     = "Test Product",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });


            products.Add(new Product
            {
                Id        = product2,
                Price     = 300,
                Title     = "Test Product1",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });

            products.Add(new Product
            {
                Id        = product3,
                Price     = 300,
                Title     = "Test Product2",
                IsDeleted = false,
                CreatedOn = DateTime.Now,
            });

            await context.Products.AddRangeAsync(products);

            await context.SaveChangesAsync();


            await Assert.ThrowsAsync <NullReferenceException>(async() =>
            {
                await userProfileService.AddToFavoritesAsync(username, product1);
            });

            await Assert.ThrowsAsync <NullReferenceException>(async() =>
            {
                await userProfileService.AddToFavoritesAsync(username, product2);
            });

            await Assert.ThrowsAsync <NullReferenceException>(async() =>
            {
                await userProfileService.AddToFavoritesAsync(username, product3);
            });
        }