mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-18 07:13:46 +01:00
32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
using HandlebarsDotNet;
|
|
using HandlebarsDotNet.Helpers.Attributes;
|
|
using HandlebarsDotNet.Helpers.Enums;
|
|
using HandlebarsDotNet.Helpers.Helpers;
|
|
using Stef.Validation;
|
|
using WireMock.Handlers;
|
|
|
|
namespace WireMock.Transformers.Handlebars;
|
|
|
|
internal class FileHelpers : BaseHelpers, IHelpers
|
|
{
|
|
internal const string Name = "File";
|
|
|
|
private readonly IFileSystemHandler _fileSystemHandler;
|
|
|
|
public FileHelpers(IHandlebars context, IFileSystemHandler fileSystemHandler) : base(context)
|
|
{
|
|
_fileSystemHandler = Guard.NotNull(fileSystemHandler);
|
|
}
|
|
|
|
[HandlebarsWriter(WriterType.String, usage: HelperUsage.Both, passContext: true, name: Name)]
|
|
public string Read(Context context, string path)
|
|
{
|
|
var templateFunc = Context.Compile(path);
|
|
var transformedPath = templateFunc(context.Value);
|
|
return _fileSystemHandler.ReadResponseBodyAsString(transformedPath);
|
|
}
|
|
|
|
public Category Category => Category.Custom;
|
|
} |