Exemplo n.º 1
0
        public void IngredientParser_TryReadRealWorldDataIngredients_ShouldSuccessfullyParseIngredient(
            string rawIngredient,
            bool expectedResult,
            ParseResult.IngredientDetails expectedDetails)
        {
            var parser = IngredientParser
                         .Builder
                         .New
                         .WithDefaultConfiguration()
                         .WithParserStrategy(
                new BestFullMatchParserStrategy(
                    BestMatchHeuristics.WeightedTokenHeuristic(TokenWeightResolver)))
                         .Build();

            var result = parser.TryParseIngredient(rawIngredient, out var parseResult);

            Assert.AreEqual(expectedResult, result);

            if (expectedResult)
            {
                Assert.AreEqual(TemplateMatchResult.FullMatch, parseResult.Metadata.MatchResult);
                Assert.IsNotNull(parseResult);
                Assert.AreEqual(expectedDetails.Amount, parseResult.Details.Amount);
                Assert.AreEqual(expectedDetails.Unit, parseResult.Details.Unit);
                Assert.AreEqual(expectedDetails.Form, parseResult.Details.Form);
                Assert.AreEqual(expectedDetails.Ingredient, parseResult.Details.Ingredient);
            }
            else
            {
                Assert.IsNull(parseResult);
            }
        }
Exemplo n.º 2
0
 private static IngredientParser CreateParser()
 {
     return(IngredientParser
            .Builder
            .New
            .WithDefaultConfiguration()
            .WithParserStrategy(new BestFullMatchParserStrategy(
                                    BestMatchHeuristics.WeightedTokenHeuristic(TokenWeightResolver)))
            .Build());
 }