コード例 #1
0
 public PizzaOrderStrategy(List <IProduct> products, IngredientMap ingredientMap, SizeMap sizeMap, IOrderStrategy nextStrategy)
 {
     _products      = products;
     _ingredientMap = ingredientMap;
     _sizeMap       = sizeMap;
     _nextStrategy  = nextStrategy;
 }
コード例 #2
0
        public void GivenExistingAlternativeIngredientNameNotAvailableAtLocation_WhenAskingToMap_ThenItShouldThrow()
        {
            // arrange
            const string  name          = "Crispy Ham";
            IngredientMap ingredientMap = new IngredientMap();

            // act
            Action action = () => ingredientMap.DomainIngredient(name, new Pizza(), new BedrockLocation());

            // assert
            action.Should().Throw <Exception>();
        }
コード例 #3
0
        public void GivenExistingDefaultIngredientNameNotAvailableAtLocation_WhenAskingToMap_ThenItShouldThrow()
        {
            // arrange
            const string  name          = "Bacon";
            IngredientMap ingredientMap = new IngredientMap();

            // act
            Action action = () => ingredientMap.DomainIngredient(name, new Pizza(), new SpringfieldLocation());

            // assert
            action.Should().Throw <Exception>();
        }
コード例 #4
0
        public void GivenExistingIngredientName_WhenAskingToMap_ThenItShouldReturnCorrectIngredient()
        {
            // arrange
            const string  name          = "Olives";
            IngredientMap ingredientMap = new IngredientMap();

            // act
            IIngredient mappedIngredient = ingredientMap.DomainIngredient(name, new Pizza(), new BedrockLocation());

            // assert
            mappedIngredient.Name().ToString().Should().BeEquivalentTo(new OlivesName());
        }
コード例 #5
0
        public void GivenNonExistentIngredientName_WhenAskingToMap_ThenItShouldThrow()
        {
            // arrange
            const string  name          = "Dammit, Bobby!";
            IngredientMap ingredientMap = new IngredientMap();

            // act
            Action action = () => ingredientMap.DomainIngredient(name, new Pizza(), new BedrockLocation());

            // assert
            action.Should().Throw <Exception>();
        }
コード例 #6
0
        public void GivenExistingAlternativeIngredientName_WhenAskingToMap_ThenItShouldReturnCorrectIngredient()
        {
            // arrange
            const string  name          = "Crispy Ham";
            IngredientMap ingredientMap = new IngredientMap();

            // act
            IIngredient mappedIngredient = ingredientMap.DomainIngredient(name, new Pizza(), new SpringfieldLocation());

            // assert
            mappedIngredient.Name().ToString().Should().BeEquivalentTo(new CrispyHamName());
            mappedIngredient.GetType().Name.Should().Be(nameof(CrispyHam));
        }
コード例 #7
0
ファイル: Allergen.cs プロジェクト: gclodge/Advent.2020
        private void PopulateInitialMaps()
        {
            //< Instantiate the 'maps'
            this.AllergenMap   = new AllergenMap();
            this.IngredientMap = new IngredientMap();
            //< Iterate over each available Recipe
            foreach (var recipe in Recipes)
            {
                //< Iterate over each available allergen
                foreach (var allergen in recipe.Allergens)
                {
                    //< Iterate over each ingredient
                    foreach (var ingredient in recipe.Ingredients)
                    {
                        if (!IngredientMap.ContainsKey(ingredient))
                        {
                            IngredientMap.Add(ingredient, new AllergenMap());
                        }

                        if (!IngredientMap[ingredient].ContainsKey(allergen))
                        {
                            IngredientMap[ingredient].Add(allergen, 0);
                        }

                        IngredientMap[ingredient][allergen]++;
                    }
                    //< Populate the allergen map (count of times an allergen is encountered across recipes)
                    if (!AllergenMap.ContainsKey(allergen))
                    {
                        AllergenMap.Add(allergen, 0);
                    }

                    AllergenMap[allergen]++;
                }
            }
        }