Update Transformer functionality to return value instead of string (#858)

This commit is contained in:
Stef Heyenrath
2022-12-11 11:07:56 +01:00
committed by GitHub
parent 6b03dfaa8c
commit 9606fee8cb
25 changed files with 639 additions and 506 deletions

View File

@@ -1,52 +1,59 @@
using System;
using FluentAssertions;
using HandlebarsDotNet;
using Moq;
using WireMock.Handlers;
using WireMock.Settings;
using WireMock.Transformers.Handlebars;
using Xunit;
namespace WireMock.Net.Tests.Transformers.Handlebars
namespace WireMock.Net.Tests.Transformers.Handlebars;
public class HandlebarsContextFactoryTests
{
public class HandlebarsContextFactoryTests
private readonly Mock<IFileSystemHandler> _fileSystemHandlerMock = new();
[Fact]
public void Create_WithNullAction_DoesNotInvokeAction()
{
private readonly Mock<IFileSystemHandler> _fileSystemHandlerMock = new Mock<IFileSystemHandler>();
[Fact]
public void Create_WithNullAction_DoesNotInvokeAction()
// Arrange
var settings = new WireMockServerSettings
{
// Arrange
var sut = new HandlebarsContextFactory(_fileSystemHandlerMock.Object, null);
FileSystemHandler = _fileSystemHandlerMock.Object
};
var sut = new HandlebarsContextFactory(settings);
// Act
var result = sut.Create();
// Act
var result = sut.Create();
// Assert
result.Should().NotBeNull();
}
// Assert
result.Should().NotBeNull();
}
[Fact]
public void Create_WithAction_InvokesAction()
[Fact]
public void Create_WithAction_InvokesAction()
{
// Arrange
int num = 0;
var settings = new WireMockServerSettings
{
// Arrange
int num = 0;
Action<IHandlebars, IFileSystemHandler> action = (ctx, fs) =>
FileSystemHandler = _fileSystemHandlerMock.Object,
HandlebarsRegistrationCallback = (ctx, fs) =>
{
ctx.Should().NotBeNull();
fs.Should().NotBeNull();
num++;
};
var sut = new HandlebarsContextFactory(_fileSystemHandlerMock.Object, action);
}
};
// Act
var result = sut.Create();
var sut = new HandlebarsContextFactory(settings);
// Assert
result.Should().NotBeNull();
// Act
var result = sut.Create();
// Verify
num.Should().Be(1);
}
// Assert
result.Should().NotBeNull();
// Verify
num.Should().Be(1);
}
}
}