public void ReturnsResultWithFourAgents_When_ListContainsFourAgents()
        {
            //Arrange
            List<HouseForSale> housesForSale = GetListWithFourAgents();
            var target = new Business();

            //Act
            var result = target.GetImportantAgents(housesForSale, 4);

            //Assert
            Assert.IsTrue(result.Count() == 4);
        }
        private static async Task ListHousesForSaleInAmsterdam(string city, params string[] parameters)
        {
            var fundaApiAccessor = new APIAccessor();
            
            IEnumerable<HouseForSale> housesForSale = await fundaApiAccessor.GetHousesForSale(city, parameters);

            IEnumerable<AgentImportance> topTenAgentsWithMostHousesForSale = new Business().GetImportantAgents(housesForSale, 10);

            Console.WriteLine("Results:");
            foreach (var agentImp in topTenAgentsWithMostHousesForSale)
            {
                Console.WriteLine(agentImp.Agent.Name + " " + agentImp.AmountOfHousesForSale);
            }
        }
        public void ReturnsAgentsWithCorrectAmountOfHousesInDescendingOrder_When_ListContainsFourAgents()
        {
            //Arrange
            List<HouseForSale> housesForSale = GetListWithFourAgents();
            var target = new Business();

            //Act
            var result = target.GetImportantAgents(housesForSale, 4);

            //Assert
            var resultItem1 = result.ElementAt(0);
            var resultItem2 = result.ElementAt(1);
            var resultItem3 = result.ElementAt(2);
            var resultItem4 = result.ElementAt(3);

            Assert.IsTrue(resultItem1.Agent.Id == 10 && resultItem1.AmountOfHousesForSale==10);
            Assert.IsTrue(resultItem2.Agent.Id == 9 && resultItem2.AmountOfHousesForSale == 9);
            Assert.IsTrue(resultItem3.Agent.Id == 8 && resultItem3.AmountOfHousesForSale == 8);
            Assert.IsTrue(resultItem4.Agent.Id == 1 && resultItem4.AmountOfHousesForSale == 1);
        }
Esempio n. 4
0
 //**************************************************
 // Method: Constructor
 //
 // Purpose: Initializing the Business and Others
 //          properties.
 //**************************************************
 public MenuB(Business b, ObservableCollection <Business> o)
 {
     Business = b;
     Others   = o;
     mainMenu();
 }
Esempio n. 5
0
        //**************************************************
        // Method: viewInv
        //
        // Purpose: Viewing the inventory of a Business.
        //**************************************************
        private void viewInv(Business dispo)
        {
            int count = 0;
            ObservableCollection <MenuItem[]> inv = getInv(dispo);

            string choice;

            do
            {
                Console.Clear();
                string[] choices = new string[9];
                choices[0] = "<";
                choices[1] = ">";
                choices[2] = "0";

                Console.WriteLine(dispo.Name + "'s Inventory");
                Console.WriteLine("\t\t\t\tPage " + (count + 1));
                Console.WriteLine("====================================");
                int counter = 1;
                foreach (MenuItem item in inv[count])
                {
                    if (item != null)
                    {
                        Console.WriteLine(counter + ". " + item.Name);
                        choices[counter + 2] = counter.ToString();
                        counter++;
                    }
                }
                Console.WriteLine("0. Exit");
                Console.WriteLine("====================================");
                Console.Write("Enter selection (type '<'/'>' to switch pages): ");
                choice = Console.ReadLine();
                while (Array.Find(choices, c => c == choice) == null)
                {
                    Console.Write("Invalid. Re-enter selection: ");
                    choice = Console.ReadLine();
                }

                if (choice == "<")
                {
                    if (count > 0)
                    {
                        count--;
                    }
                    else
                    {
                        count = inv.Count - 1;
                    }
                }
                else if (choice == ">")
                {
                    if (count < inv.Count - 1)
                    {
                        count++;
                    }
                    else
                    {
                        count = 0;
                    }
                }
                else
                {
                    int n = Convert.ToInt32(choice);
                    if (n < 7 && n > 0)
                    {
                        viewItem(inv[count][n - 1], dispo == Business);
                        inv = getInv(dispo);
                    }
                }
            } while (choice != "0");
        }
Esempio n. 6
0
        //**************************************************
        // Method: viewDispos
        //
        // Purpose: Viewing other businesses and their
        //          inventories.
        //**************************************************
        private void viewDispos()
        {
            ObservableCollection <Business[]> list = new ObservableCollection <Business[]>();
            int count = 0;

            Business[] arr = new Business[6];

            foreach (Business b in Others)
            {
                if (count > 5)
                {
                    list.Add(arr);
                    count = 0;
                    arr   = null;
                }
                if (count == 0 && arr == null)
                {
                    arr = new Business[6];
                }
                arr[count] = b;
                count++;
            }
            if (arr != null)
            {
                list.Add(arr);
            }
            count = 0;

            string choice;

            do
            {
                Console.Clear();
                string[] choices = new string[9];
                choices[0] = "<";
                choices[1] = ">";
                choices[2] = "0";

                Console.WriteLine("Browse Dispensaries");
                Console.WriteLine("\t\t\t\tPage " + (count + 1));
                Console.WriteLine("====================================");
                int counter = 1;
                foreach (Business b in list[count])
                {
                    if (b != null)
                    {
                        Console.WriteLine(counter + ". " + b.Name);
                        choices[counter + 2] = counter.ToString();
                        counter++;
                    }
                }
                Console.WriteLine("0. Exit");
                Console.WriteLine("====================================");
                Console.Write("Enter selection (type '<'/'>' to switch pages): ");
                choice = Console.ReadLine();
                while (Array.Find(choices, c => c == choice) == null)
                {
                    Console.Write("Invalid. Re-enter selection: ");
                    choice = Console.ReadLine();
                }

                if (choice == "<")
                {
                    if (count > 0)
                    {
                        count--;
                    }
                    else
                    {
                        count = list.Count - 1;
                    }
                }
                else if (choice == ">")
                {
                    if (count < list.Count - 1)
                    {
                        count++;
                    }
                    else
                    {
                        count = 0;
                    }
                }
                else
                {
                    int n = Convert.ToInt32(choice);
                    if (n < 7 && n > 0)
                    {
                        if (list[count][n - 1].Items.Count == 0)
                        {
                            Console.WriteLine("This dispensary doesn't have products yet.");
                            string wait = Console.ReadLine();
                        }
                        else
                        {
                            viewInv(list[count][n - 1]);
                        }
                    }
                }
            } while (choice != "0");
        }
Esempio n. 7
0
        //**************************************************
        // Method: viewCart
        //
        // Purpose: Viewing and editing the cart.
        //**************************************************
        private void viewCart()
        {
            string choice;

            string[] choices = new string[cart.Count + 3];
            choices[0] = "b";
            choices[1] = "c";
            choices[2] = "o";
            for (int i = 0; i < cart.Count; i++)
            {
                choices[i + 3] = (i + 1).ToString();
            }

            do
            {
                Console.Clear();
                Console.WriteLine("Cart\t\t\t\t$" + getTotalPrice());
                Console.WriteLine("====================================");
                int count = 1;
                foreach (MenuItem item in cart)
                {
                    if (count > 1)
                    {
                        Console.WriteLine("------------------------------------");
                    }
                    Console.WriteLine(count + ". " + item.Name);
                    count++;
                }
                Console.WriteLine("====================================");
                Console.WriteLine("Options: (B)ack, (C)lear, Check(O)ut");
                Console.Write("Enter item number or option above: ");
                choice = Console.ReadLine().ToLower();
                while (Array.Find(choices, c => c == choice) == null)
                {
                    Console.Write("Invalid. Re-enter selection: ");
                    choice = Console.ReadLine();
                }
                if (choice == "o" || choice == "c")
                {
                    if (choice == "o")
                    {
                        Address a;
                        if (Customer.Addresses.Count == 0)
                        {
                            a = getAddress(2);
                        }
                        else
                        {
                            Console.Clear();
                            Console.WriteLine("1. Select an address");
                            Console.WriteLine("2. Enter a new address");
                            int selection = getChoice(1, 2);
                            a = getAddress(selection);
                        }
                        Order o = new Order();
                        o.Date        = DateTime.Today.ToString("d");
                        o.TotalPrice  = getTotalPrice();
                        o.DasherShare = "0.15";
                        o.Status      = "Pending";
                        o.Business    = mainDispo;
                        o.Address     = a;
                        foreach (MenuItem item in cart)
                        {
                            o.Items.Add(item);
                        }
                        Customer.Orders.Add(o);
                    }
                    cart.Clear();
                }
                else if (choice != "b")
                {
                    int answer, n = Convert.ToInt32(choice) - 1;
                    Console.WriteLine("1. Remove from Cart");
                    Console.WriteLine("2. Cancel");
                    answer = getChoice(1, 2);
                    if (answer == 1)
                    {
                        cart.RemoveAt(n);
                    }
                }
            } while (choice != "b" && cart.Count > 0);
            if (cart.Count == 0)
            {
                mainDispo = null;
            }
        }