public RazorTemplateCodeWriter( [NotNull] IFileService fileService, [NotNull] RazorTemplating templateEngine) : base(fileService) { Check.NotNull(templateEngine, nameof(templateEngine)); TemplateEngine = templateEngine; }
public async void RunTemplateAsync_Generates_Text_For_Template_With_A_Model() { //Arrange var templateContent = "Hello @Model.Name"; var model = new SimpleModel () { Name = "World" }; var compilationService = GetCompilationService(); var templatingService = new RazorTemplating(compilationService); //Act var result = await templatingService.RunTemplateAsync(templateContent, model); //Assert Assert.Equal("Hello World", result.GeneratedText); Assert.Null(result.ProcessingException); }
public async void RunTemplateAsync_Returns_Error_For_Invalid_Template() { //Arrange var templateContent = "@Invalid"; var compilationService = GetCompilationService(); var templatingService = new RazorTemplating(compilationService); //Act var result = await templatingService.RunTemplateAsync(templateContent, templateModel:"DoesNotMatter"); //Assert Assert.Equal("", result.GeneratedText); Assert.NotNull(result.ProcessingException); Assert.Equal("Template Processing Failed:(1,7): error CS0103: The name 'Invalid' does not exist in the current context", result.ProcessingException.Message); }
public async void RunTemplateAsync_Returns_Error_For_Invalid_Template() { //Arrange var templateContent = "@Invalid"; var compilationService = GetCompilationService(); var templatingService = new RazorTemplating(compilationService); //Act var result = await templatingService.RunTemplateAsync(templateContent, templateModel : "DoesNotMatter"); //Assert Assert.Equal("", result.GeneratedText); Assert.NotNull(result.ProcessingException); Assert.Equal("Template Processing Failed:(1,2): error CS0103: The name 'Invalid' does not exist in the current context", result.ProcessingException.Message); }
public async void RunTemplateAsync_Generates_Text_For_Template_With_A_Model() { //Arrange var templateContent = @"Hello @Model.Name"; var model = new SimpleModel() { Name = "World" }; var compilationService = GetCompilationService(); var templatingService = new RazorTemplating(compilationService); //Act var result = await templatingService.RunTemplateAsync(templateContent, model); //Assert Assert.Null(result.ProcessingException); Assert.Equal("Hello World", result.GeneratedText); }