public void AddProductToDb_ProductIsAdded_ProductIsFoundInDb()
        {
            var product = new Product() { ProductName = "TestProduct" };
            _storemanager.AddProductToDb(product);

            Assert.That(_unit.Products.FindProduct("TestProduct"), Is.EqualTo(product));
        }
        public void AddProductToMyStore_ProductIsAddedToTestStore_HasARelationCanBeFoundForProductAndStore()
        {
            var product = new Product() { ProductName = "TestProduct" };
            _storemanager.AddProductToMyStore(product, 24);

            Assert.AreNotEqual(_context.HasARelation.Find(_storemanager.Store.StoreId, product.ProductId), null);
        }
        public void AutoCompleteProduct_LookUpWordStartsWithK_ReturnListOfSize1()
        {
            var kakaoProduct = new Product() { ProductName = "Kakao" };
            _products.Add(kakaoProduct);

            _unitWork.Products.FindProductStartingWith("K").Returns(_products);
            Assert.That(_uut.AutoCompleteProduct("K").Count, Is.EqualTo(1));
        }
        public void AddProductToDb_ProductIsAlreadyInDb_ReturnMinus1()
        {
            var product = new Product() { ProductName = "TestProduct" };
            _context.Products.Add(product);
            _context.SaveChanges();

            Assert.That(_storemanager.AddProductToDb(product), Is.EqualTo(-1));
        }
예제 #5
0
        /// <summary>
        ///     Add product to database
        /// </summary>
        /// <param name="product"></param>
        /// <returns>-1 if product is not found and return 0 if product is added</returns>
        public int AddProductToDb(Product product)
        {
            if (FindProduct(product.ProductName) != null)
                return -1;

            _unitwork.Products.Add(product);
            _unitwork.Complete();
            return 0;
        }
        public void AddProductToMyStore_ProductIsAlreadyAddedToTestStore_ReturnMinus1()
        {
            var product = new Product() { ProductName = "TestProduct" };
            _context.Products.Add(product);
            _context.SaveChanges();
            var hasA = new HasA() {Price = 22, Product = product, Store = _storemanager.Store, StoreId = _storemanager.Store.StoreId, ProductId = product.ProductId};
            _context.HasARelation.Add(hasA);
            _context.SaveChanges();

            Assert.That(_storemanager.AddProductToMyStore(product, 24), Is.EqualTo(-1));
        }
        public void FindProductInStore_TestProductIsSoldInStore_TestIsReturned()
        {
            _context.Stores.Add(_store);
            var product = new Product() {ProductName = "TestProduct"};
            _context.Products.Add(product);
            _context.SaveChanges();
            var hasA = new HasA() {Product = product, ProductId = product.ProductId, Store = _store, StoreId = _store.StoreId, Price = 10};
            _context.HasARelation.Add(hasA);
            _context.SaveChanges();

            Assert.That(_storeRepository.FindProductInStore(_store.StoreName, product.ProductName).Name, Is.EqualTo(product.ProductName));
        }
        public void AutoCompleteProduct_LookUpWordStartsWithB_ReturnListOfSize3()
        {
            var bananProduct = new Product() { ProductName = "Banan" };
            var baconProduct = new Product() { ProductName = "Bacon" };
            var bollerProduct = new Product() { ProductName = "Boller" };
            var brombaerProduct = new Product() { ProductName = "Brombaer" };
            _products.Add(baconProduct);
            _products.Add(bananProduct);
            _products.Add(bollerProduct);
            _products.Add(brombaerProduct);

            _unitWork.Products.FindProductStartingWith("B").Returns(_products);
            Assert.That(_uut.AutoCompleteProduct("B").Count, Is.EqualTo(3));
        }
        public void FindProductsInStore_FindProductsSoldByStore_ListWithProductsReturnedContaining3Elements()
        {
            var banan = new Product() {ProductName = "Banan"};
            var tomat = new Product() {ProductName = "Tomat"};
            var bacon = new Product() {ProductName = "Bacon"};

            _context.Products.Add(bacon);
            _context.Products.Add(tomat);
            _context.Products.Add(banan);
            _context.Stores.Add(_store);
            _context.SaveChanges();

            _context.HasARelation.Add(new HasA() { Price = 3.95, Store = _store, Product = tomat, ProductId = tomat.ProductId, StoreId = _store.StoreId });
            _context.HasARelation.Add(new HasA() { Price = 2.95, Store = _store, Product = banan, ProductId = banan.ProductId, StoreId = _store.StoreId });
            _context.HasARelation.Add(new HasA() { Price = 1.95, Store = _store, Product = bacon, ProductId = bacon.ProductId, StoreId = _store.StoreId });
            _context.SaveChanges();

            Assert.That(_storeRepository.FindProductsInStore(_store.StoreName).Count, Is.EqualTo(3));
        }
        public void FindProductsInStoreStartingWith_TestProductsIsSoldInStore_ListContaining3ElementsAreReturned()
        {
            _context.Stores.Add(_store);
            var product1 = new Product() { ProductName = "TestProduct1" };
            var product2 = new Product() { ProductName = "TestProduct2" };
            var product3 = new Product() { ProductName = "TestProduct3" };
            _context.Products.Add(product1);
            _context.Products.Add(product2);
            _context.Products.Add(product3);
            _context.SaveChanges();
            var hasA1 = new HasA() { Product = product1, ProductId = product1.ProductId, Store = _store, StoreId = _store.StoreId, Price = 10 };
            var hasA2 = new HasA() { Product = product2, ProductId = product2.ProductId, Store = _store, StoreId = _store.StoreId, Price = 11 };
            var hasA3 = new HasA() { Product = product3, ProductId = product3.ProductId, Store = _store, StoreId = _store.StoreId, Price = 12 };
            _context.HasARelation.Add(hasA1);
            _context.HasARelation.Add(hasA2);
            _context.HasARelation.Add(hasA3);
            _context.SaveChanges();

            Assert.That(_storeRepository.FindProductsInStoreStartingWith(_store.StoreName, "Test").Count, Is.EqualTo(3));
        }
        public void FindCheapestStoreForAllProductsWithSum_AldiAndFøtexSellsTestAndTest1ButFaktaOnlySellsTest_ReturnAListContaing4Elements()
        {
            var føtex = new Store() { StoreName = "Føtex" };
            var aldi = new Store() { StoreName = "Aldi" };
            var fakta = new Store() { StoreName = "Fakta" };
            var test1 = new Product() {ProductName = "Test1"};

            _context.Stores.Add(føtex);
            _context.Stores.Add(aldi);
            _context.Stores.Add(fakta);
            _context.Products.Add(_prod);
            _context.SaveChanges();
            _context.HasARelation.Add(new HasA() { Price = 2.95, Store = føtex, Product = _prod, ProductId = _prod.ProductId, StoreId = føtex.StoreId });
            _context.HasARelation.Add(new HasA() { Price = 4.95, Store = føtex, Product = test1, ProductId = test1.ProductId, StoreId = føtex.StoreId });
            _context.HasARelation.Add(new HasA() { Price = 1.95, Store = aldi, Product = _prod, ProductId = _prod.ProductId, StoreId = aldi.StoreId });
            _context.HasARelation.Add(new HasA() { Price = 5.95, Store = aldi, Product = test1, ProductId = test1.ProductId, StoreId = aldi.StoreId });
            _context.HasARelation.Add(new HasA() { Price = 1.95, Store = fakta, Product = _prod, ProductId = _prod.ProductId, StoreId = fakta.StoreId });
            _context.SaveChanges();

            Assert.That(_productRepository.FindCheapestStoreForAllProductsWithSum(new List<ProductInfo>() { new ProductInfo("Test") , new ProductInfo("Test1")}).Count, Is.EqualTo(4));
        }
예제 #12
0
        /// <summary>
        ///     Add product to storemanagers store with price
        /// </summary>
        /// <param name="product"></param>
        /// <param name="price"></param>
        /// <returns>-1 if the product exist in that store and 0 if it has been added</returns>
        public int AddProductToMyStore(Product product, double price)
        {
            if (_unitwork.HasA.Get(Store.StoreId, product.ProductId) != null)
                return -1;

            var hasA = new HasA
            {
                Price = price,
                Product = product,
                Store = Store,
                ProductId = product.ProductId,
                StoreId = Store.StoreId
            };

            _unitwork.HasA.Add(hasA);
            product.HasARelation.Add(hasA);
            Store.HasARelation.Add(hasA);

            _unitwork.Complete();
            return 0;
        }
        public void AutoCompleteProductForOneStore_3ProductsStartingWithBa_ReturnsAListContaining3Elements()
        {
            var bacon = new Product() { ProductName = "Bacon" };
            var banan = new Product() { ProductName = "Banan" };
            var bambus = new Product() { ProductName = "Bambus" };
            var store = new Store() {StoreName = "TestStore"};
            _context.Stores.Add(store);
            _context.Products.Add(bacon);
            _context.Products.Add(banan);
            _context.Products.Add(bambus);
            _context.SaveChanges();
            var hasA1 = new HasA() {Product = bacon, ProductId = bacon.ProductId, Store = store, StoreId = store.StoreId, Price = 12};
            var hasA2 = new HasA() { Product = banan, ProductId = banan.ProductId, Store = store, StoreId = store.StoreId, Price = 13 };
            var hasA3 = new HasA() { Product = bambus, ProductId = bambus.ProductId, Store = store, StoreId = store.StoreId, Price = 14 };
            _context.HasARelation.Add(hasA1);
            _context.HasARelation.Add(hasA2);
            _context.HasARelation.Add(hasA3);
            _context.SaveChanges();

            Assert.That(_autoCom.AutoCompleteProductForOneStore("TestStore", "Ba").Count, Is.EqualTo(3));
        }
        public void Complete_SavesTheChangesToTheDatabase_ProductFoundInDatabase()
        {
            var banan = new Product() { ProductName = "Banan" };
            var føtex = new Store() {StoreName = "Føtex"};

            _context.Products.Add(banan);
            _context.Stores.Add(føtex);
            _context.SaveChanges();
            var hasA = new HasA()
            {
                Price = 3.95,
                Store = føtex,
                Product = banan,
                ProductId = banan.ProductId,
                StoreId = føtex.StoreId
            };
            _context.HasARelation.Add(hasA);
            _context.SaveChanges();

            Assert.That(_unitOfWork.HasA.FindHasA(føtex.StoreName, banan.ProductName), Is.EqualTo(hasA));
        }
        public void AddProductToDb_ProductIsAdded_Return0()
        {
            var product = new Product() {ProductName = "TestProduct"};

            Assert.That(_storemanager.AddProductToDb(product), Is.EqualTo(0));
        }
 public void SetUp()
 {
     _unitWork = Substitute.For<IUnitOfWork>();
     _store = new Store() {StoreName = "Aldi", StoreId = 22};
     _product = new Product() {ProductName = "Banan", ProductId = 10};
     _uut = new Storemanager(_unitWork, _store);
 }
        public void RemoveProductFromMyStore_RemovalOfProductSuccesfull_Return0()
        {
            var product = new Product() { ProductName = "TestProduct" };
            _context.Products.Add(product);
            _context.SaveChanges();
            var hasA = new HasA() { Price = 22, Product = product, Store = _storemanager.Store, StoreId = _storemanager.Store.StoreId, ProductId = product.ProductId };
            _context.HasARelation.Add(hasA);
            _context.SaveChanges();

            Assert.That(_storemanager.RemoveProductFromMyStore(product), Is.EqualTo(0));
        }
        public void RemoveProductFromMyStore_ProductNoLongerHasAnyRelationsToAnyStore_ProductCannotBeFoundInDb()
        {
            var product = new Product() { ProductName = "TestProduct" };
            _context.Products.Add(product);
            _context.SaveChanges();
            var hasA = new HasA() { Price = 22, Product = product, Store = _storemanager.Store, StoreId = _storemanager.Store.StoreId, ProductId = product.ProductId };
            _context.HasARelation.Add(hasA);
            _context.SaveChanges();

            _storemanager.RemoveProductFromMyStore(product);

            Assert.That(_unit.Products.FindProduct("TestProduct"), Is.EqualTo(null));
        }
        public void RemoveProductFromMyStore_ProductIsNotInStore_HasARelationCannotBeFoundForProductAndStore()
        {
            var product = new Product() { ProductName = "TestProduct" };
            _context.Products.Add(product);
            _context.SaveChanges();

            Assert.That(_storemanager.RemoveProductFromMyStore(product), Is.EqualTo(-1));
        }
        public void SetUp()
        {
            var context = new DataContext();
            _unit = new UnitOfWork(context);
            context.Database.Connection.ConnectionString = "Server=.\\SQLEXPRESS;Database=Pristjek220Data.DataContext; Trusted_Connection=True;";
            context.Database.ExecuteSqlCommand("dbo.TestCleanTable");
            _store = new Store() {StoreName = "TestStore"};
            _unit.Stores.Add(_store);
            _product = new Product() {ProductName = "Testproduct"};
            _unit.Products.Add(_product);
            _unit.Complete();
            _unit.HasA.Add(new HasA() {Product = _product, ProductId = _product.ProductId, Store = _store, StoreId = _store.StoreId, Price = 10});
            _unit.Complete();

            _manager = new Storemanager(_unit, _store);
            _autocomplete = new Autocomplete(_unit);
            _createMsgBox = Substitute.For<ICreateMsgBox>();
            _changePriceModel = new ChangePriceModel(_manager, _autocomplete, _createMsgBox);
            _deleteProductModel = new DeleteProductModel(_manager, _autocomplete, _createMsgBox);
        }
 public void FindCheapestStoreWithSumForListOfProducts_2StoresSellsTestProductAndTestProduct1_ReturnsTheCheapestStoreWithPriceOf12()
 {
     var product1 = new Product() {ProductName = "TestProduct1"};
     _context.Products.Add(product1);
     var hasA3 = new HasA() {};
     var list = new List<ProductInfo>() { new ProductInfo(_product.ProductName, "1") };
     Assert.That(_consumer.FindCheapestStoreWithSumForListOfProducts(list).Price, Is.EqualTo(12));
 }
예제 #22
0
        /// <summary>
        ///     Remove the requested product from the storemanagers store, and if the product got no other relations remove the
        ///     product too
        /// </summary>
        /// <param name="product"></param>
        /// <returns>-1 if the product does not exist and 0 if it has been removed successfully</returns>
        public int RemoveProductFromMyStore(Product product)
        {
            var hasA = _unitwork.HasA.FindHasA(Store.StoreName, product.ProductName);

            if (hasA == null)
                return -1;

            hasA.Product.HasARelation.Remove(hasA);
            Store.HasARelation.Remove(hasA);
            _unitwork.HasA.Remove(hasA);

            if (product.HasARelation.Count == 0)
                _unitwork.Products.Remove(product);

            _unitwork.Complete();

            return 0;
        }
        public void AddProductToMyStore_ProductIsAddedToTestStore_Return0()
        {
            var product = new Product() { ProductName = "TestProduct" };

            Assert.That(_storemanager.AddProductToMyStore(product, 24), Is.EqualTo(0));
        }
예제 #24
0
 /// <summary>
 ///     Changes the price of the requested product
 /// </summary>
 /// <param name="product"></param>
 /// <param name="price"></param>
 public void ChangePriceOfProductInStore(Product product, double price)
 {
     var hasA = _unitwork.HasA.Get(Store.StoreId, product.ProductId);
     hasA.Price = price;
     _unitwork.Complete();
 }
        public void ChangePriceOfProductInStore_PriceOfTestProductInStoreIsSetTo10_HasARelationWithNewPriceCanBeFoundInDb()
        {
            var product = new Product() { ProductName = "TestProduct" };
            _context.Products.Add(product);
            _context.SaveChanges();
            var hasA = new HasA() { Price = 22, Product = product, Store = _storemanager.Store, StoreId = _storemanager.Store.StoreId, ProductId = product.ProductId };
            _context.HasARelation.Add(hasA);
            _context.SaveChanges();

            _storemanager.ChangePriceOfProductInStore(product, 10);

            Assert.That(_context.HasARelation.Find(_storemanager.Store.StoreId, product.ProductId).Price, Is.EqualTo(10));
        }
        public void FindProductInStore_TestProductIsInDbAndInStore_PriceOfReturnedObjectIsEqualToHasARelationsPrice()
        {
            var product = new Product() { ProductName = "TestProduct" };
            _context.Products.Add(product);
            _context.SaveChanges();
            var hasA = new HasA() { Price = 22, Product = product, Store = _storemanager.Store, StoreId = _storemanager.Store.StoreId, ProductId = product.ProductId };
            _context.HasARelation.Add(hasA);
            _context.SaveChanges();

            Assert.That(_storemanager.FindProductInStore(product.ProductName).Price, Is.EqualTo(hasA.Price));
        }
        public void SetUp()
        {
            _context = new DataContext();
            _unit = new UnitOfWork(_context);
            _context.Database.Connection.ConnectionString = "Server=.\\SQLEXPRESS;Database=Pristjek220Data.DataContext; Trusted_Connection=True;MultipleActiveResultSets=True;";
            _context.Database.ExecuteSqlCommand("dbo.TestCleanTable");

            //Opsætning af 2 forretninger der begge har samme vare
            _product = new Product() { ProductName = "TestProduct" };
            _store = new Store() { StoreName = "TestStore" };
            _store1 = new Store() { StoreName = "TestStore1" };
            _context.Products.Add(_product);
            _context.Stores.Add(_store);
            _context.Stores.Add(_store1);
            _context.SaveChanges();
            _hasA = new HasA() { Product = _product, Store = _store, ProductId = _product.ProductId, StoreId = _store.StoreId, Price = 12 };
            _hasA1 = new HasA() { Product = _product, Store = _store1, ProductId = _product.ProductId, StoreId = _store1.StoreId, Price = 13 };
            _context.HasARelation.Add(_hasA);
            _context.HasARelation.Add(_hasA1);
            _context.SaveChanges();

            _consumer = new Consumer.Consumer(_unit);
        }
        public void FindProduct_TestProductIsInDb_TestProductIsReturned()
        {
            var product = new Product() { ProductName = "TestProduct" };
            _context.Products.Add(product);
            _context.SaveChanges();

            Assert.That(_storemanager.FindProduct("TestProduct"), Is.EqualTo(product));
        }
 public void SetUp()
 {
     _context = new DataContext();
     _prod = new Product() {ProductName = "Test"};
     _context.Database.Connection.ConnectionString = "Server=.\\SQLEXPRESS;Database=Pristjek220Data.DataContext; Trusted_Connection=True;";
     _context.Database.ExecuteSqlCommand("dbo.TestCleanTable");
     _productRepository = new ProductRepository(_context);
 }
        public void RemoveProductFromMyStore_ProductIsInStore_HasARelationCannotBeFoundForProductAndStore()
        {
            var product = new Product() { ProductName = "TestProduct" };
            _context.Products.Add(product);
            _context.SaveChanges();
            var hasA = new HasA() { Price = 22, Product = product, Store = _storemanager.Store, StoreId = _storemanager.Store.StoreId, ProductId = product.ProductId };
            _context.HasARelation.Add(hasA);
            _context.SaveChanges();

            _storemanager.RemoveProductFromMyStore(product);

            Assert.That(_context.HasARelation.Find(_storemanager.Store.StoreId, product.ProductId), Is.EqualTo(null));
        }