Exemplo n.º 1
0
        public void CanParseArrayOfStrings()
        {
            var strings = new List <string> {
                "hello there", "hola", "what do you have there?"
            };

            Assert.Equal("there", ReactionParser.MostFrequentWord(strings));
        }
        public string GetAndUpdateMostCommonWord(int eventId)
        {
            //This contoller method demonstrates the NEW BEHAVIOR of DbContext.Entry.State
            //which will only affect the root of the graph passed in
            var eventGraph = _repo.GetWeatherEventAndReactionsById(eventId);
            var theWord    = ReactionParser.MostFrequentWord(
                eventGraph.Reactions.Select(r => r.Quote).ToList());

            eventGraph.MostCommonWord = theWord;
            _repo.UpdateWeatherEventOnly(eventGraph);
            Console.WriteLine($"NOTE: Graph still has {eventGraph.Reactions.Count} reactions attached");
            return(theWord);
        }
Exemplo n.º 3
0
        public void CanParseRecipe(string input, string inputIngredients, int outputQuantity, string outputName)
        {
            var parser = new ReactionParser();
            var recipe = parser.Parse(input).First();

            var parsedIngredients = inputIngredients.Split(",")
                                    .Select(part => parser.ParseIngredient(part));

            Assert.Equal(recipe.Output.Quantity, outputQuantity);
            Assert.Equal(recipe.Output.Ingredient, outputName);

            foreach (var pi in parsedIngredients)
            {
                Assert.Contains(pi, recipe.Ingredients);
            }
        }