public void ComplexTemplateWithTemplateDataContainingEnum()
        {
            // The template
            const string Templ = "@{\n" +
                                 "string dateFormat;\n" +
                                 "@switch((TestEnum)TemplateData.DateFormat)\n" +
                                 "{\n" +
                                 "case TestEnum.Option1:\n" +
                                 "dateFormat = \"dd/MM/yyyy\";\n" +
                                 "break;\n" +
                                 "case TestEnum.Option2:\n" +
                                 "default:\n" +
                                 "dateFormat = \"MM/dd/yyyy\";\n" +
                                 "break;\n" +
                                 "}\n" +
                                 "}" +
                                 "Hello @Model.Name (@Model.DateOfBirth.ToString(dateFormat))";
            var expected = "Hello Shay (04/12/1983)";

            // Arrange
            var model = new
            {
                Name        = "Shay",
                DateOfBirth = new DateTime(1983, 12, 4)
            };
            Action <dynamic> templateData = a => a.DateFormat = TestEnum.Option1;
            var service =
                RazorEngineHost.Create(
                    c => c
                    .WithBaseTemplateType(typeof(TemplateBase <>))
                    .IncludeNamespaces(typeof(TestEnum).Namespace));

            // Act
            this.CompileRunAndAssert(service, Templ, expected, model, configTemplateData: templateData);
        }
        public void ConditionalAttribute()
        {
            // The template
            const string Templ    = "@{object f = null;}<p class=\"foo @f bar\" />";
            var          expected = "<p class=\"foo bar\" />";

            // Arrange
            var service = RazorEngineHost.Create(c => c.WithBaseTemplateType(typeof(TemplateBase <>)));

            // Act
            this.CompileRunAndAssert(service, Templ, expected);
        }
        public void NonLiteralAttribute()
        {
            // The template
            const string Templ    = "<p class=\"@Environment.Version\"/>";
            var          expected = "<p class=\"" + Environment.Version + "\"/>";

            // Arrange
            var service = RazorEngineHost.Create(c => c.WithBaseTemplateType(typeof(TemplateBase <>)));

            // Act
            this.CompileRunAndAssert(service, Templ, expected);
        }
        public void HtmlRaw()
        {
            // The template
            const string Templ    = "<p>@Html.Raw(\"<p>\")</p>";
            var          expected = "<p><p></p>";

            // Arrange
            var service = RazorEngineHost.Create(c => c.WithBaseTemplateType(typeof(HtmlTemplateBase <>)));

            // Act
            this.CompileRunAndAssert(service, Templ, expected);
        }
        public void SimpleTemplate()
        {
            // The template
            const string Templ    = "<p>@Environment.Version</p>";
            var          expected = "<p>" + Environment.Version + "</p>";

            // Arrange
            var service = RazorEngineHost.Create(c => c.WithBaseTemplateType(typeof(TemplateBase <>)));

            // Act
            this.CompileRunAndAssert(service, Templ, expected);
        }
        public void DynamicModelTemplate()
        {
            // The template
            const string Templ    = "Hello @Model.Name";
            var          expected = "Hello Shay";

            // Arrange
            var model = new
            {
                Name = "Shay"
            };
            var service = RazorEngineHost.Create(c => c.WithBaseTemplateType(typeof(TemplateBase <>)));

            // Act
            this.CompileRunAndAssert(service, Templ, expected, model);
        }
        public void DynamicTemplateWithTemplateData()
        {
            // The template
            const string Templ    = "Hello @Model.Name (@Model.DateOfBirth.ToString(TemplateData.DateFormat))";
            var          expected = "Hello Shay (04/12/1983)";

            // Arrange
            var model = new
            {
                Name        = "Shay",
                DateOfBirth = new DateTime(1983, 12, 4)
            };
            Action <dynamic> templateData = a => a.DateFormat = "dd/MM/yyyy";
            var service = RazorEngineHost.Create(c => c.WithBaseTemplateType(typeof(TemplateBase <>)));

            // Act
            this.CompileRunAndAssert(service, Templ, expected, model, configTemplateData: templateData);
        }
        public void ModelWithChildTemplate()
        {
            // The template
            const string Templ    = "Hello @Model.Child.Name (@Model.D.ToString(\"F2\"))";
            var          expected = "Hello Shay (1.23)";

            // Arrange
            var model = new TestParentModel
            {
                D     = 1.234,
                Child = new TestModelA
                {
                    Name = "Shay"
                }
            };
            var service = RazorEngineHost.Create(c => c.WithBaseTemplateType(typeof(TemplateBase <>)));

            // Act
            this.CompileRunAndAssert(service, Templ, expected, model, typeof(TestParentModel));
        }
        public void DynamicModelWithChildTemplate()
        {
            // The template
            const string Templ    = "Hello @Model.Name (@Model.Child.Email)";
            var          expected = "Hello Shay ([email protected])";

            // Arrange
            var model = new
            {
                Name  = "Shay",
                Child = new
                {
                    Email = "*****@*****.**"
                }
            };
            var service = RazorEngineHost.Create(c => c.WithBaseTemplateType(typeof(TemplateBase <>)));

            // Act
            this.CompileRunAndAssert(service, Templ, expected, model);
        }
        public void ModelWithInheritanceTemplate()
        {
            // The template
            const string Templ    = "Hello @Model.Child.Name (@Model.Child.Color.Name)";
            var          expected = "Hello Shay (Green)";

            // Arrange
            var model = new TestParentModel
            {
                D     = 1.234,
                Child = new TestModelA
                {
                    Name  = "Shay",
                    Color = new TestColorModel
                    {
                        Name = "Green"
                    }
                }
            };
            var service = RazorEngineHost.Create(c => c.WithBaseTemplateType(typeof(TemplateBase <>)));

            // Act
            this.CompileRunAndAssert(service, Templ, expected, model, typeof(TestParentModel));
        }