Esempio n. 1
0
 public static void AddingProductAT2()
 {
     UserAT.GenerateRandoms(out var cookie, out var username, out var password);
     UserAT.RegisterUser(cookie, username, password);
     UserAT.LoginUser(cookie, username, password);
     var shopGuid = Tester.PBridge.OpenShop(cookie, "Name");
 }
Esempio n. 2
0
        public static void AddPurchasePolicyAT1_CompoundPolicy()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var  shopGuid     = Tester.PBridge.OpenShop(cookie, "Name");
            var  productGuid  = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 5);
            var  productGuid1 = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Iphone X", "Cellphones", 3000, 7);
            var  policyGuid   = Tester.PBridge.AddNewPurchasePolicy(cookie, shopGuid, "Product purchase policy", productGuid, ">", 1, "Must buy more than 1 Galaxy9");
            var  policyGuid1  = Tester.PBridge.AddNewPurchasePolicy(cookie, shopGuid, "Product purchase policy", productGuid1, ">", 2, "Must buy more than 2 Iphone X");
            Guid res          = Tester.PBridge.AddNewPurchasePolicy(cookie, shopGuid, "Compound purchase policy", policyGuid, "^", policyGuid1, "Must buy more than 1 Galaxy9 XOR more than 2 Iphone X");

            Assert.AreNotEqual(Guid.Empty, res);

            UserAT.GenerateRandoms(out var cookieBuyer, out var usernameBuyer, out var passwordBuyer);
            Guid buyerGuid = UserAT.RegisterUser(cookieBuyer, usernameBuyer, passwordBuyer);

            UserAT.LoginUser(cookieBuyer, usernameBuyer, passwordBuyer);
            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productGuid, 2);
            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productGuid1, 1);
            Assert.IsTrue(Tester.PBridge.PurchaseCart(cookieBuyer, shopGuid));


            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productGuid, 2);
            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productGuid1, 3);
            Assert.IsFalse(Tester.PBridge.PurchaseCart(cookieBuyer, shopGuid));
        }
Esempio n. 3
0
        public static void AddPurchasePolicyAT3()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid     = Tester.PBridge.OpenShop(cookie, "Name");
            var productGuid  = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Cool Hat", "Accessories", 200, 5);
            var productGuid1 = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Stick Light", "Cellphones", 10, 80);
            var policyGuid   = Tester.PBridge.AddNewPurchasePolicy(cookie, shopGuid, "Cart purchase policy", ">", 6, "Cart size must be beyond 6");

            Assert.AreNotEqual(Guid.Empty, policyGuid);

            UserAT.GenerateRandoms(out var cookieBuyer, out var usernameBuyer, out var passwordBuyer);
            Guid buyerGuid = UserAT.RegisterUser(cookieBuyer, usernameBuyer, passwordBuyer);

            UserAT.LoginUser(cookieBuyer, usernameBuyer, passwordBuyer);
            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productGuid, 2);
            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productGuid1, 5);
            Assert.IsTrue(Tester.PBridge.PurchaseCart(cookieBuyer, shopGuid));


            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productGuid, 1);
            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productGuid1, 3);
            Assert.IsFalse(Tester.PBridge.PurchaseCart(cookieBuyer, shopGuid));
        }
Esempio n. 4
0
        public static void AddDiscountPolicyAT4()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid                    = Tester.PBridge.OpenShop(cookie, "Name");
            var productHammer               = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Hammer", "Tools", 100, 5);
            var productScrewDriver          = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Screwdriver", "Tools", 90, 7);
            var productNail                 = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Nail", "Tools", 10, 100);
            var productDisc                 = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Disc", "Tools", 200, 4);
            var policyHammer                = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Product discount policy", productHammer, ">", 0, 0, "Buy Hammer");
            var policyScrewDriver           = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Product discount policy", productScrewDriver, ">", 0, 0, "Buy Screwdriver");
            var policyHammerAndScrew        = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Compound discount policy", policyHammer, "&", policyScrewDriver, 0, "Buy Hammer and Screwdriver");
            var policyDisc                  = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Product discount policy", productDisc, ">", 0, 0, "Buy Disc");
            var policyHammerAndScrew_OrDisc = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Compound discount policy", policyHammerAndScrew, "|", policyDisc, 0, "Buy (Hammer and Screwdriver) or Disc");
            var policyCart                  = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Cart discount policy", ">", -1, 0, "discount on cart");
            var policyHammerAndScrew_OrDisc_implies32PrecentOnCart = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Compound discount policy", policyHammerAndScrew_OrDisc, "&", policyCart, 32, "Buy (Hammer and Screwdriver) or Disc implies 32% on Cart");

            Assert.AreNotEqual(Guid.Empty, policyHammerAndScrew_OrDisc_implies32PrecentOnCart);

            //Buy According to the policy and check that the discount applies
            UserAT.GenerateRandoms(out var cookieBuyer, out var usernameBuyer, out var passwordBuyer);
            Guid buyerGuid = UserAT.RegisterUser(cookieBuyer, usernameBuyer, passwordBuyer);

            UserAT.LoginUser(cookieBuyer, usernameBuyer, passwordBuyer);
            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productHammer, 2);
            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productScrewDriver, 1);
            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productNail, 2);

            double priceAfterDiscount = Tester.PBridge.GetCartPrice(cookieBuyer, shopGuid);

            Assert.AreEqual(310 * 68 / 100.0, priceAfterDiscount);

            Tester.PBridge.PurchaseCart(cookieBuyer, shopGuid);
        }
Esempio n. 5
0
        public static void RemoveOfOwnerAT4()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid = Tester.PBridge.OpenShop(cookie, "Name");

            //Appoint ben
            UserAT.GenerateRandoms(out var benCookie, out var benUsername, out var benPassword);
            var benGuid = UserAT.RegisterUser(benCookie, benUsername, benPassword);

            UserAT.LoginUser(benCookie, benUsername, benPassword);
            Tester.PBridge.AddShopOwner(cookie, shopGuid, benGuid);

            //Ben appoints tom
            UserAT.GenerateRandoms(out var tomCookie, out var tomUsername, out var tomPassword);
            var tomGuid = UserAT.RegisterUser(tomCookie, tomUsername, tomPassword);

            Tester.PBridge.AddShopOwner(benCookie, shopGuid, tomGuid);

            //Remove ben, and cascade remove tom
            var res = Tester.PBridge.CascadeRemoveShopOwner(cookie, shopGuid, benGuid);

            Assert.IsTrue(res);

            UserAT.LoginUser(tomCookie, tomUsername, tomPassword);

            //verify he really is not an owner anymore
            Assert.Throws <NoPrivilegesException>(
                () => Tester.PBridge.AddShopOwner(tomCookie, shopGuid, benGuid));
        }
Esempio n. 6
0
 public static void EditingProductAT2()
 {
     UserAT.GenerateRandoms(out var cookie, out var username, out var password);
     UserAT.RegisterUser(cookie, username, password);
     UserAT.LoginUser(cookie, username, password);
     var shopGuid   = Tester.PBridge.OpenShop(cookie, "Name");
     var galaxyGuid = AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 10);
 }
Esempio n. 7
0
        public static void RemoveOfRegisteredUserAT1()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            var userGuid = UserAT.RegisterUser(cookie, username, password);
            var res      = Tester.PBridge.RemoveUser(_adminCookie, userGuid);

            Assert.True(res);
        }
Esempio n. 8
0
        public static void OpenStoreAT1()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var res = Tester.PBridge.OpenShop(cookie, "Name");

            Assert.AreNotEqual(res, Guid.Empty);
        }
Esempio n. 9
0
        public static void LogoutAT1()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var res = Tester.PBridge.Logout(cookie);

            Assert.IsTrue(res);
        }
Esempio n. 10
0
        public static void AddingProductAT4()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid = Tester.PBridge.OpenShop(cookie, "Name");

            Assert.Throws <IllegalArgumentException>(
                () => AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", -2000, 10));
        }
Esempio n. 11
0
        public static void AppointmentOfNewOwnerAT2()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid = Tester.PBridge.OpenShop(cookie, "Name");

            Assert.Throws <UserNotFoundException>(
                () => Tester.PBridge.AddShopOwner(cookie, shopGuid, Guid.Empty));
        }
Esempio n. 12
0
        public static void AppointmentOfNewOwnerAT3()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid = Tester.PBridge.OpenShop(cookie, "Name");

            UserAT.GenerateRandoms(out var benCookie, out var benUsername, out var benPassword);
            var benGuid = UserAT.RegisterUser(benCookie, benUsername, benPassword);
        }
Esempio n. 13
0
        public static void AddingProductAT1()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid = Tester.PBridge.OpenShop(cookie, "Name");
            var res      = AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 10);

            Assert.AreNotEqual(Guid.Empty, res);
        }
Esempio n. 14
0
        public static void RemovingProductAT3()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid    = Tester.PBridge.OpenShop(cookie, "Name");
            var productGuid = AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 10);

            Assert.Throws <ProductNotFoundException>(
                () => Tester.PBridge.RemoveProductFromShop(cookie, shopGuid, Guid.Empty));
        }
Esempio n. 15
0
        public static void AddDiscountPolicyAT2()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid    = Tester.PBridge.OpenShop(cookie, "Name");
            var productGuid = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 1);

            UserAT.GenerateRandoms(out var anotherCookie, out var anotherUsername, out var anotherPassword);
            Assert.Throws <UserNotFoundException>(() => Tester.PBridge.AddNewDiscountPolicy(anotherCookie, shopGuid, "Product discount policy", productGuid, ">", 0, 20, "20% on Galaxy S9"));
        }
Esempio n. 16
0
        public static void AddDiscountPolicyAT1()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var  shopGuid    = Tester.PBridge.OpenShop(cookie, "Name");
            var  productGuid = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 1);
            Guid res         = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Product discount policy", productGuid, ">", 2, 40, "40% if you buy more than 2 Galaxy9");

            Assert.AreNotEqual(Guid.Empty, res);
        }
Esempio n. 17
0
        public static void EditingProductAT3()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid   = Tester.PBridge.OpenShop(cookie, "Name");
            var galaxyGuid = AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 10);

            //Empty guid does not match any product
            Assert.Throws <ProductNotFoundException>(() => Tester.PBridge.EditProductInShop(cookie, shopGuid, Guid.Empty, 1500, 20));
        }
Esempio n. 18
0
        public static void AddPurchasePolicyAT2()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid    = Tester.PBridge.OpenShop(cookie, "Name");
            var productGuid = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 1);

            UserAT.GenerateRandoms(out var anotherCookie, out var anotherUsername, out var anotherPassword);
            Assert.Throws <UserNotFoundException>(() => Tester.PBridge.AddNewPurchasePolicy(anotherCookie, shopGuid, "Product purchase policy", productGuid, "<", 2, "Must buy less than 2 Galaxy9"));
        }
Esempio n. 19
0
        public static void WatchingAndEditingOfCartAT1()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid = Tester.PBridge.OpenShop(cookie, "Name");

            var res = Tester.PBridge.GetAllProductsInCart(cookie, shopGuid);

            CollectionAssert.IsEmpty(res);
        }
Esempio n. 20
0
        public static void RemovingProductAT1()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid    = Tester.PBridge.OpenShop(cookie, "Name");
            var productGuid = AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 10);
            var res         = Tester.PBridge.RemoveProductFromShop(cookie, shopGuid, productGuid);

            Assert.True(res);
        }
Esempio n. 21
0
        public static void RemoveOfRegisteredUserAT2()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            var userGuid = UserAT.RegisterUser(cookie, username, password);

            UserAT.LoginUser(cookie, username, password);
            Tester.PBridge.ChangeUserState(cookie, "SellerUserState");
            Tester.PBridge.OpenShop(cookie, "Name");

            Assert.Throws <BrokenConstraintException>(
                () => Tester.PBridge.RemoveUser(_adminCookie, userGuid));
        }
Esempio n. 22
0
        public static void SavingProductsInCartAT1()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid    = Tester.PBridge.OpenShop(cookie, "Name");
            var productGuid = StoreOwnerAT.AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 10);

            var res = Tester.PBridge.AddProductToCart(cookie, shopGuid, productGuid, 1);

            Assert.IsTrue(res);
        }
Esempio n. 23
0
        public static void SearchProductsAT1()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid   = Tester.PBridge.OpenShop(cookie, "Name");
            var galaxyGuid = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 10);
            var iphoneGuid = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Iphone 6", "Cellphones", 500, 50);

            var resByName = Tester.PBridge.SearchProduct(cookie, new List <string>()
            {
                "Iphone 6"
            }, "Name");

            Assert.AreEqual(resByName.Count, 1);
            Assert.IsTrue(resByName.Any(t => t.Item1.Guid.Equals(iphoneGuid)));

            resByName = Tester.PBridge.SearchProduct(cookie, new List <string>()
            {
                "Galaxy"
            }, "Name");
            Assert.AreEqual(resByName.Count, 1);
            Assert.IsTrue(resByName.Any(t => t.Item1.Guid.Equals(galaxyGuid)));

            resByName = Tester.PBridge.SearchProduct(cookie, new List <string>()
            {
                "OnePlus"
            }, "Name");
            Assert.AreEqual(resByName.Count, 0);

            var resByCategory = Tester.PBridge.SearchProduct(cookie, new List <string>()
            {
                "Cellphones"
            }, "Category");

            Assert.AreEqual(resByCategory.Count, 2);
            Assert.IsTrue(resByCategory.Any(t => t.Item1.Guid.Equals(iphoneGuid)));
            Assert.IsTrue(resByCategory.Any(t => t.Item1.Guid.Equals(galaxyGuid)));

            resByCategory = Tester.PBridge.SearchProduct(cookie, new List <string>()
            {
                "Dishwashers"
            }, "Category");
            Assert.AreEqual(resByCategory.Count, 0);


            /* Not yet supported from service kayer
             * var resByKeywards = Tester.PBridge.SearchProduct(cookie, new List<string>() { "Cellphones" }, "Category");
             * CollectionAssert.AreEquivalent(resByName, new List<Guid>() { iphoneGuid, galaxyGuid });
             * resByCategory = Tester.PBridge.SearchProduct(cookie, new List<string>() { "Dishwashers" }, "Category");
             * CollectionAssert.AreEquivalent(resByName, new List<Guid>());
             */
        }
Esempio n. 24
0
        public static void AppointmentOfNewManagerAT1()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid = Tester.PBridge.OpenShop(cookie, "Name");

            UserAT.GenerateRandoms(out var benCookie, out var benUsername, out var benPassword);
            var benGuid = UserAT.RegisterUser(benCookie, benUsername, benPassword);

            Tester.PBridge.AddShopManager(cookie, shopGuid, benGuid, new List <bool>());
        }
Esempio n. 25
0
        public static void SavingProductsInCartAT2()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid    = Tester.PBridge.OpenShop(cookie, "Name");
            var productGuid = StoreOwnerAT.AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 10);

            var invalidProductGuid = Guid.Empty;

            Assert.Throws <ProductNotFoundException>(
                () => Tester.PBridge.AddProductToCart(cookie, shopGuid, invalidProductGuid, 1));
        }
Esempio n. 26
0
        public static void RemoveOfManagerAT1()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid = Tester.PBridge.OpenShop(cookie, "Name");

            UserAT.GenerateRandoms(out var benCookie, out var benUsername, out var benPassword);
            var benGuid = UserAT.RegisterUser(benCookie, benUsername, benPassword);

            Tester.PBridge.AddShopManager(cookie, shopGuid, benGuid, new List <bool>());
            var res = Tester.PBridge.RemoveShopManager(cookie, shopGuid, benGuid);

            Assert.IsTrue(res);
        }
Esempio n. 27
0
        public static void AddingProductAT3()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid = Tester.PBridge.OpenShop(cookie, "Name");

            //non-owner user tries to add
            UserAT.GenerateRandoms(out var otherCookie, out var otherUsername, out var otherPassword);
            UserAT.RegisterUser(otherCookie, otherUsername, otherPassword);
            UserAT.LoginUser(otherCookie, otherUsername, otherPassword);

            Assert.Throws <NoPrivilegesException>(
                () => AddProductToShop(otherCookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 10));
        }
Esempio n. 28
0
        public static void WatchingAndEditingOfCartAT3()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);

            var shopGuid    = Tester.PBridge.OpenShop(cookie, "Name");
            var productGuid = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 10);

            Tester.PBridge.AddProductToCart(cookie, shopGuid, productGuid, 10);
            Tester.PBridge.RemoveProductFromCart(cookie, shopGuid, productGuid);
            var res = Tester.PBridge.GetAllProductsInCart(cookie, shopGuid);

            CollectionAssert.IsEmpty(res);
        }
Esempio n. 29
0
        public static void AddPurchasePolicyAT1_1()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var  shopGuid    = Tester.PBridge.OpenShop(cookie, "Name");
            var  productGuid = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Galaxy S9", "Cellphones", 2000, 4);
            Guid res         = Tester.PBridge.AddNewPurchasePolicy(cookie, shopGuid, "Product purchase policy", productGuid, "<", 2, "Must buy less than 2 Galaxy9");

            Assert.AreNotEqual(Guid.Empty, res);

            UserAT.GenerateRandoms(out var cookieBuyer, out var usernameBuyer, out var passwordBuyer);
            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productGuid, 1);
            Assert.IsTrue(Tester.PBridge.PurchaseCart(cookieBuyer, shopGuid));
            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productGuid, 2);
            Assert.IsFalse(Tester.PBridge.PurchaseCart(cookieBuyer, shopGuid));
        }
Esempio n. 30
0
        public static void AddDiscountPolicyAT5()
        {
            UserAT.GenerateRandoms(out var cookie, out var username, out var password);
            UserAT.RegisterUser(cookie, username, password);
            UserAT.LoginUser(cookie, username, password);
            var shopGuid                    = Tester.PBridge.OpenShop(cookie, "Name");
            var productHammer               = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Hammer", "Tools", 100, 5);
            var productScrewDriver          = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Screwdriver", "Tools", 90, 7);
            var productNail                 = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Nail", "Tools", 10, 100);
            var productDisc                 = Tester.PBridge.AddProductToShop(cookie, shopGuid, "Disc", "Tools", 200, 4);
            var policyHammer                = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Product discount policy", productHammer, ">", 0, 0, "Buy Hammer");
            var policyScrewDriver           = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Product discount policy", productScrewDriver, ">", 0, 0, "Buy Screwdriver");
            var policyHammerAndScrew        = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Compound discount policy", policyHammer, "&", policyScrewDriver, 0, "Buy Hammer and Screwdriver");
            var policyDisc                  = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Product discount policy", productDisc, ">", 0, 0, "Buy Disc");
            var policyHammerAndScrew_OrDisc = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Compound discount policy", policyHammerAndScrew, "|", policyDisc, 0, "Buy (Hammer and Screwdriver) or Disc");
            var policyCart                  = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Cart discount policy", ">", 0, 0, "discount on cart");
            var policyHammerAndScrew_OrDisc_implies30PrecentOnCart = Tester.PBridge.AddNewDiscountPolicy(cookie, shopGuid, "Compound discount policy", policyHammerAndScrew_OrDisc, "&", policyCart, 32, "Buy (Hammer and Screwdriver) or Disc implies 32% on Cart");

            Assert.AreNotEqual(Guid.Empty, policyHammerAndScrew_OrDisc_implies30PrecentOnCart);

            //Buy According to the policy and check that the discount applies
            UserAT.GenerateRandoms(out var cookieBuyer, out var usernameBuyer, out var passwordBuyer);
            Guid buyerGuid = UserAT.RegisterUser(cookieBuyer, usernameBuyer, passwordBuyer);

            UserAT.LoginUser(cookieBuyer, usernameBuyer, passwordBuyer);
            Tester.PBridge.AddProductToCart(cookieBuyer, shopGuid, productHammer, 2);


            double priceAfterDiscount = Tester.PBridge.GetCartPrice(cookieBuyer, shopGuid);

            Assert.AreEqual(200, priceAfterDiscount);

            Tester.PBridge.PurchaseCart(cookieBuyer, shopGuid);

            var  buyerPurchaseHistory = Tester.PBridge.GetPurchaseHistory(cookieBuyer);
            bool thereIsDiscount      = false;

            foreach (Tuple <Guid, ApplicationCore.Entitites.ShopProduct, int> item in buyerPurchaseHistory)
            {
                if (item.Item1 == shopGuid && item.Item2.Price < 0 && item.Item3 > 0)
                {
                    thereIsDiscount = true;
                }
            }
            Assert.IsFalse(thereIsDiscount);
        }