public void Run_ValidInputs_ReeturnsExpectedResults(string[] evaluations, int numberOfExpectedPassedResults)
        {
            var template =
                JObject.Parse(
                    @"{
                    ""$schema"": ""https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#"",
                    ""resources"": [
                        {
                            ""type"": ""Microsoft.ResourceProvider/resource0"",
                            ""properties"": {
                                ""somePath"": ""someValue""
                            }
                        }
                    ]
                }");

            string expectedFileId     = "MyTemplate";
            int    expectedLineNumber = 5;

            var rules = CreateRulesFromEvaluations(evaluations);


            TemplateContext templateContext = new TemplateContext {
                OriginalTemplate   = template,
                ExpandedTemplate   = template,
                IsMainTemplate     = true,
                TemplateIdentifier = expectedFileId
            };

            // Setup mock line number resolver
            var mockLineResolver = new Mock <IJsonLineNumberResolver>();

            mockLineResolver.Setup(r =>
                                   r.ResolveLineNumberForOriginalTemplate(
                                       It.IsAny <string>(),
                                       It.Is <JToken>(templateContext.ExpandedTemplate, EqualityComparer <object> .Default),
                                       It.Is <JToken>(templateContext.OriginalTemplate, EqualityComparer <object> .Default)))
            .Returns(expectedLineNumber);

            var ruleEngine = new JsonRuleEngine(mockLineResolver.Object);
            var results    = ruleEngine.EvaluateRules(templateContext, rules).ToList();

            Assert.AreEqual(evaluations.Length, results.Count());
            Assert.AreEqual(numberOfExpectedPassedResults, results.Count(result => result.Passed));
            for (int i = 0; i < evaluations.Length; i++)
            {
                var result = results[i];
                Assert.AreEqual($"RuleName {i}", result.RuleName);
                Assert.AreEqual(expectedFileId, result.FileIdentifier);
                Assert.AreEqual(expectedLineNumber, result.LineNumber);
            }
        }
        /// <summary>
        /// Runs the TemplateAnalyzer logic given the template and parameters passed to it
        /// </summary>
        /// <returns>An enumerable of TemplateAnalyzer results</returns>
        public IEnumerable <IResult> EvaluateRulesAgainstTemplate()
        {
            JToken templatejObject;

            try
            {
                ArmTemplateProcessor armTemplateProcessor = new ArmTemplateProcessor(Template);
                templatejObject = armTemplateProcessor.ProcessTemplate(Parameters);
            }
            catch (Exception e)
            {
                throw new TemplateAnalyzerException("Error while processing template.", e);
            }

            if (templatejObject == null)
            {
                throw new TemplateAnalyzerException("Processed Template cannot be null.");
            }

            try
            {
                var rules          = LoadRules();
                var jsonRuleEngine = new JsonRuleEngine(new JsonLineNumberResolver());

                IEnumerable <IResult> results = jsonRuleEngine.EvaluateRules(
                    new TemplateContext {
                    OriginalTemplate = JObject.Parse(Template),
                    ExpandedTemplate = templatejObject,
                    IsMainTemplate   = true
                },
                    rules);

                return(results);
            }
            catch (Exception e)
            {
                throw new TemplateAnalyzerException("Error while evaluating rules.", e);
            }
        }