Example #1
0
        /// <summary>
        ///     Takes a Username, password and storename, if the store does not exist and the password is not empty the Store will
        ///     be created in the database with the password
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="storeName"></param>
        /// <returns>-1 if store is not found, retruns -2 if password is empty and returns 1 if the login has been created</returns>
        public int CreateLogin(string userName, SecureString password, string storeName)
        {
            if (_unitOfWork.Stores.FindStore(storeName) != null)
            {
                return -1;
            }

            var code = ConvertToUnsecureString(password);

            if (code == "")
                return -2;

            using (var hash = SHA256.Create())
            {
                var enc = Encoding.UTF8;

                var input = code;
                var result = hash.ComputeHash(enc.GetBytes(input));

                var sb = new StringBuilder();
                foreach (var b in result)
                    sb.Append(b.ToString("x2"));
                code = sb.ToString();
            }

            var store = new Store {StoreName = storeName};
            AddStore(store);
            userName = char.ToUpper(userName[0]) + userName.Substring(1).ToLower();
            var login = new Login {Username = userName, Password = code, Store = store};
            _unitOfWork.Logins.Add(login);
            return _unitOfWork.Complete();
        }
 public void SetUp()
 {
     _unitWork = Substitute.For<IUnitOfWork>();
     _store = new Store() { StoreName = "Aldi" , StoreId = 22};
     _product = new Product() {ProductName = "Banan", ProductId = 10};
     _uut = new Consumer.Consumer(_unitWork);
 }
        public void AutoCompleteStore_LookUpWordStartsWithA_ReturnListOfSize1()
        {
            var aldiStore = new Store() { StoreName = "Aldi" };
            _stores.Add(aldiStore);

            _unitWork.Stores.FindStoreStartingWith("A").Returns(_stores);
            Assert.That(_uut.AutoCompleteStore("A").Count, Is.EqualTo(1));
        }
        public void FindCheapestStore_FindCheapestStoreForBanan_ReturnsStore()
        {
            var fakta = new Store() {StoreName = "Fakta"};
            _unitWork.Products.FindProduct(_product.ProductName).Returns(_product);
            _product.HasARelation.Add(new HasA() {Price = 2.95, Store = _store});
            _product.HasARelation.Add(new HasA() { Price = 1.95, Store = fakta });

            Assert.That(_uut.FindCheapestStore(_product.ProductName), Is.EqualTo(fakta));
        }
        public void FillOptionsStore_AddAdmin_OptionsStoresHaveTwoStores()
        {
            var adminStore = new Store() { StoreName = "Admin" };
            _context.Stores.Add(adminStore);
            _context.SaveChanges();

            var consumer = new Consumer.Consumer(_unit);

            Assert.That(consumer.OptionsStores.Count, Is.EqualTo(2));
        }
 public Storemanager(IUnitOfWork unitOfWork, Store store)
 {
     _unitwork = unitOfWork;
     var tmp = _unitwork.Stores.FindStore(store.StoreName);
     if (tmp != null)
     {
         Store = tmp;
         return;
     }
     Store = store;
 }
        public void FindCheapestStoreForAllProductsWithSum_4TestPriceIsMulipliedWithQuantity_ReturnAListWithPriceMultipied()
        {
            var føtex = new Store() { StoreName = "Føtex" };

            _context.Stores.Add(føtex);
            _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.SaveChanges();

            Assert.That(_productRepository.FindCheapestStoreForAllProductsWithSum(new List<ProductInfo>() { new ProductInfo("Test", "4")})[0].Price, Is.EqualTo(4*2.95));
        }
 public void ChangeWindowHomeCommand_ChangeWindowToHome_MainWindowTekstIsPristjek220ForbrugerStartside()
 {
     _uut.LogInCommand.Execute(this);
     _uut.Username = "******";
     var secureString = new SecureString();
     secureString.AppendChar('A');
     secureString.AppendChar('A');
     secureString.AppendChar('A');
     _uut.SecurePassword = secureString;
     Store loginstore = new Store() {StoreName = "Admin"};
     _logIn.CheckUsernameAndPassword(_uut.Username, secureString, ref loginstore).ReturnsForAnyArgs(0);
     Assert.That(_uut.Error, Is.EqualTo("Kodeordet er ugyldigt."));
 }
        public void FindCheapestStoreForAllProductsWithSum_AldiAndFøtexSellsTest_ReturnAListContaing2Elements()
        {
            var føtex = new Store() { StoreName = "Føtex" };
            var aldi = new Store() { StoreName = "Aldi" };

            _context.Stores.Add(føtex);
            _context.Stores.Add(aldi);
            _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 = 3.95, Store = aldi, Product = _prod, ProductId = _prod.ProductId, StoreId = aldi.StoreId });
            _context.SaveChanges();

            Assert.That(_productRepository.FindCheapestStoreForAllProductsWithSum(new List<ProductInfo>() { new ProductInfo("Test") }).Count, Is.EqualTo(2));
        }
        public void FindStoresThatSellsProduct_AldiAndFøtexSellsTest_ReturnAListContaing2Elements()
        {
            var aldi = new Store() {StoreName = "Aldi"};
            var føtex = new Store() {StoreName = "Føtex"};
            _context.Products.Add(_prod);
            _context.Stores.Add(aldi);
            _context.Stores.Add(føtex);
            _context.SaveChanges();

            _context.HasARelation.Add(new HasA() {Price = 2.95, Store = aldi, Product = _prod, ProductId = _prod.ProductId, StoreId = aldi.StoreId});
            _context.HasARelation.Add(new HasA() { Price = 2.95, Store = føtex, Product = _prod, ProductId = _prod.ProductId, StoreId = føtex.StoreId });
            _context.SaveChanges();

            Assert.That(_productRepository.FindStoresThatSellsProduct(_prod.ProductName).Count, Is.EqualTo(2));
        }
        public void CheckUsernameAndPassword_UsernameAndPasswdBothMatch_Return1()
        {
            Store store = new Store();
            var login = new Login() { Username = "******", Password = "******", Store = new Store() { StoreName = "TestStore" } };
            _context.Logins.Add(login);
            _context.SaveChanges();
            var pass = new SecureString();
            pass.AppendChar('p');
            pass.AppendChar('a');
            pass.AppendChar('s');
            pass.AppendChar('s');
            pass.AppendChar('w');
            pass.AppendChar('d');

            Assert.That(_login.CheckUsernameAndPassword("TestUser", pass, ref store), Is.EqualTo(1));
        }
        public void SetUp()
        {
            _context = new DataContext();
            _store = new Store() {StoreName = "TestStore"};
            _loginRepository = new LoginRepository(_context);
            _context.Database.Connection.ConnectionString = "Server=.\\SQLEXPRESS;Database=Pristjek220Data.DataContext; Trusted_Connection=True;";
            _context.Database.ExecuteSqlCommand("dbo.TestCleanTable");
            _context.Stores.Add(_store);
            _login = new Login() { Username = "******", Password = "******", Store = _store };
            _context.Logins.Add(_login);
            _context.SaveChanges();

            _passwd = new SecureString();
            _passwd.AppendChar('p');
            _passwd.AppendChar('a');
            _passwd.AppendChar('s');
            _passwd.AppendChar('s');
            _passwd.AppendChar('w');
            _passwd.AppendChar('d');
        }
        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));
        }
        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));
        }
Example #16
0
 /// <summary>
 ///     Checks if Username and password matches the database
 /// </summary>
 /// <param name="username"></param>
 /// <param name="securePassword"></param>
 /// <param name="store"></param>
 /// <returns>
 ///     -1 if the username is not in the database, return 1 if the username and password match and return 0 if it does
 ///     not match
 /// </returns>
 public int CheckUsernameAndPassword(string username, SecureString securePassword, ref Store store)
 {
     Login login;
     if ((login = _unitOfWork.Logins.CheckUsername(username)) == null) return -1;
     return (store = _unitOfWork.Logins.CheckLogin(securePassword, login)) != null ? 1 : 0;
 }
        public void FillOptionsStore_AddStore_OptionsStoresHaveThreeStores()
        {
            var NewStore = new Store() { StoreName = "NewStore" };
            _context.Stores.Add(NewStore);
            _context.SaveChanges();

            var consumer = new Consumer.Consumer(_unit);

            Assert.That(consumer.OptionsStores.Count, Is.EqualTo(3));
        }
        public void StoreNames_GetStoreNamesWithAdmin_UnitofWorkReturnsTwoStores()
        {
            var adminStore = new Store() { StoreName = "Admin" };
            _context.Stores.Add(adminStore);
            var list = _consumer.StoreNames;

            Assert.That(list.Count, Is.EqualTo(2));
        }
        public void CreateShoppingList_CreateShoppingListForBanan_ListHasCorrectPrice()
        {
            _uut.ShoppingListData.Add(new ProductInfo(_product.ProductName));

            var fakta = new Store() {StoreName = "Fakta"};
            _uut.OptionsStores.Add(new StoresInPristjek("Fakta"));
            _unitWork.Products.FindProduct(_product.ProductName).Returns(_product);
            _product.HasARelation.Add(new HasA() {Price = 2.95, Store = _store});
            _product.HasARelation.Add(new HasA() {Price = 1.95, Store = fakta});
            _store.HasARelation.Add(new HasA() {Price = 2.95, Product = _product, Store = _store});
            fakta.HasARelation.Add(new HasA() {Price = 1.95, Product = _product, Store = fakta});
            _uut.CreateShoppingList();

            Assert.That(_uut.TotalSum, Is.EqualTo(double.Parse("1,95", new CultureInfo("da-DK")).ToString() + " kr"));
        }
        public void FindStroesThatSellsProduct_AddANewStoreANdInsetValidProduct_UnitofWorkReturnsStoresThatsSellProduct()
        {
            var TestStore = new Store() { StoreName = "TestStore2" };
            _context.Stores.Add(TestStore);
            _context.SaveChanges();
            var HasA = new HasA() { Product = _product, Store = TestStore, ProductId = _product.ProductId, StoreId = TestStore.StoreId, Price = 13 };
            _context.HasARelation.Add(HasA);
            _context.SaveChanges();

            var list = _consumer.FindStoresThatSellsProduct(_product.ProductName);

            Assert.That(list.Count, Is.EqualTo(3));
        }
        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 CreateShoppingList_CreateShoppingListForBanan_ListHasCorrectStoreName()
        {
            _uut.ShoppingListData.Add(new ProductInfo(_product.ProductName));

            var fakta = new Store() {StoreName = "Fakta"};
            _uut.OptionsStores.Add(new StoresInPristjek("Fakta"));
            _unitWork.Products.FindProduct(_product.ProductName).Returns(_product);
            _product.HasARelation.Add(new HasA() {Price = 2.95, Store = _store});
            _product.HasARelation.Add(new HasA() {Price = 1.95, Store = fakta});
            _store.HasARelation.Add(new HasA() {Price = 2.95, Product = _product, Store = _store});
            fakta.HasARelation.Add(new HasA() {Price = 1.95, Product = _product, Store = fakta});
            _uut.CreateShoppingList();

            Assert.That(_uut.GeneratedShoppingListData[0].StoreName, Is.EqualTo("Fakta"));
        }
 public void CheckUsernameAndPassword_UsernamesDoesNotMatch_ReturnMinus1()
 {
     Store store = new Store();
     Assert.That(_login.CheckUsernameAndPassword("", new SecureString(), ref store), Is.EqualTo(-1));
 }
 /// <summary>
 ///     Storemanager constructor takes a UnitOfWork to access the database and a store to set as his Store
 /// </summary>
 /// <param name="unitOfWork"></param>
 /// <param name="store"></param>
 public Storemanager(IUnitOfWork unitOfWork, Store store)
 {
     _unitwork = unitOfWork;
     Store = _unitwork.Stores.FindStore(store.StoreName);
 }
        public void SetUp()
        {
            _context = new DataContext();
            _unit = new UnitOfWork(_context);
            _context.Database.Connection.ConnectionString = "Server=.\\SQLEXPRESS;Database=Pristjek220Data.DataContext; Trusted_Connection=True;";
            _context.Database.ExecuteSqlCommand("dbo.TestCleanTable");

            var store = new Store() { StoreName = "TestStore" };
            _context.Stores.Add(store);
            _context.SaveChanges();
            _storemanager = new Storemanager(_unit, store);
        }
        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 AutoCompleteStore_SortList_ListIsSortedCheckTwo()
        {
            var faktaStore = new Store() { StoreName = "Fakta" };
            var føtexStore = new Store() { StoreName = "Føtex" };
            var fleggardStore = new Store() { StoreName = "Fleggard" };
            var fantasiStore = new Store() { StoreName = "Fantasi" };
            _stores.Add(fantasiStore);
            _stores.Add(føtexStore);
            _stores.Add(fleggardStore);
            _stores.Add(faktaStore);

            _unitWork.Stores.FindStoreStartingWith("F").Returns(_stores);
            Assert.That(_uut.AutoCompleteStore("F")[1], Is.EqualTo("Fantasi"));
        }
        public void AutoCompleteStore_LookUpWordStartsWithF_ReturnListOfSize3()
        {
            var faktaStore = new Store() { StoreName = "Fakta" };
            var føtexStore = new Store() { StoreName = "Føtex" };
            var fleggardStore = new Store() { StoreName = "Fleggard" };
            var fantasiStore = new Store() { StoreName = "Fantasi" };
            _stores.Add(faktaStore);
            _stores.Add(føtexStore);
            _stores.Add(fleggardStore);
            _stores.Add(fantasiStore);

            _unitWork.Stores.FindStoreStartingWith("F").Returns(_stores);
            Assert.That(_uut.AutoCompleteStore("F").Count, Is.EqualTo(3));
        }
 public void SetUp()
 {
     _unitWork = Substitute.For<IUnitOfWork>();
     _store = new Store() {StoreName = "Aldi", StoreId = 22};
     _product = new Product() {ProductName = "Banan", ProductId = 10};
     _unitWork.Stores.GetAllStores().Returns(new List<Store>());
     _uut = new Consumer.Consumer(_unitWork);
 }
        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");

            _store = new Store() { StoreName = "TestStore" };
            _autocomplete = new Autocomplete(_unit);
            _msgBox = Substitute.For<ICreateMsgBox>();

            _context.Stores.Add(_store);
            _context.SaveChanges();

            _storemanager = new Storemanager(_unit, _store);
            _newProduct = new NewProductModel(_storemanager, _autocomplete, _msgBox );

            _context.Products.Add(new Product() {ProductName = "Test"});
            _context.Products.Add(new Product() { ProductName = "Test2" });
            _context.SaveChanges();
        }