예제 #1
0
 public void Setup()
 {
     Item1      = Guid.NewGuid();
     Item3      = Guid.NewGuid();
     Item2      = Guid.NewGuid();
     cart1With5 = new StoreCart(MOCK_GUID_FOR_STORE);
     cart1With5.AddToStoreCart(Item1, 5);
     cart2With5 = new StoreCart(MOCK_GUID_FOR_STORE);
     cart2With5.AddToStoreCart(Item2, 5);
     multyItemsAmount10 = new StoreCart(MOCK_GUID_FOR_STORE);
     multyItemsAmount10.AddToStoreCart(Item1, 2);
     multyItemsAmount10.AddToStoreCart(Item2, 3);
     multyItemsAmount10.AddToStoreCart(Item3, 5);
 }
예제 #2
0
        public void OrderManager_Payment_Guest_ShouldPass()
        {
            using var context = new MarketDbContext(inMemoryConnection);

            string storeName = GetStoreName();
            // setup test
            StoreContactDetails details = new StoreContactDetails(storeName, "*****@*****.**", "location", "222", "222", "bank", "cool store");

            storeHandler.OpenStore(details, Owner, context);
            Store s = storeHandler.Stores(context).Where(s => s.ContactDetails.Name.Equals(storeName, StringComparison.InvariantCultureIgnoreCase)).First();

            string itemName = "testItemD";
            Item   item     = s.AddItem(itemName, 2, new HashSet <string>()
            {
                "CategoryA"
            }, 1.22, context, keyWords: new HashSet <string>()
            {
                "test"
            });

            Dictionary <Guid, StoreCart> shoppingCart = new Dictionary <Guid, StoreCart>();
            StoreCart cart = new StoreCart(s.Id);

            cart.AddToStoreCart(item.Id, 1);
            shoppingCart.Add(s.Id, cart);

            PaymentReal realPayment = new PaymentReal(new System.Net.Http.HttpClient());

            orderManager.Payment.Real = realPayment;
            Order order = null;

            Assert.DoesNotThrow(() => order = orderManager.DiscountAndReserve(GetGuestId(), shoppingCart, context));
            Assert.IsNotNull(order);
            Assert.DoesNotThrow(() => orderManager.CollectPayment(order.userKey, order.OrderId, "1111222233334444", "12/2021", "111", "name", "222333231", context));
        }
예제 #3
0
        public void OrderManager_Delivery_Guest_ShouldPass()
        {
            using var context = new MarketDbContext(inMemoryConnection);

            string storeName = GetStoreName();
            // setup test
            StoreContactDetails details = new StoreContactDetails(storeName, "*****@*****.**", "location", "222", "222", "bank", "cool store");

            storeHandler.OpenStore(details, Owner, context);
            Store s = storeHandler.Stores(context).Where(s => s.ContactDetails.Name.Equals(storeName, StringComparison.InvariantCultureIgnoreCase)).First();

            string itemName = "testItemD";
            Item   item     = s.AddItem(itemName, 2, new HashSet <string>()
            {
                "CategoryA"
            }, 1.22, context);

            Dictionary <Guid, StoreCart> shoppingCart = new Dictionary <Guid, StoreCart>();
            StoreCart cart = new StoreCart(s.Id);

            cart.AddToStoreCart(item.Id, 1);
            shoppingCart.Add(s.Id, cart);

            DeliveryReal realDelivery = new DeliveryReal(new HttpClient());

            orderManager.Delivery.Real = realDelivery;
            Order order = null;

            Assert.DoesNotThrow(() => order = orderManager.DiscountAndReserve(GetGuestId(), shoppingCart, context));
            Assert.IsNotNull(order);
            order.Status = OrderStatus.PAYED_FOR;
            Assert.DoesNotThrow(() => orderManager.ScheduleDelivery(order.userKey, order.OrderId, "address", "city", "country", "22222", "name", context));
        }
예제 #4
0
        public void OrderManager_InvalidOrder_Guest_ShouldPass()
        {
            using var context = new MarketDbContext(inMemoryConnection);

            string storeName = GetStoreName();
            // setup test
            StoreContactDetails details = new StoreContactDetails(storeName, "*****@*****.**", "location", "222", "222", "bank", "cool store");

            Store s = storeHandler.OpenStore(details, Owner, context);

            string itemName = "testItemD";
            Item   item     = s.AddItem(itemName, 2, new HashSet <string>()
            {
                "CategoryA"
            }, 1.22, context);

            Dictionary <Guid, StoreCart> shoppingCart = new Dictionary <Guid, StoreCart>();
            StoreCart cart = new StoreCart(s.Id);

            cart.AddToStoreCart(item.Id, 1);
            shoppingCart.Add(s.Id, cart);

            Order order = null;

            Assert.DoesNotThrow(() => order = orderManager.DiscountAndReserve(GetGuestId(), shoppingCart, context));
            Assert.IsNotNull(order);
            order.Status = OrderStatus.DELIVERED;
            orderManager.LogOrder(order.userKey, order.OrderId, context);
            Assert.AreEqual(orderManager.GetStoreOrdersHistory(s.Id, context).Count, 1);
        }
예제 #5
0
        public void OrderManager_ValidOrder_ShouldPass()
        {
            using var context = new MarketDbContext(inMemoryConnection);

            string storeName = GetStoreName();
            // setup test
            StoreContactDetails details = new StoreContactDetails(storeName, "*****@*****.**", "location", "222", "222", "bank", "cool store");

            storeHandler.OpenStore(details, Owner, context);
            Store s = storeHandler.Stores(context).Where(s => s.ContactDetails.Name.Equals(storeName, StringComparison.InvariantCultureIgnoreCase)).First();

            string itemName = "testItemD";
            Item   item     = s.AddItem(itemName, 2, new HashSet <string>()
            {
                "CategoryA"
            }, 1.22, context);

            Dictionary <Guid, StoreCart> shoppingCart = new Dictionary <Guid, StoreCart>();
            StoreCart cart = new StoreCart(s.Id);

            cart.AddToStoreCart(item.Id, 1);
            shoppingCart.Add(s.Id, cart);

            // test
            Order order = null;

            Assert.DoesNotThrow(() => order = orderManager.DiscountAndReserve(Buyer1, shoppingCart, context));
            Assert.IsNotNull(order);
            order.Status = OrderStatus.DELIVERED;
            Assert.DoesNotThrow(() => orderManager.LogOrder(order.UserId, order.OrderId, context));
        }
예제 #6
0
        public void OrderManager_ValidOrder_TooManyItems_ShouldFail()
        {
            using var context = new MarketDbContext(inMemoryConnection);

            string storeName = GetStoreName();

            // setup test
            StoreContactDetails details = new StoreContactDetails(storeName, "*****@*****.**", "location", "222", "222", "bank", "cool store");

            storeHandler.OpenStore(details, Owner, context);
            Store s = storeHandler.Stores(context).Where(s => s.ContactDetails.Name.Equals(storeName, StringComparison.InvariantCultureIgnoreCase)).First();

            string itemName = "testItemC";
            Item   item     = s.AddItem(itemName, 1, new HashSet <string>()
            {
                "CategoryA"
            }, 1.22, context);

            Dictionary <Guid, StoreCart> shoppingCart = new Dictionary <Guid, StoreCart>();
            StoreCart cart = new StoreCart(s.Id);

            cart.AddToStoreCart(item.Id, 3);
            shoppingCart.Add(s.Id, cart);

            // test
            Assert.Throws <ItemAmountException>(() => orderManager.DiscountAndReserve(Buyer1, shoppingCart, context));
        }
예제 #7
0
        public void OrderManager_StoreHistory_TwoStores_ShouldPass()
        {
            using var context = new MarketDbContext(inMemoryConnection);

            string storeName1 = GetStoreName();
            string storeName2 = GetStoreName();

            // setup test
            StoreContactDetails details1 = new StoreContactDetails(storeName1, "*****@*****.**", "location", "222", "222", "bank", "cool store");
            StoreContactDetails details2 = new StoreContactDetails(storeName2, "*****@*****.**", "location", "222", "222", "bank", "very cool store");

            storeHandler.OpenStore(details1, Owner, context);
            storeHandler.OpenStore(details2, Owner, context);

            Store store1 = storeHandler.Stores(context).Where(s => s.ContactDetails.Name.Equals(storeName1, StringComparison.InvariantCultureIgnoreCase)).First();
            Store store2 = storeHandler.Stores(context).Where(s => s.ContactDetails.Name.Equals(storeName2, StringComparison.InvariantCultureIgnoreCase)).First();

            string itemName1 = "testItemD";
            string itemName2 = "testItemE";

            Item item1 = store1.AddItem(itemName1, 2, new HashSet <string>()
            {
                "CategoryA"
            }, 1.22, context);
            Item item2 = store2.AddItem(itemName2, 2, new HashSet <string>()
            {
                "CategoryA"
            }, 1.22, context);

            Dictionary <Guid, StoreCart> shoppingCart = new Dictionary <Guid, StoreCart>();
            StoreCart cart1 = new StoreCart(store1.Id);

            cart1.AddToStoreCart(item1.Id, 1);
            shoppingCart.Add(store1.Id, cart1);

            StoreCart cart2 = new StoreCart(store2.Id);

            cart2.AddToStoreCart(item2.Id, 1);
            shoppingCart.Add(store2.Id, cart2);
            // test
            Order order = null;

            Assert.DoesNotThrow(() => order = orderManager.DiscountAndReserve(Buyer1, shoppingCart, context));
            Assert.IsNotNull(order);
            order.Status = OrderStatus.DELIVERED;
            Assert.DoesNotThrow(() => orderManager.LogOrder(order.UserId, order.OrderId, context));

            List <StoreOrder> storeHistory1 = orderManager.GetStoreOrdersHistory(store1.Id, context);

            Assert.AreEqual(1, storeHistory1.Count());
            Assert.AreEqual(storeHistory1[0].OrderItemsDict[item1.Id].Name, itemName1);
            Assert.AreEqual(storeHistory1[0].StoreId, store1.Id);

            List <StoreOrder> storeHistory2 = orderManager.GetStoreOrdersHistory(store2.Id, context);

            Assert.AreEqual(1, storeHistory2.Count());
            Assert.AreEqual(storeHistory2[0].OrderItemsDict[item2.Id].Name, itemName2);
            Assert.AreEqual(storeHistory2[0].StoreId, store2.Id);
        }
예제 #8
0
        public void OrderManager_ReviewPending_Timeout_ShouldPass()
        {
            using var context = new MarketDbContext(inMemoryConnection);

            string storeName1 = GetStoreName();
            string storeName2 = GetStoreName();

            // setup test
            StoreContactDetails details1 = new StoreContactDetails(storeName1, "*****@*****.**", "location", "222", "222", "bank", "cool store");
            StoreContactDetails details2 = new StoreContactDetails(storeName2, "*****@*****.**", "location", "222", "222", "bank", "very cool store");

            storeHandler.OpenStore(details1, Owner, context);
            storeHandler.OpenStore(details2, Owner, context);

            Store store1 = storeHandler.Stores(context).Where(s => s.ContactDetails.Name.Equals(storeName1, StringComparison.InvariantCultureIgnoreCase)).First();
            Store store2 = storeHandler.Stores(context).Where(s => s.ContactDetails.Name.Equals(storeName2, StringComparison.InvariantCultureIgnoreCase)).First();

            string itemName1 = "testItemD";
            string itemName2 = "testItemE";

            Item item1 = store1.AddItem(itemName1, 2, new HashSet <string>()
            {
                "CategoryA"
            }, 1.22, context);
            Item item2 = store2.AddItem(itemName2, 2, new HashSet <string>()
            {
                "CategoryA"
            }, 1.22, context);

            Dictionary <Guid, StoreCart> shoppingCart = new Dictionary <Guid, StoreCart>();
            StoreCart cart1 = new StoreCart(store1.Id);

            cart1.AddToStoreCart(item1.Id, 2);
            shoppingCart.Add(store1.Id, cart1);

            StoreCart cart2 = new StoreCart(store2.Id);

            cart2.AddToStoreCart(item2.Id, 2);
            shoppingCart.Add(store2.Id, cart2);
            // test
            Order order = null;

            Assert.DoesNotThrow(() => order = orderManager.DiscountAndReserve(Buyer1, shoppingCart, context));
            Assert.IsNotNull(order);
            Assert.Throws <ItemAmountException>(() => orderManager.DiscountAndReserve(Buyer1, shoppingCart, context));
            context.SaveChanges();
            context.Dispose();

            Thread.Sleep(1000 * 60 * 4);// sleep max time for delete

            using var context2 = new MarketDbContext(inMemoryConnection);
            Assert.DoesNotThrow(() => order = orderManager.DiscountAndReserve(Buyer1, shoppingCart, context2));
        }
예제 #9
0
        public void OrderManager_ValidOrder_StoreNotFound_ShouldFail()
        {
            using var context = new MarketDbContext(inMemoryConnection);

            Dictionary <Guid, StoreCart> shoppingCart = new Dictionary <Guid, StoreCart>();
            StoreCart cart = new StoreCart(Guid.NewGuid());

            cart.AddToStoreCart(Guid.NewGuid(), 1);
            shoppingCart.Add(Guid.NewGuid(), cart);

            // test
            Assert.Throws <StoreNotFoundException>(() => orderManager.DiscountAndReserve(Buyer1, shoppingCart, context));
        }
예제 #10
0
        public void OrderManager_ValidOrder_TwoStores_TwoShoppingCarts_OneDoesntHaveEnoughItems_ShuoldFail()
        {
            using var context = new MarketDbContext(inMemoryConnection);

            string storeName1 = GetStoreName();
            string storeName2 = GetStoreName();

            // setup test
            StoreContactDetails details1 = new StoreContactDetails(storeName1, "*****@*****.**", "location", "222", "222", "bank", "cool store");
            StoreContactDetails details2 = new StoreContactDetails(storeName2, "*****@*****.**", "location", "222", "222", "bank", "very cool store");

            storeHandler.OpenStore(details1, Owner, context);
            storeHandler.OpenStore(details2, Owner, context);

            Store store1 = storeHandler.Stores(context).Where(s => s.ContactDetails.Name.Equals(storeName1, StringComparison.InvariantCultureIgnoreCase)).First();
            Store store2 = storeHandler.Stores(context).Where(s => s.ContactDetails.Name.Equals(storeName2, StringComparison.InvariantCultureIgnoreCase)).First();

            string itemName1 = "testItemD";
            string itemName2 = "testItemE";

            Item item1 = store1.AddItem(itemName1, 2, new HashSet <string>()
            {
                "CategoryA"
            }, 1.22, context);
            Item item2 = store2.AddItem(itemName2, 0, new HashSet <string>()
            {
                "CategoryA"
            }, 1.22, context);

            Dictionary <Guid, StoreCart> shoppingCart1 = new Dictionary <Guid, StoreCart>();
            StoreCart cart1 = new StoreCart(store1.Id);

            cart1.AddToStoreCart(item1.Id, 1);
            shoppingCart1.Add(store1.Id, cart1);

            Dictionary <Guid, StoreCart> shoppingCart2 = new Dictionary <Guid, StoreCart>();
            StoreCart cart2 = new StoreCart(store2.Id);

            cart2.AddToStoreCart(item2.Id, 1);
            shoppingCart2.Add(store2.Id, cart2);

            // test
            Order order = null;

            Assert.DoesNotThrow(() => order = orderManager.DiscountAndReserve(Buyer1, shoppingCart1, context));
            Assert.IsNotNull(order);
            order.Status = OrderStatus.DELIVERED;
            Assert.DoesNotThrow(() => orderManager.LogOrder(order.UserId, order.OrderId, context));
            Assert.Throws <ItemAmountException>(() => orderManager.DiscountAndReserve(Buyer1, shoppingCart2, context));
        }
예제 #11
0
        public void OrderManager_UserHistory_2UsersSameStore_ShouldPass()
        {
            using var context = new MarketDbContext(inMemoryConnection);

            string storeName = GetStoreName();
            // setup test
            StoreContactDetails details = new StoreContactDetails(storeName, "*****@*****.**", "location", "222", "222", "bank", "cool store");

            storeHandler.OpenStore(details, Owner, context);
            Store s = storeHandler.Stores(context).Where(s => s.ContactDetails.Name.Equals(storeName, StringComparison.InvariantCultureIgnoreCase)).First();

            string itemName = "testItemD";
            Item   item     = s.AddItem(itemName, 4, new HashSet <string>()
            {
                "CategoryA"
            }, 1.22, context);

            Dictionary <Guid, StoreCart> shoppingCart = new Dictionary <Guid, StoreCart>();
            StoreCart cart = new StoreCart(s.Id);

            cart.AddToStoreCart(item.Id, 1);
            shoppingCart.Add(s.Id, cart);

            // test
            Order order = null;

            Assert.DoesNotThrow(() => order = orderManager.DiscountAndReserve(Buyer1, shoppingCart, context));
            Assert.IsNotNull(order);
            order.Status = OrderStatus.DELIVERED;
            Assert.DoesNotThrow(() => orderManager.LogOrder(order.UserId, order.OrderId, context));

            order = null;
            Assert.DoesNotThrow(() => order = orderManager.DiscountAndReserve(Buyer2, shoppingCart, context));
            Assert.IsNotNull(order);
            order.Status = OrderStatus.DELIVERED;
            Assert.DoesNotThrow(() => orderManager.LogOrder(order.UserId, order.OrderId, context));

            List <Order> userHistory1 = orderManager.GetUserOrdersHistory(Buyer1, context);

            Assert.AreEqual(1, userHistory1.Count());
            Order orderHistory1 = userHistory1.First();

            Assert.AreEqual(orderHistory1.StoreOrdersDict.Count, 1);
            KeyValuePair <Guid, StoreOrder> orderedItemFromStore1 = orderHistory1.StoreOrdersDict.First();

            Assert.AreEqual(orderedItemFromStore1.Value.StoreOrderItems.Count, 1);
            OrderItem orderedItem1 = orderedItemFromStore1.Value.OrderItemsDict[item.Id];

            Assert.AreEqual(orderedItem1.ItemId, item.Id);

            List <Order> userHistory2 = orderManager.GetUserOrdersHistory(Buyer1, context);

            Assert.AreEqual(1, userHistory2.Count());
            Order orderHistory2 = userHistory2.First();

            Assert.AreEqual(orderHistory2.StoreOrdersDict.Count, 1);
            KeyValuePair <Guid, StoreOrder> orderedItemFromStore2 = orderHistory2.StoreOrdersDict.First();

            Assert.AreEqual(orderedItemFromStore2.Value.StoreOrderItems.Count, 1);
            OrderItem orderedItem2 = orderedItemFromStore2.Value.OrderItemsDict[item.Id];

            Assert.AreEqual(orderedItem2.ItemId, item.Id);
        }