Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compatible with PhysicalFileProvider in the TextTemplating.
Resolve #6523 Related dotnet/extensions#757
- Loading branch information
Showing
5 changed files
with
111 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...Tests/Volo/Abp/TextTemplating/VirtualFiles/LocalizedTemplateContentReaderFactory_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.FileProviders; | ||
using Microsoft.Extensions.Primitives; | ||
using Shouldly; | ||
using Volo.Abp.VirtualFileSystem; | ||
using Xunit; | ||
|
||
namespace Volo.Abp.TextTemplating.VirtualFiles | ||
{ | ||
public class LocalizedTemplateContentReaderFactory_Tests: AbpTextTemplatingTestBase | ||
{ | ||
private readonly ITemplateDefinitionManager _templateDefinitionManager; | ||
|
||
public LocalizedTemplateContentReaderFactory_Tests() | ||
{ | ||
_templateDefinitionManager = GetRequiredService<ITemplateDefinitionManager>(); | ||
} | ||
|
||
[Fact] | ||
public async Task Create_Should_Work_With_PhysicalFileProvider() | ||
{ | ||
var localizedTemplateContentReaderFactory = new LocalizedTemplateContentReaderFactory( | ||
new PhysicalFileVirtualFileProvider( | ||
new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), | ||
@"Volo\Abp\TextTemplating\")))); | ||
|
||
var reader = await localizedTemplateContentReaderFactory.CreateAsync(_templateDefinitionManager.Get(TestTemplates.WelcomeEmail)); | ||
|
||
reader.GetContentOrNull("en").ShouldBe("Welcome {{model.name}} to the abp.io!"); | ||
reader.GetContentOrNull("tr").ShouldBe("Merhaba {{model.name}}, abp.io'ya hoşgeldiniz!"); | ||
} | ||
|
||
class PhysicalFileVirtualFileProvider : IVirtualFileProvider | ||
{ | ||
private readonly PhysicalFileProvider _physicalFileProvider; | ||
|
||
public PhysicalFileVirtualFileProvider(PhysicalFileProvider physicalFileProvider) | ||
{ | ||
_physicalFileProvider = physicalFileProvider; | ||
} | ||
|
||
public IFileInfo GetFileInfo(string subpath) | ||
{ | ||
return _physicalFileProvider.GetFileInfo(subpath); | ||
} | ||
|
||
public IDirectoryContents GetDirectoryContents(string subpath) | ||
{ | ||
return _physicalFileProvider.GetDirectoryContents(subpath); | ||
} | ||
|
||
public IChangeToken Watch(string filter) | ||
{ | ||
return _physicalFileProvider.Watch(filter); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters