public async Task GetUserHistoryWithPermission()
        {
            CreditCard card    = new CreditCard("1", "1", "1", "1", "1", "1");
            Address    address = new Address("1", "1", "1", "1", "1");
            Product    product = new Product(new Guid(), 100, 100, 100);
            User       user    = new User("testUser");
            Store      store   = new Store("storeTest", card, address);

            store.Founder = Founder.makeFounder(new MemberState("userTest"), store);
            MemberState memberState = new MemberState(user.Username);

            user.ChangeState(memberState);
            store.UpdateProduct(product);
            await user.UpdateProductInShoppingBasket(store, product, 5);

            ICollection <IHistory> userHistory = await user.GetUserHistory(user.Username);

            Assert.IsNotNull(userHistory);
            int originCount = userHistory.Count;
            var v1          = await user.PurchaseShoppingCart(card, "0544444444", address);

            Assert.IsTrue(!v1.IsErr);
            userHistory = await user.GetUserHistory(user.Username);

            Assert.AreEqual(originCount + 1, userHistory.Count);
        }
        public async Task Initialize()
        {
            ProxyMarketContext.Instance.marketTearDown();
            marketStores = MarketStores.Instance;
            marketUsers  = MarketUsers.Instance;
            PublisherManagement.Instance.DeleteAll();
            marketUsers.DeleteAll();
            marketStores.DeleteAll();
            PublisherManagement.Instance.SetTestMode(true);

            this.user = new User("UserTests");
            user.ChangeState(new MemberState(user.Username));
            var dataUser = new DataUser(user.Username, "", new Address("1", "1", "1", "1", "1"), "054444444");

            dataUser.IsLoggedin = true;
            await ProxyMarketContext.Instance.AddDataUser(dataUser);

            marketUsers.ActiveUsers.TryAdd(user.Username, user);

            this.store  = new Store("Founder", new CreditCard("1", "1", "1", "1", "1", "1"), new Address("1", "1", "1", "1", "1"));
            founderUser = new User("Founder");
            founderUser.ChangeState(new MemberState(founderUser.Username));
            this.founder        = Founder.makeFounder((MemberState)founderUser.State, store);
            store.Founder       = founder;
            dataUser            = new DataUser(founderUser.Username, "", new Address("1", "1", "1", "1", "1"), "054444444");
            dataUser.IsLoggedin = true;
            await ProxyMarketContext.Instance.AddDataUser(dataUser);

            marketUsers.ActiveUsers.TryAdd(founder.Username, founderUser);
            ProxyMarketContext.Instance.IsDebug = true;
        }
 public MarketRulesTests()
 {
     this.store = new Store("TestStore", new CreditCard("1", "1", "1", "1", "1", "1"), new Address("1", "1", "1", "1", "1"));
     this.store.SetFounder(Founder.makeFounder(new MemberState("Founder"), store));
     marketStores.LoadedStores.TryAdd(store.GetId(), store);
     this.product        = new Product(new Guid(), "ProductName", 100, 100, 100, "CategoryName");
     this.shoppingBasket = new ShoppingBasket(new ShoppingCart(new User()), store);
     shoppingBasket.addProduct(product, 10);
 }
Esempio n. 4
0
        public void DeleteAll()
        {
            Store s = new Store("testStore", testStoreCreditCard, testStoreAddress);

            s.Founder           = Founder.makeFounder(new MemberState("userTest"), s);
            testStore           = s;
            this.shoppingCart   = new ShoppingCart(testUser);
            this.shoppingBasket = new ShoppingBasket(shoppingCart, testStore);
            Transaction.Instance.DeleteAllTests();
        }
        public getInfoTests()
        {
            ProxyMarketContext.Instance.IsDebug = true;
            address = new Address("1", "1", "1", "1", "1");
            card    = new CreditCard("1", "1", "1", "1", "1", "1");
            store   = new Store("testStore", card, address);
            MemberState ms = new MemberState("founder");

            founder       = Founder.makeFounder(ms, store);
            store.Founder = founder;
        }
Esempio n. 6
0
        public PurchaseTests()
        {
            product             = new Product(new Guid(), QUANTITY1, WEIGHT1, PRICE1);
            testUserAddress     = new Address("1", "1", "1", "1", "1");
            testStoreAddress    = new Address("2", "2", "2", "2", "2");
            testUserCreditCard  = new CreditCard("1", "1", "1", "1", "1", "1");
            testStoreCreditCard = new CreditCard("1", "1", "1", "1", "1", "1");
            testUser            = new User("testUser");
            Store s = new Store("testStore", testStoreCreditCard, testStoreAddress);

            s.Founder           = Founder.makeFounder(new MemberState("userTest"), s);
            testStore           = s;
            this.shoppingCart   = new ShoppingCart(testUser);
            this.shoppingBasket = new ShoppingBasket(shoppingCart, testStore);
        }
        public ProductsTest()
        {
            ProxyMarketContext.Instance.IsDebug = true;
            product1 = new Product(new Guid(), "1", 10, 10, 10, "category");
            address  = new Address("1", "1", "1", "1", "1");
            card     = new CreditCard("1", "1", "1", "1", "1", "1");
            store    = new Store("testStore", card, address);
            MemberState ms = new MemberState("founder");

            founder = Founder.makeFounder(ms, store);
            Mock <Manager> imanager = new Mock <Manager>();

            imanager.Setup(m => m.GetPermission(It.IsAny <Permission>())).Returns(false);
            manager       = imanager.Object;
            store.Founder = founder;
            store.Managers.Add(manager);
        }
        public async Task GetUserHistoryWithoutPermission()
        {
            CreditCard card    = new CreditCard("1", "1", "1", "1", "1", "1");
            Address    address = new Address("1", "1", "1", "1", "1");
            Product    product = new Product(new Guid(), 100, 100, 100);
            User       user    = new User("testUser");
            Store      store   = new Store("storeTest", card, address);

            store.Founder = Founder.makeFounder(new MemberState("userTest"), store);
            store.UpdateProduct(product);
            await user.UpdateProductInShoppingBasket(store, product, 5);

            var v1 = await user.PurchaseShoppingCart(card, "0544444444", address);

            Assert.IsTrue(!v1.IsErr);
            await user.GetUserHistory(user.Username);
        }
Esempio n. 9
0
        public PurchaseConcurrentTests()
        {
            product                  = new Product(new Guid(), QUANTITY1, WEIGHT1, PRICE1);
            oneProduct               = new Product(new Guid(), 1, WEIGHT1, PRICE1);
            testUserAddress          = new Address("1", "1", "1", "1", "1");
            testStoreAddress         = new Address("2", "2", "2", "2", "2");
            testSecondUserAddress    = new Address("3", "3", "3", "3", "3");
            testUserCreditCard       = new CreditCard("1", "1", "1", "1", "1", "1");
            testStoreBankAccount     = new CreditCard("1", "1", "1", "1", "1", "1");
            testSecondUserCreditCard = new CreditCard("2", "2", "2", "2", "2", "2");
            testStore                = new Store("testStore", testStoreBankAccount, testStoreAddress);
            testUser                 = new User("testUser");
            MemberState m = new MemberState(testUser.Username);
            Founder     f = Founder.makeFounder(m, testStore);

            secondTestUser    = new User("secondTestUser");
            testStore.Founder = f;
        }
Esempio n. 10
0
        public void ApplyTwoRelevantDiscounts()
        {
            shoppingBasket.UpdateProduct(product1, 30);
            Address    address = new Address("1", "1", "1", "1", "1");
            CreditCard card    = new CreditCard("1", "1", "1", "1", "1", "1");
            Store      store   = new Store("testStore", card, address);

            store.SetFounder(Founder.makeFounder(new MemberState("Founder"), store));
            store.UpdateProduct(product1);
            ConditionDiscount discount1 = new ConditionDiscount(new DiscountCalculator(return10));

            discount1.AddRule(new Rule(MoreThan10Products));
            ConditionDiscount discount2 = new ConditionDiscount(new DiscountCalculator(return20));

            discount2.AddRule(new Rule(MoreThan20Products));
            store.AddDiscount(store.Founder.Username, discount1);
            store.AddDiscount(store.Founder.Username, discount2);
            Assert.AreEqual(0.2 * product1.Price, store.ApplyDiscounts(shoppingBasket));
        }
Esempio n. 11
0
        public async Task CheckLegalPurchaseAsync()
        {
            HashSet <ProductInCart> product_quantity = new HashSet <ProductInCart>();
            string     clientPhone = "0544444444";
            Address    address     = new Address("1", "1", "1", "1", "1");
            CreditCard card        = new CreditCard("1", "1", "1", "1", "1", "1");
            Product    product1    = new Product(new Guid(), "1", 10, 10, 10, "category");
            Product    product2    = new Product(new Guid(), "2", 20, 20, 20, "category");

            product_quantity.Add(new ProductInCart(product1, 1));
            product_quantity.Add(new ProductInCart(product2, 2));
            shoppingBasket.Product_quantity = product_quantity;
            Store store = new Store("testStore", card, address);

            store.Founder = Founder.makeFounder(new MemberState("userTest"), store);
            store.UpdateProduct(product1);
            store.UpdateProduct(product2);
            PurchaseStatus purchaseStatus = await store.Purchase(shoppingBasket, clientPhone, address, card);

            Assert.AreEqual(true, purchaseStatus.TransactionStatus.Status);
        }