Exemplo n.º 1
0
        public void GetFoodFromFridge_TakeAFoodToFridge_GetItBack()
        {
            var foodToTest = new Food(120, 30, "tesztalma");

            refrig.AddFood(foodToTest);

            var result = refrig.GetFoodFromFridge("tesztalma");

            Assert.IsNotNull(result);
            Assert.AreSame(foodToTest, result);
        }
Exemplo n.º 2
0
        public void FridgeMenuLogic(Refigrigator refig, string option)
        {
            switch (option)
            {
            case "1":
                Console.Clear();
                try
                {
                    if (refig.ListFood().Count > 0)
                    {
                        foreach (var food in refig.ListFood())
                        {
                            if (food.Size > 80)
                            {
                                Console.WriteLine($"{food.Name} it's a big item!");
                            }
                            else
                            {
                                Console.WriteLine(food.Name);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("There is no food in the fridge");
                    }
                }
                catch (FridgeIsClosedException)
                {
                    Console.WriteLine("Open the fridge first!");;
                }
                break;

            case "2":
                Console.Clear();
                if (refig.IsOpen())
                {
                    Console.WriteLine($"The {refig.Name} is already open!");
                }
                else
                {
                    Console.WriteLine($"You opened the {refig.Name} fridge!");
                    refig.Open();
                }
                break;

            case "3":
                Console.Clear();
                try
                {
                    if (refig.IsOpen())
                    {
                        Console.WriteLine("What is the name of the food?");
                        var foodName = Console.ReadLine();
                        Console.WriteLine("How many calories it has?");
                        var calories = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("What is the size of the food?(If it'size bigger than 80 - it's a big item, if smaller than 20 -it's a small item.)");
                        var size = Convert.ToInt32(Console.ReadLine());
                        refig.AddFood(new Food(calories, size, foodName));

                        if (refig.RemovedShelf != null)
                        {
                            shelves.Add(refig.RemovedShelf);
                            foods.AddRange(refig.RemovedShelf.foodList);
                            refig.RemovedShelf.foodList = new List <Food>();
                            refig.RemovedShelf          = null;
                        }
                    }
                    else
                    {
                        throw new FridgeIsClosedException();
                    }
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("Invalid input - calories and size must be numbers");
                }
                catch (FridgeIsClosedException)
                {
                    Console.WriteLine("Open the fridge first!");
                }
                catch (FridgeIsFullException)
                {
                    Console.WriteLine("This fridge is full!");
                }
                catch (CannotCoolItException)
                {
                    Console.WriteLine("The size of the food not good for this fridge.");
                }
                catch (BigItemCoolingException)
                {
                    Console.WriteLine("This food so huge, you cannat place it to this fridge!");
                }
                break;

            case "4":
                Console.Clear();
                if (Foods.Count > 0)
                {
                    Console.WriteLine("Which food you want to add from the table: ");
                    foreach (var food in Foods)
                    {
                        if (food.Size > 80)
                        {
                            Console.WriteLine($"{food.Name} it's a big item!");
                        }
                        else
                        {
                            Console.WriteLine(food.Name);
                        }
                    }
                    try
                    {
                        if (refig.IsOpen())
                        {
                            var foodName           = Console.ReadLine();
                            var foodToAddFromTable = mh.FindFoodInTable(foodName, Foods);
                            refig.AddFood(foodToAddFromTable);

                            if (refig.RemovedShelf != null)
                            {
                                shelves.Add(refig.RemovedShelf);
                                foods.AddRange(refig.RemovedShelf.foodList);
                                refig.RemovedShelf.foodList = new List <Food>();
                                refig.RemovedShelf          = null;
                            }
                            Foods.Remove(foodToAddFromTable);
                        }
                        else
                        {
                            throw new FridgeIsClosedException();
                        }
                    }
                    catch (System.FormatException)
                    {
                        Console.WriteLine("Invalid input - calories and size must be numbers");
                    }
                    catch (FridgeIsClosedException)
                    {
                        Console.WriteLine("Open the fridge first!");
                    }
                    catch (FridgeIsFullException)
                    {
                        Console.WriteLine("This fridge is full!");
                    }
                    catch (CannotCoolItException)
                    {
                        Console.WriteLine("The size of the food not good for this fridge.");
                    }
                }
                else
                {
                    Console.WriteLine("There is no food in the table!");
                }
                break;

            case "5":
                Console.Clear();
                try
                {
                    Console.WriteLine("What food you want to take to the table?");
                    var foodToAddName = Console.ReadLine();
                    Foods.Add(refig.GetFoodFromFridge(foodToAddName));
                }
                catch (FoodNotExistsException)
                {
                    Console.WriteLine("Fridge doesn't contains it.");
                }

                break;

            case "6":
                Console.Clear();
                try
                {
                    Console.WriteLine("What you want to eat?");
                    var foodToEat = Console.ReadLine();
                    consumedCalories += refig.GetFoodFromFridge(foodToEat).Calories;
                }
                catch (FoodNotExistsException)
                {
                    Console.WriteLine("You have no food called like that!");
                }
                catch (FridgeIsClosedException)
                {
                    Console.WriteLine("Open the fridge first!");
                }
                break;

            case "7":
                Console.Clear();
                try
                {
                    Console.WriteLine($"Your {refig.Name} fridge has {refig.GetFreeSpace()} unit free space.");
                }
                catch (FridgeIsClosedException)
                {
                    Console.WriteLine("Please open the fridge first");
                }
                break;

            case "8":
                Console.Clear();
                try
                {
                    Console.WriteLine("Which shelf you want to remove?");
                    for (int i = 0; i < refig.shelfContainer.Length; i++)
                    {
                        if (refig.shelfContainer[i] != null)
                        {
                            Console.WriteLine(i + 1);
                        }
                    }
                    var shelfToRemove = Convert.ToInt32(Console.ReadLine());
                    var removedShelf  = refig.RemoveShelf(shelfToRemove - 1);

                    shelves.Add(removedShelf);
                    foods.AddRange(removedShelf.foodList);
                    removedShelf.foodList = new List <Food>();
                    Console.WriteLine($"You have removed the number {shelfToRemove} shelf!");
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("Invalid Input, pls give a number!");
                }
                catch (FridgeIsClosedException)
                {
                    Console.WriteLine("Please open the fridge first");
                }
                catch (ShelfAlreadyRemovedException)
                {
                    Console.WriteLine("The choosen shelf already out of the fridge");
                }
                catch (NotEnoughShelfException)
                {
                    Console.WriteLine("The fridge doesn't have as many shelves!");
                }
                break;

            case "9":
                Console.Clear();
                try
                {
                    var emptyslots = refig.FindEmptySlots();

                    Console.WriteLine("This fridge misses the following shelfes:");
                    foreach (var num in emptyslots)
                    {
                        Console.WriteLine(num + 1);
                    }
                    Console.WriteLine("Which shelf you want to take back?");
                    var id = Convert.ToInt32(Console.ReadLine());

                    var shelfToTakeBack = mh.FindShelfByIdANdSize(id, refig.fridgeSize, shelves);
                    refig.AddShelf(shelfToTakeBack);
                    shelves.Remove(shelfToTakeBack);
                }
                catch (BigItemCoolingException)
                {
                    Console.WriteLine("There are a big food which dont let you take the shelf back");
                }
                catch (NoEmptyShelfPlaceException)
                {
                    Console.WriteLine("There are no empty shelf place!");
                }
                catch (System.FormatException)
                {
                    Console.WriteLine("The input must be a number!");
                }
                catch (FridgeIsClosedException)
                {
                    Console.WriteLine("Please open the fridge first");
                }
                break;

            case "10":
                Console.Clear();
                Console.WriteLine("The fridge is closed");
                refig.Close();
                break;

            case "0":
                Console.Clear();
                refig.Close();
                inFridge = false;
                break;

            default:
                Console.Clear();
                Console.WriteLine("Invalid input");
                break;
            }
        }