Ejemplo n.º 1
0
        private static void RunMustacheSpecs(MustacheSpec.MustacheTest test)
        {
            TemplateLocator testDataTemplateLocator = name =>
            {
                if (test.Partials != null && test.Partials[name] != null)
                {
                    var template = new Template();
                    template.Load(new StringReader(test.Partials[name].ToString()));
                    return(template);
                }
                ;

                return(null);
            };

            var rendered = Render.StringToString(test.Template, test.Example, testDataTemplateLocator);

            Assert.AreEqual(test.Expected, rendered, "JSON object rendering failed for " + test.Description);

            rendered = Render.StringToString(test.Template, test.StronglyTypedExample, testDataTemplateLocator);
            Assert.AreEqual(test.Expected, rendered, "Strongly typed rendering failed for " + test.Description);

            var templ = new Template();

            templ.Load(new StringReader(test.Template));

            if (!test.Name.ToLower().Contains("context miss") &&
                !test.Name.ToLower().Contains("broken chain") &&
                !(test.SpecName == "inverted" && (test.Name == "List" || test.Name == "Context")))
            {
                var compiledTemplate = templ.Compile(
                    test.StronglyTypedExample != null ? test.StronglyTypedExample.GetType() : typeof(object),
                    testDataTemplateLocator);
                rendered = compiledTemplate(test.StronglyTypedExample);
                Assert.AreEqual(test.Expected, rendered, "Compiled Template rendering failed for " + test.Description);
            }
            else
            {
                bool gotException = false;
                try
                {
                    var compiledTemplate = templ.Compile(
                        test.StronglyTypedExample != null ? test.StronglyTypedExample.GetType() : typeof(object),
                        testDataTemplateLocator);
                }
                catch (Compilation.CompilationException)
                {
                    gotException = true;
                }

                Assert.IsTrue(gotException, "Expected test to throw a compilation exception for an invalid template");
            }
        }
Ejemplo n.º 2
0
 public void Partials(MustacheSpec.MustacheTest test)
 {
     RunMustacheSpecs(test);
 }
Ejemplo n.º 3
0
 public void Inverted(MustacheSpec.MustacheTest test)
 {
     RunMustacheSpecs(test);
 }
Ejemplo n.º 4
0
 public void Interpolation(MustacheSpec.MustacheTest test)
 {
     RunMustacheSpecs(test);
 }
Ejemplo n.º 5
0
 public void Comments(MustacheSpec.MustacheTest test)
 {
     RunMustacheSpecs(test);
 }
Ejemplo n.º 6
0
 public void Sections(MustacheSpec.MustacheTest test)
 {
     RunMustacheSpecs(test);
 }