public void AddReviewShouldAddReview(int rating, int expected)
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: $"AddReviews_Product_Database")
                          .Options;

            var dbContext      = new XeonDbContext(options);
            var productService = new ProductsService(dbContext);

            var parentCategory = new ParentCategory {
                Name = "Computers"
            };
            var childCategory = new ChildCategory {
                Name = "Cables", ParentCategory = parentCategory
            };

            dbContext.ChildCategories.Add(childCategory);
            dbContext.SaveChanges();

            var product = new Product {
                Name = "USB ", ChildCategory = childCategory
            };

            dbContext.Products.Add(product);
            dbContext.SaveChanges();

            productService.AddReview(rating, product.Id);

            Assert.Equal(expected, product.Reviews.Count());
        }
        public void DeleteChildCategoryWithProductsShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteChildCategory_ChildCategories_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var parentCategoryName = "Computers";

            dbContext.ParentCategories.Add(new ParentCategory {
                Name = parentCategoryName
            });
            dbContext.SaveChanges();

            var parentCategory = dbContext.ParentCategories.FirstOrDefault(x => x.Name == parentCategoryName);

            var childCategoriesService = new ChildCategoriesService(dbContext);

            var childCategoryName        = "Cables";
            var childCategoryDescription = "USB";
            var childCategory            = childCategoriesService.CreateChildCategory(childCategoryName, childCategoryDescription, parentCategory.Id);

            childCategory.Products = new List <Product> {
                new Product {
                    Name = "Headsets"
                }
            };
            dbContext.SaveChanges();

            var isChildCategoryDeleted = childCategoriesService.DeleteChildCategory(childCategory.Id);

            Assert.False(isChildCategoryDeleted);
            Assert.Equal(1, dbContext.ChildCategories.Count());
        }
        public void GetProductsFilterShouldFilterProducts(string test, int expected, string searchString, int?childCategoryId)
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: $"{test}_GetProductsFilter_Product_Database")
                          .Options;

            var dbContext      = new XeonDbContext(options);
            var productService = new ProductsService(dbContext);

            var parentCategory = new ParentCategory {
                Name = "Computers"
            };
            var childCategories = new List <ChildCategory>
            {
                new ChildCategory {
                    Name = "Cables", ParentCategory = parentCategory
                },
                new ChildCategory {
                    Name = "Monitors", ParentCategory = parentCategory
                }
            };

            dbContext.ChildCategories.AddRange(childCategories);
            dbContext.SaveChanges();

            dbContext.Products.AddRange(new List <Product>
            {
                new Product {
                    Name = "USB Cable", ChildCategory = childCategories.First()
                },
                new Product {
                    Name = "Adapter Cable", ChildCategory = childCategories.First()
                },
                new Product {
                    Name = "Keyboard", ChildCategory = childCategories.First()
                },
                new Product {
                    Name = "Computer", ChildCategory = childCategories.First()
                },
                new Product {
                    Name = "Monitor LG", ChildCategory = childCategories.Last()
                },
            });
            dbContext.SaveChanges();

            if (childCategoryId.HasValue && childCategoryId.Value == 1)
            {
                childCategoryId = childCategories.First().Id;
            }

            var products = productService.GetProductsFilter(searchString, childCategoryId);

            Assert.Equal(expected, products.Count());
        }
        public void OrderByShouldOrderProducts(string test, ProductsSort productsSort, string productName)
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: $"{test}_OrderBy_Product_Database")
                          .Options;

            var dbContext      = new XeonDbContext(options);
            var productService = new ProductsService(dbContext);

            var parentCategory = new ParentCategory {
                Name = "Computers"
            };
            var childCategories = new List <ChildCategory>
            {
                new ChildCategory {
                    Name = "Cables", ParentCategory = parentCategory
                },
                new ChildCategory {
                    Name = "Monitors", ParentCategory = parentCategory
                }
            };

            dbContext.ChildCategories.AddRange(childCategories);
            dbContext.SaveChanges();

            dbContext.Products.AddRange(new List <Product>
            {
                new Product {
                    Name = "USB Cable", Price = 33, ChildCategory = childCategories.First()
                },
                new Product {
                    Name = "Adapter Cable", Price = 28, ChildCategory = childCategories.First()
                },
                new Product {
                    Name = "Keyboard", Price = 45, ChildCategory = childCategories.First()
                },
                new Product {
                    Name = "Computer", Price = 11, ChildCategory = childCategories.First()
                },
                new Product {
                    Name = "Monitor LG", Price = 36, ChildCategory = childCategories.Last()
                },
            });
            dbContext.SaveChanges();

            var products        = productService.GetVisibleProducts();
            var orderedProducts = productService.OrderBy(products, productsSort);

            Assert.Equal(productName, orderedProducts.First().Name);
        }
        public void AddImageUrlsShouldAddImageUrls()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "AddImageUrls_Product_Database")
                          .Options;

            var dbContext      = new XeonDbContext(options);
            var productService = new ProductsService(dbContext);

            var parentCategory = new ParentCategory {
                Name = "Computers"
            };
            var childCategory = new ChildCategory {
                Name = "Cables", ParentCategory = parentCategory
            };

            dbContext.ChildCategories.Add(childCategory);
            dbContext.SaveChanges();

            var productName = "USB";

            dbContext.Products.AddRange(new List <Product>
            {
                new Product {
                    Name = productName, ChildCategory = childCategory
                },
                new Product {
                    Name = "Cable", ChildCategory = childCategory
                },
                new Product {
                    Name = "Keyboard", ChildCategory = childCategory
                },
                new Product {
                    Name = "Computer", ChildCategory = childCategory
                },
            });
            dbContext.SaveChanges();

            var productId = dbContext.Products.FirstOrDefault(x => x.Name == productName).Id;
            var imageUrls = new List <string> {
                "wwwroot/image1", "wwwroot/image2", "wwwroot/image3"
            };

            productService.AddImageUrls(productId, imageUrls);

            var product = dbContext.Products.FirstOrDefault(x => x.Id == productId);

            Assert.Equal(3, product.Images.Count);
        }
        public void AddImageUrlShouldReturnTrueAndAddImageUrl()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "AddImageUrly_ChildCategories_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            dbContext.ParentCategories.Add(new ParentCategory {
                Name = "Computers"
            });
            dbContext.SaveChanges();

            var parentCategoryName = "Computers";
            var parentCategory     = dbContext.ParentCategories.FirstOrDefault(x => x.Name == parentCategoryName);

            var childCategoriesService = new ChildCategoriesService(dbContext);

            var childCategoryName = "Cables";
            var childCategory     = childCategoriesService.CreateChildCategory(childCategoryName, null, parentCategory.Id);

            var isImageUrlCreated = childCategoriesService.AddImageUrl(childCategory.Id);

            var childCategoryExpectedImageUrl = string.Format(GlobalConstants.CHILD_CATEGORY_PATH_TEMPLATE, childCategory.Id);

            Assert.Equal(childCategoryExpectedImageUrl, childCategory.ImageUrl);
            Assert.True(isImageUrlCreated);
        }
        public void GetChildCategoryByIdShouldReturnChildCategory()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetChildCategoryById_ChildCategories_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var parentCategory = new ParentCategory {
                Name = "Computers"
            };

            dbContext.ChildCategories.AddRange(new List <ChildCategory>
            {
                new ChildCategory {
                    Id = 1, Name = "Cables", ParentCategory = parentCategory
                },
                new ChildCategory {
                    Id = 2, Name = "Monitors", ParentCategory = parentCategory
                }
            });
            dbContext.SaveChanges();

            var childCategoriesService = new ChildCategoriesService(dbContext);
            var childCategory          = childCategoriesService.GetChildCategoryById(1);

            Assert.Equal("Cables", childCategory.Name);
        }
Esempio n. 8
0
        public void GetSupplierByIdShouldReturnSupplier()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetSupplierById_Supplier_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var suppliersService = new SuppliersService(dbContext);

            var supplierId   = 1;
            var supplierName = "Econt";
            var suppliers    = new List <Supplier>
            {
                new Supplier {
                    Id = supplierId, Name = supplierName, IsDefault = true
                },
                new Supplier {
                    Id = 2, Name = "DHL", IsDefault = false
                },
            };

            dbContext.Suppliers.AddRange(suppliers);
            dbContext.SaveChanges();

            var supplier = suppliersService.GetSupplierById(supplierId);

            Assert.Equal(supplierName, supplier.Name);
        }
Esempio n. 9
0
        public void EditLastNameRequstsShouldEditLastName()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "EditLastName_Users_Database")
                          .Options;

            var dbContext = new XeonDbContext(options);

            var user = new XeonUser
            {
                UserName = "******",
                LastName = "AdminLastName"
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var store       = new Mock <IUserStore <XeonUser> >();
            var userManager = new Mock <UserManager <XeonUser> >(store.Object, null, null, null, null, null, null, null, null);

            var usersService = new UsersService(dbContext, userManager.Object);

            var lastName = "UserLastName";

            usersService.EditLastName(user, lastName);

            Assert.Equal(lastName, user.LastName);
        }
Esempio n. 10
0
        public void CreateShouldCreateSupplierAndIsDefaultShouldStayFalse()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateIsDefaultFalse_Supplier_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var suppliersService = new SuppliersService(dbContext);

            dbContext.Suppliers.Add(new Supplier {
                Name = "Econt", IsDefault = true
            });
            dbContext.SaveChanges();

            var name          = "DHL";
            var priceToHome   = 5.5M;
            var priceToOffice = 4.5M;

            suppliersService.Create(name, priceToHome, priceToOffice);

            var supplier = dbContext.Suppliers.FirstOrDefault(x => x.Name == name);

            Assert.NotNull(supplier);
            Assert.Equal(name, supplier.Name);
            Assert.Equal(priceToHome, supplier.PriceToHome);
            Assert.Equal(priceToOffice, supplier.PriceToOffice);
            Assert.False(supplier.IsDefault);
        }
        public void ProductExistsShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "ProductNotExists_Product_Database")
                          .Options;

            var dbContext      = new XeonDbContext(options);
            var productService = new ProductsService(dbContext);

            dbContext.Products.AddRange(new List <Product>
            {
                new Product {
                    Name = "USB"
                },
                new Product {
                    Name = "Cable"
                },
                new Product {
                    Name = "Keyboard"
                },
                new Product {
                    Name = "Computer"
                },
            });
            dbContext.SaveChanges();

            var invalidProductId = 123;
            var isProductExist   = productService.ProductExists(invalidProductId);

            Assert.False(isProductExist);
        }
        public void AnyProductsShouldReturnFalseWhenThereAreNotAnyProducts()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: $"АnyProductsFalse_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var user = new XeonUser {
                UserName = "******", ShoppingCart = new ShoppingCart()
            };

            dbContext.Users.Add(user);

            var product = new Product {
                Name = "USB Cable"
            };

            dbContext.Products.Add(product);
            dbContext.SaveChanges();

            var userService = new Mock <IUsersService>();

            userService.Setup(r => r.GetUserByUsername(user.UserName))
            .Returns(user);

            var productService = new Mock <IProductsService>();

            var shoppingCartsService = new ShoppingCartsService(dbContext, productService.Object, userService.Object);
            var areThereAnyProducts  = shoppingCartsService.AnyProducts(user.UserName);

            Assert.False(areThereAnyProducts);
        }
        public void GetRequestByIdShouldReturnUserRequest()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetRequestById_UserRequests_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var userRequestsService = new UserRequestsService(dbContext);

            var userRequestId    = 1;
            var userRequestTitle = "Request-1";

            dbContext.UserRequests.AddRange(new List <UserRequest>
            {
                new UserRequest {
                    Id = userRequestId, Title = userRequestTitle
                },
                new UserRequest {
                    Id = 2, Title = "Request-2"
                },
                new UserRequest {
                    Id = 3, Title = "Request-3"
                },
            });
            dbContext.SaveChanges();

            var userRequest = userRequestsService.GetRequestById(userRequestId);

            Assert.Equal(userRequestTitle, userRequest.Title);
            Assert.Equal(userRequestId, userRequest.Id);
        }
        public void DeleteShouldReturnTrueAndDeleteUserRequest()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "Delete_UserRequests_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var userRequestsService = new UserRequestsService(dbContext);

            var userRequestId    = 1;
            var userRequestTitle = "Request-1";

            dbContext.UserRequests.AddRange(new List <UserRequest>
            {
                new UserRequest {
                    Id = userRequestId, Title = userRequestTitle, Seen = true
                },
                new UserRequest {
                    Id = 2, Title = "Request-2"
                },
                new UserRequest {
                    Id = 3, Title = "Request-3"
                },
            });
            dbContext.SaveChanges();

            var isDeleted = userRequestsService.Delete(userRequestId);

            var userRequest = dbContext.UserRequests.FirstOrDefault(x => x.Id == userRequestId);

            Assert.Null(userRequest);
            Assert.True(isDeleted);
        }
        public void GetUnseenRequestsShouldReturneAllGetUnSeenRequests()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetUnseenRequests_UserRequests_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var userRequestsService = new UserRequestsService(dbContext);

            var userRequestId    = 1;
            var userRequestTitle = "Request-1";

            dbContext.UserRequests.AddRange(new List <UserRequest>
            {
                new UserRequest {
                    Id = userRequestId, Title = userRequestTitle, Seen = true
                },
                new UserRequest {
                    Id = 2, Title = "Request-2"
                },
                new UserRequest {
                    Id = 3, Title = "Request-3"
                },
            });
            dbContext.SaveChanges();

            var unseenRequests = userRequestsService.GetUnseenRequests();

            Assert.Equal(2, unseenRequests.Count());
        }
        public void UnseenShouldChangeIsSeenOnFalse()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "Unseen_UserRequests_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var userRequestsService = new UserRequestsService(dbContext);

            var userRequestId    = 1;
            var userRequestTitle = "Request-1";

            dbContext.UserRequests.AddRange(new List <UserRequest>
            {
                new UserRequest {
                    Id = userRequestId, Title = userRequestTitle, Seen = true
                },
                new UserRequest {
                    Id = 2, Title = "Request-2"
                },
                new UserRequest {
                    Id = 3, Title = "Request-3"
                },
            });
            dbContext.SaveChanges();

            userRequestsService.Unseen(userRequestId);

            var userRequest = dbContext.UserRequests.FirstOrDefault(x => x.Id == userRequestId);

            Assert.False(userRequest.Seen);
        }
Esempio n. 17
0
        public void MakeDafaultShouldSwapDefaultSupplier()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "MakeDafaultSwap_Supplier_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var suppliersService = new SuppliersService(dbContext);

            var suppliers = new List <Supplier>
            {
                new Supplier {
                    Name = "Econt", IsDefault = true
                },
                new Supplier {
                    Name = "DHL", IsDefault = false
                },
            };

            dbContext.Suppliers.AddRange(suppliers);
            dbContext.SaveChanges();

            suppliersService.MakeDafault(suppliers.Last().Id);

            Assert.False(suppliers.First().IsDefault);
            Assert.True(suppliers.Last().IsDefault);
        }
        public void HideInvalidProducShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "RemoveInvalid_Product_Database")
                          .Options;

            var dbContext      = new XeonDbContext(options);
            var productService = new ProductsService(dbContext);

            dbContext.Products.AddRange(new List <Product>
            {
                new Product {
                    Name = "USB"
                },
                new Product {
                    Name = "Cable"
                },
                new Product {
                    Name = "Keyboard"
                },
                new Product {
                    Name = "Computer"
                },
            });
            dbContext.SaveChanges();

            var invalidProductId = 123;
            var isProductDeleted = productService.HideProduct(invalidProductId);

            Assert.False(isProductDeleted);
            Assert.Equal(4, dbContext.Products.Count());
        }
Esempio n. 19
0
        public void EditShouldEditSupplier()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "Edit_Supplier_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var suppliersService = new SuppliersService(dbContext);

            var supplier = new Supplier
            {
                Name          = "DHL",
                PriceToHome   = 4.5M,
                PriceToOffice = 5.5M
            };

            dbContext.Suppliers.Add(supplier);
            dbContext.SaveChanges();

            var name          = "econt";
            var priceToHome   = 3.5M;
            var priceToOffice = 3M;

            suppliersService.Edit(supplier.Id, name, priceToHome, priceToOffice);

            Assert.Equal(name, supplier.Name);
            Assert.Equal(priceToHome, supplier.PriceToHome);
            Assert.Equal(priceToOffice, supplier.PriceToOffice);
        }
        public void AddProductInShoppingCartWithInvalidProductShouldNotAddProduct()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "AddProductInShoppingCartWithInvalidProduct_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var username = "******";
            var user     = new XeonUser {
                UserName = username, ShoppingCart = new ShoppingCart()
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var userService = new Mock <IUsersService>();

            userService.Setup(r => r.GetUserByUsername(username))
            .Returns(dbContext.Users.FirstOrDefault(x => x.UserName == username));

            var     productId      = 1;
            Product product        = null;
            var     productService = new Mock <IProductsService>();

            productService.Setup(p => p.GetProductById(productId))
            .Returns(product);

            var shoppingCartsService = new ShoppingCartsService(dbContext, productService.Object, userService.Object);

            shoppingCartsService.AddProductInShoppingCart(productId, username);

            var shoppingCartProducts = dbContext.ShoppingCartProducts.ToList();

            Assert.Empty(shoppingCartProducts);
        }
        public void EditProductProductShouldEditProduct()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_Product_Database")
                          .Options;

            var dbContext      = new XeonDbContext(options);
            var productService = new ProductsService(dbContext);

            var product = new Product
            {
                Name          = "USB",
                ParnersPrice  = 31,
                Price         = 39,
                Specification = "1.1"
            };

            dbContext.Products.Add(product);
            dbContext.SaveChanges();

            product.Name          = "NewName";
            product.ParnersPrice  = 11;
            product.Price         = 10;
            product.Specification = "2.0";
            productService.EditProduct(product);

            var editedProduct = dbContext.Products.FirstOrDefault(x => x.Name == product.Name);

            Assert.Equal(product.Name, editedProduct.Name);
            Assert.Equal(product.ParnersPrice, editedProduct.ParnersPrice);
            Assert.Equal(product.Price, editedProduct.Price);
            Assert.Equal(product.Specification, editedProduct.Specification);
        }
Esempio n. 22
0
        public void GetUsersWithPartnersRequstsShouldReturnAllUsersWithPartnersRequst()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetUsersWithPartnersRequsts_Users_Database")
                          .Options;

            var dbContext = new XeonDbContext(options);

            dbContext.Users.AddRange(new List <XeonUser>
            {
                new XeonUser {
                    UserName = "******", PartnerRequest = new PartnerRequest()
                },
                new XeonUser {
                    UserName = "******", PartnerRequest = new PartnerRequest()
                },
                new XeonUser {
                    UserName = "******",
                },
                new XeonUser {
                    UserName = "******",
                }
            });
            dbContext.SaveChanges();

            var store       = new Mock <IUserStore <XeonUser> >();
            var userManager = new Mock <UserManager <XeonUser> >(store.Object, null, null, null, null, null, null, null, null);

            var usersService = new UsersService(dbContext, userManager.Object);

            var users = usersService.GetUsersWithPartnersRequsts();

            Assert.Equal(2, users.Count());
        }
        public void EditChildCategoryShouldReturnTrueAndEditCorrectlyChildCategory()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "EditChildCategory_ChildCategories_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var parentCategoryName = "Computers";

            dbContext.ParentCategories.Add(new ParentCategory {
                Name = parentCategoryName
            });
            dbContext.SaveChanges();

            var parentCategory = dbContext.ParentCategories.FirstOrDefault(x => x.Name == parentCategoryName);

            var childCategoriesService = new ChildCategoriesService(dbContext);

            var childCategoryName        = "Cables";
            var childCategoryDescription = "USB";
            var childCategory            = childCategoriesService.CreateChildCategory(childCategoryName, childCategoryDescription, parentCategory.Id);

            var newChildCategoryName        = "Monitors";
            var newChildCategoryDescription = "17''";
            var isChildCategoryEdit         = childCategoriesService.EditChildCategory(childCategory.Id, newChildCategoryName, newChildCategoryDescription, parentCategory.Id);

            var childCategoryExpectedImageUrl = string.Format(GlobalConstants.CHILD_CATEGORY_PATH_TEMPLATE, childCategory.Id);

            Assert.Equal(newChildCategoryName, childCategory.Name);
            Assert.Equal(newChildCategoryDescription, childCategory.Description);
            Assert.True(isChildCategoryEdit);
        }
Esempio n. 24
0
        public void GetDiliveryPriceShouldReturnDiliveryPrice()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetDiliveryPrice_Supplier_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var suppliersService = new SuppliersService(dbContext);

            var suppliers = new List <Supplier>
            {
                new Supplier {
                    Name = "Econt", PriceToHome = 4.5M, PriceToOffice = 3.5M
                },
                new Supplier {
                    Name = "DHL", PriceToHome = 3.2M, PriceToOffice = 2.8M
                },
            };

            dbContext.Suppliers.AddRange(suppliers);
            dbContext.SaveChanges();

            var homeDeliveryPrice   = suppliersService.GetDiliveryPrice(suppliers.First().Id, DeliveryType.Home);
            var officeDeliveryPrice = suppliersService.GetDiliveryPrice(suppliers.First().Id, DeliveryType.Office);

            Assert.Equal(homeDeliveryPrice, suppliers.First().PriceToHome);
            Assert.Equal(officeDeliveryPrice, suppliers.First().PriceToOffice);
        }
        public void HideProductShouldChangeHiteToTrue()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "Remove_Product_Database")
                          .Options;

            var dbContext      = new XeonDbContext(options);
            var productService = new ProductsService(dbContext);

            var productName = "USB";

            dbContext.Products.AddRange(new List <Product>
            {
                new Product {
                    Name = productName
                },
                new Product {
                    Name = "Cable"
                },
                new Product {
                    Name = "Keyboard"
                },
                new Product {
                    Name = "Computer"
                },
            });
            dbContext.SaveChanges();

            var product = dbContext.Products.FirstOrDefault(x => x.Name == productName);

            var isProductHide = productService.HideProduct(product.Id);

            Assert.True(isProductHide);
            Assert.True(product.Hide);
        }
        public void EditChildCategoryWhithInvaliParentCategoryIdShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "EditChildCategory_ChildCategories_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var parentCategoryName = "Computers";

            dbContext.ParentCategories.Add(new ParentCategory {
                Name = parentCategoryName
            });
            dbContext.SaveChanges();

            var parentCategory = dbContext.ParentCategories.FirstOrDefault(x => x.Name == parentCategoryName);

            var childCategoriesService = new ChildCategoriesService(dbContext);

            var childCategoryName        = "Cables";
            var childCategoryDescription = "USB";
            var childCategory            = childCategoriesService.CreateChildCategory(childCategoryName, childCategoryDescription, parentCategory.Id);

            var newChildCategoryName        = "Monitors";
            var newChildCategoryDescription = "17''";
            var invalidParentCategoryId     = 121;
            var isChildCategoryEdit         = childCategoriesService.EditChildCategory(childCategory.Id, newChildCategoryName, newChildCategoryDescription, invalidParentCategoryId);

            Assert.False(isChildCategoryEdit);
        }
Esempio n. 27
0
        public void GetUserCompanyByUsernameShouldReturnCurrentUserCompany()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetUserCompanyByUsername_Users_Database")
                          .Options;

            var dbContext = new XeonDbContext(options);

            var mockUserStore = new Mock <IUserStore <XeonUser> >();
            var userManager   = new Mock <UserManager <XeonUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            var usersService = new UsersService(dbContext, userManager.Object);

            var user = new XeonUser
            {
                UserName = "******",
                Company  = new Company {
                    Name = "Computers Ltd"
                }
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var company = usersService.GetUserCompanyByUsername(user.UserName);

            Assert.Equal(user.Company.Name, company.Name);
        }
        public void DeleteChildCategoryShouldReturnTrueAndDeleteChildCategory()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteChildCategoryCorrect_ChildCategories_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var parentCategoryName = "Computers";

            dbContext.ParentCategories.Add(new ParentCategory {
                Name = parentCategoryName
            });
            dbContext.SaveChanges();

            var parentCategory = dbContext.ParentCategories.FirstOrDefault(x => x.Name == parentCategoryName);

            var childCategoriesService = new ChildCategoriesService(dbContext);

            var childCategoryName        = "Cables";
            var childCategoryDescription = "USB";
            var childCategory            = childCategoriesService.CreateChildCategory(childCategoryName, childCategoryDescription, parentCategory.Id);

            var isChildCategoryDeleted = childCategoriesService.DeleteChildCategory(childCategory.Id);

            Assert.Equal(0, dbContext.ChildCategories.Count());
            Assert.True(isChildCategoryDeleted);
        }
Esempio n. 29
0
        public void CreateCompanyShouldCreateUserCompanyAndReturTrue()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateCompany_Users_Database")
                          .Options;

            var dbContext = new XeonDbContext(options);

            var user = new XeonUser
            {
                UserName = "******",
            };

            dbContext.Users.Add(user);
            dbContext.SaveChanges();

            var mockUserStore = new Mock <IUserStore <XeonUser> >();
            var userManager   = new Mock <UserManager <XeonUser> >(mockUserStore.Object, null, null, null, null, null, null, null, null);

            userManager.Setup(m => m.FindByNameAsync(user.UserName))
            .Returns(Task.FromResult <XeonUser>(user));

            var usersService = new UsersService(dbContext, userManager.Object);


            var company = new Company {
                Name = "Computers Ltd"
            };
            var isCreated = usersService.CreateCompany(company, user.UserName);

            Assert.True(isCreated);
            Assert.Equal(company.Name, user.Company.Name);
        }
Esempio n. 30
0
        public void DeleteDefaultSupplierShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <XeonDbContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteDefaultSupplier_Supplier_Database")
                          .Options;
            var dbContext = new XeonDbContext(options);

            var suppliersService = new SuppliersService(dbContext);

            var suppliers = new List <Supplier>
            {
                new Supplier {
                    Name = "Econt", IsDefault = true
                },
                new Supplier {
                    Name = "DHL", IsDefault = false
                },
            };

            dbContext.Suppliers.AddRange(suppliers);
            dbContext.SaveChanges();

            var isDeleted = suppliersService.Delete(suppliers.First().Id);

            Assert.Equal(2, dbContext.Suppliers.Count());
            Assert.False(isDeleted);
        }