public void SelectAll_Should_Return_All_Products()
        {
            SqlProductRepository  productRepository = new SqlProductRepository(connectionString);
            ICollection <Product> products          = productRepository.SelectAll();

            Assert.Equal(9, products.Count);
        }
        public void GetProductPrices_Returns_Correct_Prices()
        {
            // Arrange
            Product product1 = GetProductWithName("Name1");
            Product product2 = GetProductWithName("Name2");

            product2.Id = 2;
            ProductContext ctx = new ProductContext(new DbContextOptions <ProductContext>());

            ctx.Products = GetProductDbSet(product1, product2);
            ProductPrice price1a = GetPrice(product1);
            ProductPrice price1b = GetPrice(product1);
            ProductPrice price2a = GetPrice(product2);
            ProductPrice price2b = GetPrice(product2);

            ctx.Prices = GetPricesDbSet(price1a, price1b, price2a, price2b);
            SqlProductRepository target = new SqlProductRepository(ctx);

            // Act
            var result = target.GetProductPrices(2);

            // Assert
            Assert.Contains(price2a, result);
            Assert.Contains(price2b, result);
        }
Esempio n. 3
0
        private void retrieveProducts_Click(object sender, EventArgs e)
        {
            SqlProductRepository    products    = new SqlProductRepository(connectionString);
            IReadOnlyList <Product> productList = products.RetrieveProducts();

            dataGridView1.DataSource = productList;
        }
Esempio n. 4
0
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["CommerceObjectContext"].ConnectionString;

            var productRepository  = new SqlProductRepository(connectionString);
            var basketRepository   = new SqlBasketRepository(connectionString);
            var discountRepository = new SqlDiscountRepository(connectionString);

            var discountPolicy = new RepositoryBasketDiscountPolicy(discountRepository);

            var basketService = new BasketService(basketRepository, discountPolicy);

            var currencyProvider = new CachingCurrencyProvider(new SqlCurrencyProvider(connectionString), TimeSpan.FromHours(1));

            if (controllerType == typeof(BasketController))
            {
                return(new BasketController(basketService, currencyProvider));
            }

            if (controllerType == typeof(HomeController))
            {
                return(new HomeController(productRepository, currencyProvider));
            }

            return(base.GetControllerInstance(requestContext, controllerType));
        }
        public IProductManagementService ResolveProductManagementService()
        {
            string connectionString =
                ConfigurationManager.ConnectionStrings
                ["CommerceObjectContext"].ConnectionString;

            // Inner Product Repository
            ProductRepository sqlRepository =
                new SqlProductRepository(connectionString);

            IAuditor sqlAuditor =
                new SqlAuditor(connectionString);

            // Decorator class
            ProductRepository auditingRepository =
                new AuditingProductRepository(
                    sqlRepository, sqlAuditor);

            IContractMapper mapper = new ContractMapper();

            // Injection of Decorator to use it as an interceptor of
            // the inner class functionality
            return(new ProductManagementService(
                       auditingRepository, mapper));
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            var productRepository = new SqlProductRepository("sql1");
            var productService    = new ProductService(productRepository);
            var myProducts        = productService.GetProducts();

            WriteLine($"Product found: {myProducts.Count()} using Sql engine 1");
        }
 public void SutIsProductRepository(SqlProductRepository sut)
 {
     // Fixture setup
     // Exercise system
     // Verify outcome
     Assert.IsAssignableFrom <ProductRepository>(sut);
     // Teardown
 }
 public async Task Delete()
 {
     using (var contex = new ApplicationDbContext(_options))
     {
         var repository = new SqlProductRepository(contex);
         await repository.Remove(3);
     }
 }
 public void SutIsProductRepository(SqlProductRepository sut)
 {
     // Fixture setup
     // Exercise system
     // Verify outcome
     Assert.IsAssignableFrom<ProductRepository>(sut);
     // Teardown
 }
 public void ConnectionStringIsCorrect([Frozen]string expectedConnectionString, SqlProductRepository sut)
 {
     // Fixture setup
     // Exercise system
     string result = sut.ConnectionString;
     // Verify outcome
     Assert.Equal(expectedConnectionString, result);
     // Teardown
 }
        ResolveProductManagementService()
        {
            ProductRepository repository =
                new SqlProductRepository(
                    this.connectionString);

            return(new ProductManagementService(
                       repository, this.mapper));
        }
        public void Delete_ProductNotInDataStore_ShouldReturnFalse()
        {
            //arrange
            SqlProductRepository productRepository = new SqlProductRepository(connectionString);
            //act
            bool deleted = productRepository.Delete("z1");

            //assert
            Assert.False(deleted);
        }
        public void Indexer_ReturnsMatchingProduct()
        {
            //arrange
            SqlProductRepository productRepository = new SqlProductRepository(connectionString);
            //act
            Product product = productRepository["p4"];

            //assert
            Assert.Equal("p4", product.Id);
            Assert.Equal("Spaghetti", product.Name);
        }
Esempio n. 14
0
        private void GetProductQuantityButton_Click(object sender, EventArgs e)
        {
            SqlProductRepository products = new SqlProductRepository(connectionString);

            try
            {
                productList = products.FetchProductQuantity(Convert.ToInt32(TypeIDTextbox.Text));
            }catch (Exception ex)
            {
                MessageBox.Show("Incorrect input. Parameter takes an integer.");
            }
        }
        public IProductManagementService ResolveProductManagementService()
        {
            var repository = new SqlProductRepository(this.connectionString);
            var srvc       = new ProductManagementService(repository, this.mapper);

            lock (this.syncRoot)
            {
                this.repositories.Add(srvc, repository);
            }

            return(srvc);
        }
        public void Create_Product_ShouldAddProduct()
        {
            //arrange
            SqlProductRepository productRepository = new SqlProductRepository(connectionString);
            Product product = new Product("p11", "Hammer", 2.20);
            //act
            bool created = productRepository.Create(product);

            //assert
            Assert.True(created);
            Assert.Contains(product, productRepository.SelectAll());
        }
        public void Delete_Product_ShouldRemoveProduct()
        {
            //arrange
            SqlProductRepository productRepository = new SqlProductRepository(connectionString);
            //act
            bool deleted = productRepository.Delete("p1");

            //assert
            Assert.True(deleted);
            Assert.DoesNotContain(productRepository.SelectAll(), p => p.Id == "p1");
            Assert.Equal(8, productRepository.SelectAll().Count);
        }
Esempio n. 18
0
        protected override async Task <TransportationMovementGoodsInfoViewModel> CreateMovementGoodInfoAsync(Product product)
        {
            SqlProductRepository productRepository = new SqlProductRepository();

            return(new TransportationMovementGoodsInfoViewModel
            {
                IdProduct = product.Id,
                Price = await productRepository.GetCurrentPrice(product.Id),
                MovementGoods = MovementGoodsReport,
                Product = product,
                Count = 0
            });
        }
Esempio n. 19
0
        private void ProductsRatingButton_Click(object sender, EventArgs e)
        {
            SqlProductRepository    products    = new SqlProductRepository(connectionString);
            IReadOnlyList <Product> productList = products.RetrieveHighestRatings();

            dataGridView1.DataSource = productList;

            for (int i = 0; i < dataGridView1.Columns.Count; i++)
            {
                DataGridViewColumn columnOne = dataGridView1.Columns[0];
                columnOne.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
        }
Esempio n. 20
0
 public StoreService(SqlProductRepository productRepository, SqlCategoryRepository categoryRepository)
 {
     if (productRepository == null)
     {
         throw new ArgumentNullException(nameof(productRepository));
     }
     if (categoryRepository == null)
     {
         throw new ArgumentNullException(nameof(categoryRepository));
     }
     _productRepository  = productRepository;
     _categoryRepository = categoryRepository;
 }
        // NOTE Allows dependencies to be released when no longer needed
        public IProductManagementService ResolveProductManagementService()
        {
            // Create Product Repository
            var repository = new SqlProductRepository(this.connectionString);
            var srvc       = new ProductManagementService(repository, this.mapper);

            // need to lock dictionary to ensure concurrent requests don't overwrite each other
            lock (this.syncRoot)
            {
                this.repositories.Add(srvc, repository);
            }

            return(srvc);
        }
        public IProductManagementService ResolveProductManagementService()
        {
            string connectionString =
                ConfigurationManager.ConnectionStrings
                ["CommerceObjectContext"].ConnectionString;

            ProductRepository repository =
                new SqlProductRepository(connectionString);

            IContractMapper mapper = new ContractMapper();

            return(new ProductManagementService(repository,
                                                mapper));
        }
Esempio n. 23
0
        private void UpdateProductButton_Click(object sender, EventArgs e)
        {
            try
            {
                ProductsData ed = new ProductsData();

                SqlProductRepository products = new SqlProductRepository(connectionString);
                products.UpdateProduct(Convert.ToInt32(ProductIdTextbox.Text), SKUTextbox.Text, ProductNameTextbox.Text, Convert.ToInt32(ProductTypeIDTextbox.Text), Convert.ToInt32(QuantityTextbox.Text), DescriptionTextbox.Text, PriceTextbox.Text, RatingTextbox.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        public void Update_Product_ShouldUpdateProduct()
        {
            //arrange
            SqlProductRepository productRepository = new SqlProductRepository(connectionString);
            Product product = productRepository.SelectAll().First(p => p.Id == "p1");

            product.CostPrice = 1.6;
            //act
            bool updated = productRepository.Update(product);

            //assert
            Assert.True(updated);
            Assert.Equal(1.6, productRepository.SelectAll().First(p => p.Id == "p1").CostPrice);
        }
Esempio n. 25
0
        public static void TestSqlEngine1()
        {
            // We first initialise the repository we want to use
            // to retrieve the products data from a specific datastore
            // In this test case we select to use 'sql1' database engine
            var productRepository = new SqlProductRepository("sql1");
            // We then create the products service instance by injecting the repo
            var productService = new ProductService(productRepository);
            // We query the products from db
            var myProducts = productService.GetProducts();

            // We test if we got any products back
            Assert.AreEqual(myProducts.Any(), true);
        }
        public void GetProductByName_Returns_Product_If_Correct_Name()
        {
            // Arrange
            Product        product = GetProductWithName("Name");
            ProductContext ctx     = new ProductContext(new DbContextOptions <ProductContext>());

            ctx.Products = GetProductDbSet(product);
            SqlProductRepository target = new SqlProductRepository(ctx);

            // Act
            var result = target.GetProductByName("Name");

            // Assert
            Assert.IsAssignableFrom <Product>(result);
        }
        public async Task AddProductTest()
        {
            using (var contex = new ApplicationDbContext(_options))
            {
                var repository = new SqlProductRepository(contex);
                await repository.Create(new Domain.Product()
                {
                    Title = "test", Model = "a", Price = 10
                });

                var result = repository.GetList();

                Assert.True(await result.CountAsync() > 0);
            }
        }
        public void GetProductByName_Returns_Null_If_No_Product_Found()
        {
            // Arrange
            Product        product = GetProductWithName("Name");
            ProductContext ctx     = new ProductContext(new DbContextOptions <ProductContext>());

            ctx.Products = GetProductDbSet(product);
            SqlProductRepository target = new SqlProductRepository(ctx);

            // Act
            var result = target.GetProductByName("FalseName");

            // Assert
            Assert.Null(result);
        }
Esempio n. 29
0
        private void retrieveProductTypeCount_Click(object sender, EventArgs e)
        {
            SqlProductRepository             products    = new SqlProductRepository(connectionString);
            IReadOnlyList <ProductTypeCount> productList = products.RetrieveProductCount();

            dataGridView1.DataSource = productList;

            for (int i = 0; i < dataGridView1.Columns.Count; i++)
            {
                DataGridViewColumn columnTwo = dataGridView1.Columns[1];
                columnTwo.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

                DataGridViewColumn columnThree = dataGridView1.Columns[2];
                columnThree.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            }
        }
        public Controller Create(ControllerContext cc, Type controllerType)
        {
            // Create Scoped components
            var context           = new CommerceContext(this.configuration.ConnectionString).TrackDisposable(cc);
            var productRepository = new SqlProductRepository(context);
            var orderRepository   = new SqlOrderRepository(context);

            // Create Transient components
            switch (controllerType.Name)
            {
            case nameof(HomeController):
                return(new HomeController());

            case nameof(InventoryController):
                return(new InventoryController(
                           productRepository,
                           this.Decorate(
                               context,
                               new AdjustInventoryService(
                                   new SqlInventoryRepository(context),
                                   this.Handler <InventoryAdjusted>(context)))));

            case nameof(OrderController):
                return(new OrderController(
                           orderApprover: Decorate(
                               context,
                               new ApproveOrderService(
                                   orderRepository,
                                   this.Handler <OrderApproved>(context))),
                           orderCancellor: Decorate(
                               context,
                               new CancelOrderService(
                                   orderRepository,
                                   this.Handler <OrderCancelled>(context)))));

            case nameof(ProductController):
                return(new ProductController(
                           productRepository,
                           productDeleter: Decorate(context, new DeleteProductService(productRepository)),
                           productInserter: Decorate(context, new InsertProductService(productRepository)),
                           productUpdater: Decorate(context, new UpdateProductService(productRepository))));

            default:
                throw new InvalidOperationException($"Unknown controller {controllerType}.");
            }
        }
Esempio n. 31
0
        private void CreateProductButton_Click(object sender, EventArgs e)
        {
            try
            {
                SqlProductRepository products = new SqlProductRepository(connectionString);

                Product createProduct = products.CreateProduct(SKUTextbox.Text, NameTextbox.Text, Convert.ToInt32(TypeIdTextbox.Text), Convert.ToInt32(QuantityTextbox.Text), DescriptionTextBox.Text, PriceTextBox.Text, RatingTextbox.Text);
                list.Add(createProduct);

                ProductsData pd = new ProductsData();
                pd.dataGridView1.DataSource = list;
            }
            catch (Exception ex)
            {
                MessageBox.Show("There cannot be any empty or incorrectly entered parameters. Check submission.");
            }
        }
        public void GetProductById_Returns_Correct_Product()
        {
            // Arrange
            Product product1 = GetProductWithName("Name1");
            Product product2 = GetProductWithName("Name2");

            product2.Id = 2;
            ProductContext ctx = new ProductContext(new DbContextOptions <ProductContext>());

            ctx.Products = GetProductDbSet(product1, product2);
            SqlProductRepository target = new SqlProductRepository(ctx);

            // Act
            var result = target.GetProductById(2);

            // Assert
            Assert.StrictEqual(product2, result);
        }