Move CSharpCodeMatcher to a new project (#548)

* matcher

* wip

* fix

* <VersionPrefix>1.4.0</VersionPrefix>

* .

* x

* ?

* netstandard2.1

* {}

* test

* Fix: Assembly with same name is already loaded

* _format file

* AssemblyFile = $"WireMock.CodeHelper.Class{Guid.NewGuid()}"

* AssemblyFile = $"WireMock.CodeHelper.Class{Guid.NewGuid().ToString().Replace("-", "")}"

* GC

* x

* remove load ex

* ret

* readme

* no GC

* GetImplementationTypeByInterface

* ``

* PluginLoader

* type
This commit is contained in:
Stef Heyenrath
2021-01-12 16:56:03 +01:00
committed by GitHub
parent d4da8dc15d
commit 92923a12ae
16 changed files with 274 additions and 63 deletions

View File

@@ -0,0 +1,35 @@
using System;
using FluentAssertions;
using WireMock.Matchers;
using WireMock.Plugin;
using Xunit;
namespace WireMock.Net.Tests.Plugin
{
public class PluginLoaderTests
{
public interface IDummy
{
}
[Fact]
public void Load_Valid()
{
// Act
var result = PluginLoader.Load<ICSharpCodeMatcher>(MatchBehaviour.AcceptOnMatch, "x");
// Assert
result.Should().NotBeNull();
}
[Fact]
public void Load_Invalid_ThrowsException()
{
// Act
Action a = () => PluginLoader.Load<IDummy>();
// Assert
a.Should().Throw<DllNotFoundException>();
}
}
}

View File

@@ -20,6 +20,50 @@ namespace WireMock.Net.Tests.Serialization
_sut = new MatcherMapper(_settings);
}
[Fact]
public void MatcherModelMapper_Map_CSharpCodeMatcher()
{
// Assign
var model = new MatcherModel
{
Name = "CSharpCodeMatcher",
Patterns = new[] { "return it == \"x\";" }
};
var sut = new MatcherMapper(new WireMockServerSettings { AllowCSharpCodeMatcher = true });
// Act 1
var matcher1 = (ICSharpCodeMatcher)sut.Map(model);
// Assert 1
matcher1.Should().NotBeNull();
matcher1.IsMatch("x").Should().Be(1.0d);
// Act 2
var matcher2 = (ICSharpCodeMatcher)sut.Map(model);
// Assert 2
matcher2.Should().NotBeNull();
matcher2.IsMatch("x").Should().Be(1.0d);
}
[Fact]
public void MatcherModelMapper_Map_CSharpCodeMatcher_NotAllowed_ThrowsException()
{
// Assign
var model = new MatcherModel
{
Name = "CSharpCodeMatcher",
Patterns = new[] { "x" }
};
var sut = new MatcherMapper(new WireMockServerSettings { AllowCSharpCodeMatcher = false });
// Act
Action action = () => sut.Map(model);
// Assert
action.Should().Throw<NotSupportedException>();
}
[Fact]
public void MatcherModelMapper_Map_Null()
{

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<Authors>Stef Heyenrath</Authors>
<TargetFrameworks>net452;netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>net452;net461;netcoreapp3.1;net5.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<DebugType>full</DebugType>
<AssemblyName>WireMock.Net.Tests</AssemblyName>
@@ -26,6 +26,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net.FluentAssertions\WireMock.Net.FluentAssertions.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net.Matchers.CSharpCode\WireMock.Net.Matchers.CSharpCode.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net.RestClient\WireMock.Net.RestClient.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
</ItemGroup>

View File

@@ -1,4 +1,5 @@
using System;
#if !NET452 && !NET461
using System;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
@@ -552,4 +553,5 @@ namespace WireMock.Net.Tests
server.Stop();
}
}
}
}
#endif

View File

@@ -175,7 +175,7 @@ namespace WireMock.Net.Tests
server.Stop();
}
#if !NET452
#if !NET452 && !NET461
[Theory]
[InlineData("TRACE")]
[InlineData("GET")]