Ejemplo n.º 1
0
        public void Should_return_an_unit_when_provided_a_correct_menu_item()
        {
            //arrange
            var keyPair = (TimeOfDayType.Morning, DishType.Entree);
            var dish    = new Dish("eggs", AllowedOrderType.Single);
            var dict    = new Dictionary <(TimeOfDayType, DishType), Dish> {
                { keyPair, dish }
            };

            var dishesMenuServiceFake = A.Fake <IDishesMenuService>();

            A.CallTo(() => dishesMenuServiceFake.TryAddDish(keyPair, dish)).Returns(true);

            var inputProcessorService = new InputProcessorService(dishesMenuServiceFake);
            var exception             = default(ArgumentException);
            var unit = default(Unit);

            //act
            var setupResult = inputProcessorService.Setup(dict);

            setupResult.Match(
                failure: ex => exception = ex,
                success: _ =>
            {
                unit = _;
            }
                );

            //assert
            exception.Should().BeNull("Because the setup will succeed and return a unit");
        }
Ejemplo n.º 2
0
        public void Should_not_update_a_dish_when_the_dish_name_is_null()
        {
            //arrange
            const DishType      dishType        = DishType.Drink;
            const string        dishName        = default(string);
            const TimeOfDayType timeOfDay       = TimeOfDayType.Morning;
            const int           nextAmountToAdd = 2;

            var dishes = new Dictionary <(DishType, string), int> {
                { (dishType, dishName), 1 }
            };

            var dishesMenuServiceFake = A.Fake <IDishesMenuService>();

            A.CallTo(() => dishesMenuServiceFake.IsValidAmount(
                         timeOfDay,
                         dishType,
                         nextAmountToAdd)
                     ).Returns(false);

            var inputProcessorService = new InputProcessorService(dishesMenuServiceFake);

            //act
            var dishAddedOrUpdated = inputProcessorService.TryAddOrUpdateDishesAmount(
                dishes,
                timeOfDay,
                dishType,
                dishName
                );

            //assert
            dishAddedOrUpdated.Should().BeFalse("Because when the dish name is null it's considered a error");
        }
Ejemplo n.º 3
0
        public void Should_not_update_a_dish_when_the_name_already_exists_and_disallow_multiple_orders()
        {
            //arrange
            const DishType      dishType        = DishType.Drink;
            var                 dish            = new Dish("eggs", AllowedOrderType.Single);
            const TimeOfDayType timeOfDay       = TimeOfDayType.Morning;
            const int           nextAmountToAdd = 2;

            var dishes = new Dictionary <(DishType, string), int> {
                { (dishType, dish.Name), 1 }
            };

            var dishesMenuServiceFake = A.Fake <IDishesMenuService>();

            A.CallTo(() => dishesMenuServiceFake.IsValidAmount(
                         timeOfDay,
                         dishType,
                         nextAmountToAdd)
                     ).Returns(false);

            var inputProcessorService = new InputProcessorService(dishesMenuServiceFake);

            //act
            var dishAddedOrUpdated = inputProcessorService.TryAddOrUpdateDishesAmount(
                dishes,
                timeOfDay,
                dishType,
                dish.Name
                );

            //assert
            dishAddedOrUpdated.Should().BeFalse("Because the dish disallow multiple orders, the rule will not be satisfied");
        }
Ejemplo n.º 4
0
        public void Should_add_the_dish_when_this_is_the_first()
        {
            //arrange
            var dishes = new Dictionary <(DishType, string), int>();
            const TimeOfDayType timeOfDay = TimeOfDayType.Morning;
            const DishType      dishType  = DishType.Drink;
            var dish = new Dish("coffee", AllowedOrderType.Multiple);

            var dishesMenuServiceFake = A.Fake <IDishesMenuService>();

            A.CallTo(() => dishesMenuServiceFake.IsValidAmount(timeOfDay, dishType, 1)).Returns(true);

            var inputProcessorService = new InputProcessorService(dishesMenuServiceFake);

            //act
            var dishAddedOrUpdated = inputProcessorService.TryAddOrUpdateDishesAmount(
                dishes,
                timeOfDay,
                dishType,
                dish.Name
                );

            //assert
            dishAddedOrUpdated.Should().BeTrue("Because the dish allow multiple orders, the rule will be satisfied and should be added");
        }
Ejemplo n.º 5
0
        public void Should_return_empty_timeOfDay_when_provided_a_non_registered_timeOfDay()
        {
            //arrange
            var          input = new string[] { "evening" };
            var          dishesMenuServiceFake = A.Fake <IDishesMenuService>();
            var          inputProcessorService = new InputProcessorService(dishesMenuServiceFake);
            const string morningText           = default(string);

            //act
            var timeOfDay = inputProcessorService.ParseTimeOfDay(input);

            //assert
            timeOfDay.Should().Be(morningText, "Because will not be found, if the value don't exists it's considered an error");
        }
Ejemplo n.º 6
0
        public void Should_return_a_normalized_timeOfDay_when_provided_a_correct_string()
        {
            //arrange
            var input = new string[] { "MorNing" };
            var dishesMenuServiceFake = A.Fake <IDishesMenuService>();
            var inputProcessorService = new InputProcessorService(dishesMenuServiceFake);
            var morningText           = TimeOfDayType.Morning.ToString();

            //act
            var timeOfDay = inputProcessorService.ParseTimeOfDay(input);

            //assert
            timeOfDay.Should().Be(morningText, "Because will be found, no matter the case, if the value exists on TimeOfDayType (ex: Morning, Night)");
        }
Ejemplo n.º 7
0
        public void Should_return_an_argumentException_when_provided_a_null()
        {
            //arrange
            var dishesMenuServiceFake = A.Fake <IDishesMenuService>();
            var inputProcessorService = new InputProcessorService(dishesMenuServiceFake);
            var exception             = default(ArgumentException);

            //act
            var setupResult = inputProcessorService.Setup(null);

            setupResult.Match(
                failure: ex => exception = ex,
                success: _ => { }
                );

            //assert
            exception.Should().BeOfType(typeof(ArgumentException), "Because the setup will fail");
        }
Ejemplo n.º 8
0
        public void Should_the_input_be_processed_with_success_when_looks_like_the_first_test_sample_input()
        {
            //arrange
            var dishesMenuServiceFake = A.Fake <IDishesMenuService>();

            A.CallTo(() => dishesMenuServiceFake.HasDishes()).Returns(true);

            A.CallTo(() => dishesMenuServiceFake.FindDish(TimeOfDayType.Morning, DishType.Entree)).Returns("eggs");
            A.CallTo(() => dishesMenuServiceFake.FindDish(TimeOfDayType.Morning, DishType.Side)).Returns("toast");
            A.CallTo(() => dishesMenuServiceFake.FindDish(TimeOfDayType.Morning, DishType.Drink)).Returns("coffee");

            var          inputProcessorService = new InputProcessorService(dishesMenuServiceFake);
            const string input          = "morning, 1, 2, 3";
            var          exception      = default(Exception);
            var          processResult  = default(InputProcessResult);
            var          expectedOutput = new Dictionary <(DishType, string), int>
            {
                { (DishType.Entree, "eggs"), 1 },