Skip to content

How to get a complex model to parce? #41

@BrettBock

Description

@BrettBock

The unit test below fails because the result is just a ToString() of the SimpleModel.

How do we get the RazorMachine to use the SimpleModel template?

namespace RazorMachine.Test
{
    public class SimpleModel
    {
        public string Name { get; set; }
    }

    public class ComplexModel
    {
        public SimpleModel SubProperty { get; set; }
    }

    [TestClass]
    public class RazorMachineTest
    {
        [TestMethod]
        public void ComplexModel()
        {
            const string expected = "name";

            var model = new ComplexModel() { SubProperty = new SimpleModel() { Name = expected } };

            var engine = new RazorMachine(includeGeneratedSourceCode: true);
            engine.RegisterTemplate("~/SimpleModel.cshtml",
@"@model RazorMachine.Test.SimpleModel
@Model.Name");
            ITemplate test = engine.Execute("@Model.SubProperty", model);

            Assert.AreEqual(expected, test.ToString());
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions