Skip to content

Commit

Permalink
Update Mono.TextTemplating to new preview package
Browse files Browse the repository at this point in the history
Part of #32385
  • Loading branch information
ajcvickers committed Jan 23, 2024
1 parent 7003680 commit 61b31ae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/EFCore.Design/EFCore.Design.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="$(MicrosoftExtensionsDependencyModelVersion)" />
<PackageReference Include="Microsoft.Extensions.HostFactoryResolver.Sources" PrivateAssets="All" Version="$(MicrosoftExtensionsHostFactoryResolverSourcesVersion)" />
<PackageReference Include="Mono.TextTemplating" Version="2.2.1" />
<PackageReference Include="Mono.TextTemplating" Version="3.0.0-preview-0045-g9b6fc72764" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public override ScaffoldedModel GenerateModel(IModel model, ModelCodeGenerationO
{
host.TemplateFile = contextTemplate;

generatedCode = Engine.ProcessTemplate(File.ReadAllText(contextTemplate), host);
generatedCode = Engine.ProcessTemplateAsync(File.ReadAllText(contextTemplate), host).GetAwaiter().GetResult();;
CheckEncoding(host.OutputEncoding);
HandleErrors(host);
}
Expand Down Expand Up @@ -165,7 +165,8 @@ public override ScaffoldedModel GenerateModel(IModel model, ModelCodeGenerationO

if (compiledEntityTypeTemplate is null)
{
compiledEntityTypeTemplate = Engine.CompileTemplate(File.ReadAllText(entityTypeTemplate), host);
compiledEntityTypeTemplate = Engine.CompileTemplateAsync(File.ReadAllText(entityTypeTemplate), host, default)
.GetAwaiter().GetResult();;
entityTypeExtension = host.Extension;
CheckEncoding(host.OutputEncoding);
}
Expand Down Expand Up @@ -208,7 +209,8 @@ public override ScaffoldedModel GenerateModel(IModel model, ModelCodeGenerationO

if (compiledConfigurationTemplate is null)
{
compiledConfigurationTemplate = Engine.CompileTemplate(File.ReadAllText(configurationTemplate), host);
compiledConfigurationTemplate = Engine.CompileTemplateAsync(File.ReadAllText(configurationTemplate), host, default)
.GetAwaiter().GetResult();;
configurationExtension = host.Extension;
CheckEncoding(host.OutputEncoding);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public void Service_works()
.AddSingleton("Hello, Services!")
.BuildServiceProvider());

var result = _engine.ProcessTemplate(
var result = _engine.ProcessTemplateAsync(
@"<#@ template hostSpecific=""true"" #><#= ((IServiceProvider)Host).GetService(typeof(string)) #>",
host);
host).GetAwaiter().GetResult();

Assert.Empty(host.Errors);
Assert.Equal("Hello, Services!", result);
Expand All @@ -35,9 +35,9 @@ public void Session_works()
{
var host = new TextTemplatingEngineHost { Session = new TextTemplatingSession { ["Value"] = "Hello, Session!" } };

var result = _engine.ProcessTemplate(
var result = _engine.ProcessTemplateAsync(
@"<#= Session[""Value""] #>",
host);
host).GetAwaiter().GetResult();

Assert.Empty(host.Errors);
Assert.Equal("Hello, Session!", result);
Expand All @@ -48,9 +48,9 @@ public void Session_works_with_parameter()
{
var host = new TextTemplatingEngineHost { Session = new TextTemplatingSession { ["Value"] = "Hello, Session!" } };

var result = _engine.ProcessTemplate(
var result = _engine.ProcessTemplateAsync(
@"<#@ parameter name=""Value"" type=""System.String"" #><#= Value #>",
host);
host).GetAwaiter().GetResult();

Assert.Empty(host.Errors);
Assert.Equal("Hello, Session!", result);
Expand All @@ -66,9 +66,9 @@ public void Include_works()

var host = new TextTemplatingEngineHost { TemplateFile = Path.Combine(dir, "test.tt") };

var result = _engine.ProcessTemplate(
var result = _engine.ProcessTemplateAsync(
@"<#@ include file=""test.ttinclude"" #>",
host);
host).GetAwaiter().GetResult();

Assert.Empty(host.Errors);
Assert.Equal("Hello, Include!", result);
Expand All @@ -79,9 +79,9 @@ public void Error_works()
{
var host = new TextTemplatingEngineHost();

_engine.ProcessTemplate(
_engine.ProcessTemplateAsync(
@"<# Error(""Hello, Error!""); #>",
host);
host).GetAwaiter().GetResult();

var error = Assert.Single(host.Errors.Cast<CompilerError>());
Assert.Equal("Hello, Error!", error.ErrorText);
Expand All @@ -93,9 +93,9 @@ public void Directive_throws_when_processor_unknown()
var host = new TextTemplatingEngineHost();

var ex = Assert.Throws<FileNotFoundException>(
() => _engine.ProcessTemplate(
() => _engine.ProcessTemplateAsync(
@"<#@ test processor=""TestDirectiveProcessor"" #>",
host));
host).GetAwaiter().GetResult());

Assert.Equal(DesignStrings.UnknownDirectiveProcessor("TestDirectiveProcessor"), ex.Message);
}
Expand All @@ -107,9 +107,9 @@ public void ResolvePath_work()

var host = new TextTemplatingEngineHost { TemplateFile = Path.Combine(dir, "test.tt") };

var result = _engine.ProcessTemplate(
var result = _engine.ProcessTemplateAsync(
@"<#@ template hostSpecific=""true"" #><#= Host.ResolvePath(""data.json"") #>",
host);
host).GetAwaiter().GetResult();

Assert.Empty(host.Errors);
Assert.Equal(Path.Combine(dir, "data.json"), result);
Expand All @@ -120,9 +120,9 @@ public void Output_works()
{
var host = new TextTemplatingEngineHost();

_engine.ProcessTemplate(
_engine.ProcessTemplateAsync(
@"<#@ output extension="".txt"" encoding=""us-ascii"" #>",
host);
host).GetAwaiter().GetResult();

Assert.Empty(host.Errors);
Assert.Equal(".txt", host.Extension);
Expand All @@ -134,9 +134,9 @@ public void Assembly_works()
{
var host = new TextTemplatingEngineHost();

var result = _engine.ProcessTemplate(
var result = _engine.ProcessTemplateAsync(
@"<#@ assembly name=""Microsoft.EntityFrameworkCore"" #><#= nameof(Microsoft.EntityFrameworkCore.DbContext) #>",
host);
host).GetAwaiter().GetResult();

Assert.Empty(host.Errors);
Assert.Equal("DbContext", result);
Expand Down

0 comments on commit 61b31ae

Please sign in to comment.