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);
        }
Beispiel #2
0
        private static string CheckAndAddOneCustomer(StoreRepository repo, string storeLoc, CStore store, ISearch ss)
        {
            Console.WriteLine("What is the customer's first name?");
            string firstname = ValidateNotNull(Console.ReadLine());

            Console.WriteLine("What is the customer's last name?");
            string lastname = ValidateNotNull(Console.ReadLine());

            Console.WriteLine("What is the customer's phone number?");
            string phonenumber = ValidatePhonenumber(Console.ReadLine());
            string customerid;
            // or use repo.GetOneCustomerByNameAndPhone, check null reference
            // can delay setting up customer profiles
            // by name or by name and phone
            bool Found = ss.SearchByNameAndPhone(store, firstname, lastname, phonenumber, out customerid);

            if (Found)
            {
                Console.WriteLine($"Dear Customer, you already have a profile with us, here is your customer id {customerid}");
            }
            else
            {
                // new customer has no order history atm
                customerid = CIDGen.Gen();
                CCustomer newCustomer = new CCustomer(customerid, firstname, lastname, phonenumber);
                store.AddCustomer(newCustomer);
                repo.StoreAddOneCusomter(storeLoc, newCustomer);
                Console.WriteLine($"Dear {customerid}, your profile has been set up successfuly");
            }
            return(customerid);
        }
Beispiel #3
0
        public void StoreAddACustomer()
        {
            List <CProduct> supply = new List <CProduct>
            {
                new CProduct("111", "Banana", "Produce", 0.5, 10),
                new CProduct("222", "orange", "Produce", 0.88, 10)
            };

            CStore    store    = new CStore("Phoenix101", "606", supply);
            CCustomer customer = new CCustomer("123123121", "John", "Smith", "6021111111");

            store.AddCustomer(customer);
            foreach (var pair in store.CustomerDict)
            {
                if (pair.Key == customer.Customerid)
                {
                    Assert.True(true);
                }
            }
        }