Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get a complex model to parce? #41

Open
BrettBock opened this issue Nov 21, 2015 · 0 comments
Open

How to get a complex model to parce? #41

BrettBock opened this issue Nov 21, 2015 · 0 comments

Comments

@BrettBock
Copy link

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());
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant