public async Task TemplateEngineShouldUseSameNamingConventionForBinding() { var cacheProvider = new MemoryCacheProvider(); var handlerFactory = new Mock <IHelperHandlerFactory>(); handlerFactory.Setup(f => f.Create()).Returns(Enumerable.Empty <IHelperHandler>()); var namingRule = new NamingRule(); var schemaProvider = new HandlebarsViewSchemaProvider(null, new MemberLocatorFromNamingRule(namingRule)); var codeGenerator = new JsonSchemaCodeGenerator(namingRule); const string input = "<p>{{name}}</p><p>{{first_name}}</p>"; var templateInfo = new StringTemplateInfo("views/test", input); var schema = await schemaProvider.GetSchemaFromTemplateAsync(templateInfo).ConfigureAwait(false); var modelType = codeGenerator.Compile(schema); var viewEngine = new VeilViewEngine(cacheProvider, handlerFactory.Object, namingRule); var view = await viewEngine.CreateViewAsync(templateInfo, modelType).ConfigureAwait(false); var model = Activator.CreateInstance(modelType); modelType.GetProperty("Name").SetValue(model, "{{name}}"); modelType.GetProperty("FirstName").SetValue(model, "{{first_name}}"); var writer = new StringWriter(); view.Render(model, new RenderingContext(writer)); var stringResult = writer.ToString(); Assert.AreEqual(input, stringResult); }
public void TestCompileComplexType() { var path = "Schemas/listComplex.json"; var generator = new JsonSchemaCodeGenerator(); var schema = GetSchema(Path.Combine(TestContext.DeploymentDirectory, path)); var type = generator.Compile(schema); Assert.IsNotNull(type); }
private async Task <string> ExecuteServerSideStrongModel(string testName, string templateFile, string dataFile) { var cacheProvider = new NullCacheProvider(); var namingRule = new NamingRule(); var handlerFactory = new NullRenderingHelperHandlerFactory(); var templateInfo = new FileTemplateInfo(testName, PathInfo.Create(templateFile), new FileSystem()); var schemaProvider = new HandlebarsViewSchemaProvider(handlerFactory, new MemberLocatorFromNamingRule(namingRule)); var generator = new JsonSchemaCodeGenerator(namingRule); var schema = await schemaProvider.GetSchemaFromTemplateAsync(templateInfo).ConfigureAwait(false); schema.Title = "Model"; var modelType = generator.Compile(schema); var viewEngine = new VeilViewEngine(cacheProvider, handlerFactory, namingRule); var view = await viewEngine.CreateViewAsync(templateInfo, modelType).ConfigureAwait(false); if (view == null) { Assert.Fail("Could not create view from file '{0}'.", templateFile); } object model; using (var reader = new JsonTextReader(new StreamReader(dataFile))) { model = JsonSerializer.Create().Deserialize(reader, modelType); } this.TestContext.BeginTimer("ServerStrong"); var builder = new StringBuilder(); using (var writer = new StringWriterDelayed(builder)) { view.Render(model, new RenderingContext(writer)); } var resultString = builder.ToString(); this.TestContext.EndTimer("ServerStrong"); return(resultString); }
private static string GenerateCode(JSchema schema) { var generator = new JsonSchemaCodeGenerator(); return(generator.Generate(schema)); }
private static string GenerateCode(JSchema schema) { var generator = new JsonSchemaCodeGenerator(); return generator.Generate(schema); }