public void TestRemoveShouldReturnVoidIfItemDoesNotExist()
        {
            //Arrange
            var uniqueId = Guid.NewGuid().ToString();

            var mockDatabaseContext = new Mock <IDatabaseContext>();


            mockDatabaseContext.Setup(c => c.ShopItems.Find(999))
            .Returns(new ShopItem
            {
                Id         = 999,
                CategoryId = 999
            });

            mockDatabaseContext.Setup(c => c.ShoppingCartItems)
            .Returns(new DatabaseContext(_options).ShoppingCartItems);

            var sut = new ShoppingCartItemRepository(mockDatabaseContext.Object);

            //Act
            sut.Remove(new ShoppingCartItem
            {
                ShopItemId     = 999,
                ShoppingCartId = uniqueId
            });


            //Assert
            mockDatabaseContext.Verify(d => d.ShoppingCartItems, Times.Once);
        }
        public void TestAddShouldThrowsArgumentNullExceptionWhenShoppingCartIdIsNull()
        {
            //Arrange
            var shoppingCartItem = new ShoppingCartItem
            {
                Id         = 999,
                ShopItemId = 999,
                ShopItem   = new ShopItem
                {
                    Id         = 999,
                    Name       = "TestItem",
                    CategoryId = 999
                },
                ShoppingCartId = null !,
                Amount         = 1
            };

            var mockDatabaseContext = new Mock <IDatabaseContext>();

            var sut = new ShoppingCartItemRepository(mockDatabaseContext.Object);

            //Act
            Assert.Throws <ArgumentNullException>(
                //Assert
                () => sut.Add(shoppingCartItem));
        }
        public void TestAddShouldThrowsArgumentExceptionWhenShopItemWithShopItemIdNotFound()
        {
            //Arrange
            var          uniqueId = Guid.NewGuid().ToString();
            const string expectedExceptionMessage = "Shop Item not found with ShopItemId";

            var shoppingCartItem = new ShoppingCartItem
            {
                Id         = 999,
                ShopItemId = 99,
                ShopItem   = new ShopItem
                {
                    Id         = 999,
                    Name       = "TestItem",
                    CategoryId = 999
                },
                ShoppingCartId = uniqueId,
                Amount         = 1
            };

            var mockDatabaseContext = new DatabaseContext(_options);

            var sut = new ShoppingCartItemRepository(mockDatabaseContext);

            //Act
            var exception = Assert.Throws <ArgumentException>(
                //Assert
                () => sut.Add(shoppingCartItem));

            Assert.Equal(expectedExceptionMessage, exception.Message);
        }
        public void TestClearShouldThrowArgumentNullExceptionWhenCartIdNull()
        {
            //Arrange
            using var context = new DatabaseContext(_options);
            var sut = new ShoppingCartItemRepository(context);

            //Act

            Assert.Throws <ArgumentNullException>(
                //Assert
                () => sut.Clear(null !));
        }
Example #5
0
        public UnitOfWork(OnlineStoreContext context)
        {
            _context = context;

            UserAddress = new UserAddressRepository(_context);
            Products    = new ProductRepository(_context);

            Orders     = new OrderRepository(_context);
            OrderItems = new OrderItemRepository(_context);

            ShoppingCarts     = new ShoppingCartRepository(_context);
            ShoppingCartItems = new ShoppingCartItemRepository(_context);
        }
        public void TestRemoveShouldThrowArgumentNullExceptionIfShoppingCartItemIsNull()
        {
            //Arrange

            var mockDatabaseContext = new Mock <IDatabaseContext>();

            var sut = new ShoppingCartItemRepository(mockDatabaseContext.Object);

            //Act

            Assert.Throws <ArgumentNullException>(
                //Assert
                () => sut.Remove(null !));
        }
        public UserFriendlyShoppingCart(DatabaseContext DatabaseContext, string UserAccount)
        {
            this._dbContext                  = DatabaseContext;
            this._userThumbPrint             = new UserThumbprint(UserAccount);
            this._shoppingCartItemRepository = new ShoppingCartItemRepository(this._dbContext);
            this._productRepository          = new ProductRepository(this._dbContext);

            this._items = new Dictionary <int, ShoppingCartItem>();

            // Load this user's shopping cart
            foreach (ShoppingCartItem sci in _shoppingCartItemRepository.GetAllForUser(this._userThumbPrint))
            {
                this.AddItem(sci);
            }
        }
        public void TestRemoveShouldReduceAmountIfMoreThanOneExists()
        {
            //Arrange
            var uniqueId = Guid.NewGuid().ToString();

            var expectedShoppingCartItem = new ShoppingCartItem
            {
                Id             = 999,
                ShopItemId     = 999,
                ShoppingCartId = uniqueId,
                Amount         = 5
            };


            using (var context = new DatabaseContext(_options))
            {
                var shopItem = context.ShopItems.Find(999);
                context.ShoppingCartItems.Add(new ShoppingCartItem
                {
                    Id             = 999,
                    ShopItem       = shopItem,
                    ShoppingCartId = uniqueId,
                    Amount         = 6
                });

                context.SaveChanges();
            }

            using (var context = new DatabaseContext(_options))
            {
                var sut = new ShoppingCartItemRepository(context);

                //Act
                sut.Remove(new ShoppingCartItem
                {
                    ShopItemId     = 999,
                    ShoppingCartId = uniqueId
                });

                var result = sut.GetAll();


                //Assert
                Assert.Contains(expectedShoppingCartItem, result);
            }
        }
        public void TestGetAllShouldReturnAllShoppingCartItemsIncludingShopItemProperty()
        {
            //Arrange
            var uniqueId = Guid.NewGuid().ToString();

            var expectedShoppingCartItem = new ShoppingCartItem
            {
                Id         = 999,
                Amount     = 1,
                ShopItemId = 999,
                ShopItem   = new ShopItem
                {
                    CategoryId = 999,
                    Id         = 999,
                    Name       = "TestShopItem"
                },
                ShoppingCartId = uniqueId
            };

            using (var context = new DatabaseContext(_options))
            {
                var shopItem = context.ShopItems.Find(999);

                context.ShoppingCartItems.Add(new ShoppingCartItem
                {
                    Id             = 999,
                    Amount         = 1,
                    ShopItem       = shopItem,
                    ShoppingCartId = uniqueId
                });

                context.SaveChanges();
            }

            using (var context = new DatabaseContext(_options))
            {
                var sut = new ShoppingCartItemRepository(context);

                //Act
                var result = sut.GetAll();

                //Assert
                Assert.Contains(expectedShoppingCartItem, result);
            }
        }
        public void TestAddShouldIncreaseTheAmountIfEntityExists()
        {
            //Arrange
            const int expectedShoppingCartItemsCount  = 1;
            const int expectedShoppingCartItemsAmount = 2;
            var       uniqueId = Guid.NewGuid().ToString();

            var shoppingCartItem = new ShoppingCartItem
            {
                Id         = 999,
                ShopItemId = 999,
                ShopItem   = new ShopItem
                {
                    Id         = 999,
                    Name       = "TestItem",
                    CategoryId = 999
                },
                ShoppingCartId = uniqueId,
                Amount         = 1
            };


            using var context = new DatabaseContext(_options);

            var sut = new ShoppingCartItemRepository(context);

            //Act
            sut.Add(shoppingCartItem);
            sut.Add(shoppingCartItem);


            var result = sut.GetAll().Where(s => s.ShoppingCartId == uniqueId);

            //Assert
            Assert.Equal(expectedShoppingCartItemsCount, result.Count());

            Assert.Equal(expectedShoppingCartItemsAmount, result.First().Amount);
        }
        public void TestAddShouldThrowsArgumentNullExceptionWhenShopItemIsNull()
        {
            //Arrange
            var uniqueId = Guid.NewGuid().ToString();

            var shoppingCartItem = new ShoppingCartItem
            {
                Id             = 999,
                ShopItemId     = 999,
                ShopItem       = null !,
                ShoppingCartId = uniqueId,
                Amount         = 1
            };

            var mockDatabaseContext = new Mock <IDatabaseContext>();

            var sut = new ShoppingCartItemRepository(mockDatabaseContext.Object);

            //Act
            Assert.Throws <ArgumentNullException>(
                //Assert
                () => sut.Add(shoppingCartItem));
        }
Example #12
0
 public AWUnitOfWork(AWContext context)
 {
     _context                = context;
     Address                 = new AddressRepository(context);
     BusinessEntity          = new BusinessEntityRepository(context);
     BusinessEntityAddress   = new BusinessEntityAddressRepository(context);
     PersonPhone             = new PersonPhoneRepository(context);
     StateProvince           = new StateProvinceRepository(context);
     Customer                = new CustomerRepository(context);
     SalesPerson             = new SalesPersonRepository(context);
     SalesOrderHeader        = new SalesOrderHeaderRepository(context);
     SalesOrderDetail        = new SalesOrderDetailRepository(context);
     ShoppingCartItem        = new ShoppingCartItemRepository(context);
     SalesTerritory          = new SalesTerritoryRepository(context);
     Product                 = new ProductRepository(context);
     ProductCategory         = new ProductCategoryRepository(context);
     ProductDescription      = new ProductDescriptionRepository(context);
     ProductInventory        = new ProductInventoryRepository(context);
     ProductListPriceHistory = new ProductListPriceHistoryRepository(context);
     ProductPhoto            = new ProductPhotoRepository(context);
     ProductProductPhoto     = new ProductProductPhotoRepository(context);
     Person = new PersonRepository(context);
 }
        public void TestRemoveShouldRemoveEntityIfOnlyOneExists()
        {
            //Arrange
            var uniqueId = Guid.NewGuid().ToString();

            using (var context = new DatabaseContext(_options))
            {
                var shopItem = context.ShopItems.Find(999);
                context.ShoppingCartItems.Add(new ShoppingCartItem
                {
                    Id             = 999,
                    ShopItem       = shopItem,
                    ShoppingCartId = uniqueId,
                    Amount         = 1
                });

                context.SaveChanges();
            }


            using (var context = new DatabaseContext(_options))
            {
                var sut = new ShoppingCartItemRepository(context);

                //Act
                sut.Remove(new ShoppingCartItem
                {
                    ShopItemId     = 999,
                    ShoppingCartId = uniqueId
                });

                var result = sut.GetAll();

                //Assert
                Assert.Empty(result);
            }
        }
        public void TestClearShouldEmptyCart()
        {
            //Arrange
            var       uniqueId    = Guid.NewGuid().ToString();
            var       testClearId = Guid.NewGuid().ToString();
            const int expectedShoppingCartItems = 1;

            var fixture = new OmitRecursionFixture();

            using (var context = new DatabaseContext(_options))
            {
                var shopItems = fixture
                                .Build <ShopItem>()
                                .Without(p => p.Id)
                                .With(p => p.CategoryId, 999)
                                .CreateMany().ToList();
                context.ShopItems.AddRange(shopItems);

                foreach (var item in shopItems)
                {
                    context.Add(new ShoppingCartItem
                    {
                        Id             = item.Id,
                        ShopItem       = item,
                        ShoppingCartId = testClearId,
                        Amount         = 1
                    });
                }

                var shopItem = context.ShopItems.Find(999);
                context.ShoppingCartItems.Add(new ShoppingCartItem
                {
                    Id             = 999,
                    ShopItem       = shopItem,
                    ShoppingCartId = uniqueId,
                    Amount         = 1
                });

                context.SaveChanges();
            }


            using (var context = new DatabaseContext(_options))
            {
                var sut = new ShoppingCartItemRepository(context);

                //Act

                sut.Clear(testClearId);
                context.SaveChanges();
            }

            using (var context = new DatabaseContext(_options))
            {
                var sut    = new ShoppingCartItemRepository(context);
                var result = sut.GetAll();
                //Assert


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

                Assert.NotNull(result.FirstOrDefault(i => i.ShoppingCartId == uniqueId));

                Assert.Null(result.FirstOrDefault(i => i.ShoppingCartId == testClearId));
            }
        }
Example #15
0
        public ECommerceUnitTests()
        {
            int.TryParse(ConfigurationManager.AppSettings["TwoFactorAuthTimeSpan"], out _twoFactorAuthTimeSpan);
            int.TryParse(ConfigurationManager.AppSettings["TwoFactorTimeOut"], out _twoFactorTimeOut);
            bool.TryParse(ConfigurationManager.AppSettings["TwoFactorEnabled"], out _twoFactorEnabled);
            _twoFactorAuthCookie    = ConfigurationManager.AppSettings["TwoFactorAuthCookie"];
            _twoFactorAuthSmtpHost  = ConfigurationManager.AppSettings["TwoFactorAuthSmtpHost"];
            _twoFactorAuthFromEmail = ConfigurationManager.AppSettings["TwoFactorAuthFromEmail"];
            _twoFactorAuthFromPhone = ConfigurationManager.AppSettings["TwoFactorAuthFromPhone"];
            _emailPassword          = ConfigurationManager.AppSettings["EmailPassword"];
            _authToken  = ConfigurationManager.AppSettings["TwilioAuthToken"];
            _accountSID = ConfigurationManager.AppSettings["TwilioAccountSID"];

            //Get payfabric configs
            _payfabricDeviceId       = ConfigurationManager.AppSettings["PayfabricDeviceId"];
            _payfabricDevicePassword = ConfigurationManager.AppSettings["PayfabricDevicePassword"];
            _payfabricDeviceUrl      = ConfigurationManager.AppSettings["PayfabricDeviceUrl"];


            var smsConfigs = new InitTwoFactor()
            {
                TwoFactorAuthTimeSpan  = _twoFactorAuthTimeSpan,
                TwoFactorAuthCookie    = _twoFactorAuthCookie,
                TwoFactorAuthSmtpHost  = _twoFactorAuthSmtpHost,
                TwoFactorAuthFromEmail = _twoFactorAuthFromEmail,
                TwoFactorAuthFromPhone = _twoFactorAuthFromPhone,
                AuthToken        = _authToken,
                AccountSID       = _accountSID,
                TwoFactorEnabled = _twoFactorEnabled,
                EmailPassword    = _emailPassword
            };

            _twoFactorAuth = new TwoFactorAuth(smsConfigs);

            //repositories
            var catalogSettings        = new CatalogSettings();
            var commonSettings         = new CommonSettings();
            var categoryRepository     = new CategoryRepository(connectionString);
            var productRepository      = new ProductRepository(connectionString);
            var productCategory        = new ProductCategoryMappingRepository(connectionString);
            var shoppingCartRepository = new ShoppingCartItemRepository(connectionString);

            var _pictureBinaryRepository = new PictureBinaryRepository(connectionString);
            var _pictureRepository       = new PictureRepository(connectionString);
            var _productAttributeCombinationRepository          = new ProductAttributeCombinationRepository(connectionString);
            var _productAttributeRepository                     = new ProductAttributeRepository(connectionString);
            var _productAttributeValueRepository                = new ProductAttributeValueRepository(connectionString);
            var _productAvailabilityRangeRepository             = new ProductAvailabilityRangeRepository(connectionString);
            var _productCategoryMappingRepository               = new ProductCategoryMappingRepository(connectionString);
            var _productProductAttributeMappingRepository       = new ProductProductAttributeMappingRepository(connectionString);
            var _productProductTagMappingRepository             = new ProductTagMappingRepository(connectionString);
            var _productSpecificationAttributeMappingRepository = new ProductSpecificationAttributeRepository(connectionString);
            var _specificationAttributeOptionRepository         = new SpecificationAttributeOptionRepository(connectionString);
            var _specificationAttributeRepository               = new SpecificationAttributeRepository(connectionString);
            var _productRepository = new ProductRepository(connectionString);
            var _productManufacturerMappingRepository = new ProductManufacturerMappingRepository(connectionString);
            var _productPictureRepository             = new ProductPictureRepository(connectionString);
            var _productReviewsRepository             = new ProductReviewsRepository(connectionString);
            var _tierPricesRepository                = new TierPricesRepository(connectionString);
            var _discountProductMappingRepository    = new DiscountProductMappingRepository(connectionString);
            var _productWarehouseInventoryRepository = new ProductWarehouseInventoryRepository(connectionString);
            var _customerRepository = new CustomerRepository(connectionString);

            //services
            _categoryService = new CategoryService(catalogSettings, commonSettings, categoryRepository, productRepository, productCategory);

            _menuService    = new MenuService(_categoryService);
            _cartService    = new CartService(commonSettings, shoppingCartRepository);
            _productService = new ProductService(
                _pictureBinaryRepository,
                _pictureRepository,
                _productAttributeCombinationRepository,
                _productAttributeRepository,
                _productAttributeValueRepository,
                _productAvailabilityRangeRepository,
                _productCategoryMappingRepository,
                _productProductAttributeMappingRepository,
                _productProductTagMappingRepository,
                _productSpecificationAttributeMappingRepository,
                _specificationAttributeOptionRepository,
                _specificationAttributeRepository,
                _productRepository,
                _productManufacturerMappingRepository,
                _productPictureRepository,
                _productReviewsRepository,
                _tierPricesRepository,
                _discountProductMappingRepository,
                _productWarehouseInventoryRepository
                );
            _customerService = new CustomerService(_customerRepository);
        }