Пример #1
0
        public void CustomerWithProfileFailedToPlaceAnOrder()
        {
            List <CProduct> supply = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 10),
                new CProduct("222", "orange", "Produce", 0.88, 10)
            };
            List <CProduct> p = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 20),
                new CProduct("222", "orange", "Produce", 0.88, 20)
            };
            CStore    store    = new CStore("Phoenix101", "606", supply);
            CCustomer customer = new CCustomer("123123121", "John", "Smith", "6021111111");
            COrder    order    = new COrder(store, customer, DateTime.Today, 100, p);

            // customer has an existing profile
            store.AddCustomer(customer);
            customer.PlaceOrder(store, order);

            // inventory should not be updated 10-20<0 => 10
            foreach (var item in store.Inventory)
            {
                Assert.Equal(10, item.Value.Quantity);
            }

            // userDict should have customer file, but with no order history
            Assert.Empty(store.CustomerDict["123123121"].OrderHistory);
        }
Пример #2
0
        public void CustomerWithoutProfileFailedToPlaceAnOrder()
        {
            List <CProduct> supply = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 10),
                new CProduct("222", "orange", "Produce", 0.88, 10)
            };
            List <CProduct> p = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 20),
                new CProduct("222", "orange", "Produce", 0.88, 20)
            };
            CStore    store    = new CStore("Phoenix101", "606", supply);
            CCustomer customer = new CCustomer("123123121", "John", "Smith", "6021111111");
            COrder    order    = new COrder(store, customer, DateTime.Today, 100, p);

            customer.PlaceOrder(store, order);

            // inventory should not be updated 10-20<0 => 10
            foreach (var item in store.Inventory)
            {
                Assert.Equal(10, item.Value.Quantity);
            }

            // customer does not have an existing profile
            // a failed order doesn not create a new user profile
            // userDict should be empty
            // .Equal 0 does not check a collection size
            Assert.Empty(store.CustomerDict);
        }
Пример #3
0
        public void ResupplyAndReorderReadAndWrite()
        {
            string          path    = "../../../SimplyWriteData.json";
            JsonFilePersist persist = new JsonFilePersist(path);
            CStore          store   = persist.ReadStoreData();

            List <CProduct> supply = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 10),
                new CProduct("222", "orange", "Produce", 0.88, 10),
                new CProduct("333", "Rocket", "Transport", 1000000, 15)
            };

            store.AddProducts(supply);
            CCustomer       customer = new CCustomer("127137147", "Adam", "Savage", "4801111111");
            List <CProduct> p        = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 1),
                new CProduct("222", "orange", "Produce", 0.88, 1)
            };
            COrder order = new COrder(store, customer, DateTime.Today, 100, p);

            customer.PlaceOrder(store, order);

            persist.WriteStoreData(store);
            foreach (var pair in store.Inventory)
            {
                Assert.Equal(15, pair.Value.Quantity);
            }
        }
Пример #4
0
        public void SearchCustomerByNameShouldReturnProfile()
        {
            // arrange
            List <CProduct> supply = new List <CProduct>
            {
                new CProduct("111", "Banana", "Produce", 0.5, 10),
                new CProduct("222", "orange", "Produce", 0.88, 10)
            };
            List <CProduct> p = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 4),
                new CProduct("222", "orange", "Produce", 0.88, 4)
            };
            CStore    store    = new CStore("Phoenix101", "606", supply);
            CCustomer customer = new CCustomer("123123121", "John", "Smith", "6021111111");

            COrder order = new COrder(store, customer, DateTime.Today, 100, p);

            customer.PlaceOrder(store, order);
            ISearch searchTool = new SimpleSearch();
            // act
            string customerid;
            bool   result = searchTool.SearchByName(store, "John", "Smith", out customerid);


            // assert
            Assert.True(result);
        }
Пример #5
0
        public void CustomerPlacedASuccessfulOrder()
        {
            List <CProduct> supply = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 10),
                new CProduct("222", "orange", "Produce", 0.88, 10)
            };
            List <CProduct> p = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 4),
                new CProduct("222", "orange", "Produce", 0.88, 4)
            };
            CStore    store    = new CStore("Phoenix101", "606", supply);
            CCustomer customer = new CCustomer("123123121", "John", "Smith", "6021111111");
            COrder    order    = new COrder(store, customer, DateTime.Today, 100, p);

            customer.PlaceOrder(store, order);
            // inventory should be updated 10-4=6
            foreach (var item in store.Inventory)
            {
                Assert.Equal(6, item.Value.Quantity);
            }
        }
Пример #6
0
        public void SimplyWriteData()
        {
            List <CProduct> supply = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 10),
                new CProduct("222", "orange", "Produce", 0.88, 10)
            };
            List <CProduct> p = new List <CProduct> {
                new CProduct("111", "Banana", "Produce", 0.5, 4),
                new CProduct("222", "orange", "Produce", 0.88, 4)
            };
            CStore    store    = new CStore("Phoenix101", "606", supply);
            CCustomer customer = new CCustomer("123123121", "John", "Smith", "6021111111");
            // orders the same as the store's inventory
            COrder        order = new COrder(store, customer, DateTime.Today, 100, p);
            SimpleDisplay dis   = new SimpleDisplay();

            string          path    = "../../../SimplyWriteData.json";
            JsonFilePersist persist = new JsonFilePersist(path);

            customer.PlaceOrder(store, order);
            persist.WriteStoreData(store);
        }