mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-18 23:20:11 +02:00
Refactor Transformer (add Scriban) (#562)
This commit is contained in:
@@ -1,52 +1,52 @@
|
||||
using FluentAssertions;
|
||||
using HandlebarsDotNet;
|
||||
using Moq;
|
||||
using System;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Transformers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Transformers
|
||||
{
|
||||
public class HandlebarsContextFactoryTests
|
||||
{
|
||||
private readonly Mock<IFileSystemHandler> _fileSystemHandlerMock = new Mock<IFileSystemHandler>();
|
||||
|
||||
[Fact]
|
||||
public void Create_WithNullAction_DoesNotInvokeAction()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new HandlebarsContextFactory(_fileSystemHandlerMock.Object, null);
|
||||
|
||||
// Act
|
||||
var result = sut.Create();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WithAction_InvokesAction()
|
||||
{
|
||||
// Arrange
|
||||
int num = 0;
|
||||
Action<IHandlebars, IFileSystemHandler> action = (ctx, fs) =>
|
||||
{
|
||||
ctx.Should().NotBeNull();
|
||||
fs.Should().NotBeNull();
|
||||
|
||||
num++;
|
||||
};
|
||||
var sut = new HandlebarsContextFactory(_fileSystemHandlerMock.Object, action);
|
||||
|
||||
// Act
|
||||
var result = sut.Create();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
|
||||
// Verify
|
||||
num.Should().Be(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
using FluentAssertions;
|
||||
using HandlebarsDotNet;
|
||||
using Moq;
|
||||
using System;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Transformers.Handlebars;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Transformers.Handlebars
|
||||
{
|
||||
public class HandlebarsContextFactoryTests
|
||||
{
|
||||
private readonly Mock<IFileSystemHandler> _fileSystemHandlerMock = new Mock<IFileSystemHandler>();
|
||||
|
||||
[Fact]
|
||||
public void Create_WithNullAction_DoesNotInvokeAction()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new HandlebarsContextFactory(_fileSystemHandlerMock.Object, null);
|
||||
|
||||
// Act
|
||||
var result = sut.Create();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WithAction_InvokesAction()
|
||||
{
|
||||
// Arrange
|
||||
int num = 0;
|
||||
Action<IHandlebars, IFileSystemHandler> action = (ctx, fs) =>
|
||||
{
|
||||
ctx.Should().NotBeNull();
|
||||
fs.Should().NotBeNull();
|
||||
|
||||
num++;
|
||||
};
|
||||
var sut = new HandlebarsContextFactory(_fileSystemHandlerMock.Object, action);
|
||||
|
||||
// Act
|
||||
var result = sut.Create();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
|
||||
// Verify
|
||||
num.Should().Be(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Transformers.Scriban;
|
||||
using WireMock.Types;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Transformers.Scriban
|
||||
{
|
||||
public class ScribanContextFactoryTests
|
||||
{
|
||||
private readonly Mock<IFileSystemHandler> _fileSystemHandlerMock = new Mock<IFileSystemHandler>();
|
||||
|
||||
[Theory]
|
||||
[InlineData(TransformerType.Scriban)]
|
||||
[InlineData(TransformerType.ScribanDotLiquid)]
|
||||
public void Create_With_Scriban_TransformerType_Creates_ITransformerContext(TransformerType transformerType)
|
||||
{
|
||||
// Arrange
|
||||
var sut = new ScribanContextFactory(_fileSystemHandlerMock.Object, transformerType);
|
||||
|
||||
// Act
|
||||
var result = sut.Create();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_With_Invalid_TransformerType_Throws_Exception()
|
||||
{
|
||||
// Act
|
||||
Action action = () => new ScribanContextFactory(_fileSystemHandlerMock.Object, TransformerType.Handlebars);
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<Exception>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user