This commit is contained in:
Stef Heyenrath
2020-04-01 22:45:46 +02:00
9 changed files with 41 additions and 18 deletions

View File

@@ -31,6 +31,7 @@
<PackageReference Include="Handlebars.Net" Version="1.9.5" /> <PackageReference Include="Handlebars.Net" Version="1.9.5" />
<PackageReference Include="log4net" Version="2.0.8" /> <PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<!--<PackageReference Include="Microsoft.CodeAnalysis.Scripting.Common" Version="3.4.0" />-->
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -11,6 +11,7 @@ using WireMock.RequestBuilders;
using WireMock.ResponseBuilders; using WireMock.ResponseBuilders;
using WireMock.Server; using WireMock.Server;
using WireMock.Settings; using WireMock.Settings;
using WireMock.Util;
namespace WireMock.Net.ConsoleApplication namespace WireMock.Net.ConsoleApplication
{ {
@@ -515,6 +516,12 @@ namespace WireMock.Net.ConsoleApplication
.WithStatusCode(200) .WithStatusCode(200)
.WithHeader("Content-Type", "application/json") .WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { Id = "5bdf076c-5654-4b3e-842c-7caf1fabf8c9" })); .WithBodyAsJson(new { Id = "5bdf076c-5654-4b3e-842c-7caf1fabf8c9" }));
server
.Given(Request.Create().WithPath("/random200or505").UsingGet())
.RespondWith(Response.Create().WithCallback(request => new ResponseMessage
{
StatusCode = new Random().Next(1, 100) == 1 ? 504 : 200
}));
System.Console.WriteLine(JsonConvert.SerializeObject(server.MappingModels, Formatting.Indented)); System.Console.WriteLine(JsonConvert.SerializeObject(server.MappingModels, Formatting.Indented));

View File

@@ -4,7 +4,7 @@
<Description>Commonly used interfaces, models, enumerations and types.</Description> <Description>Commonly used interfaces, models, enumerations and types.</Description>
<AssemblyTitle>WireMock.Net.Abstractions</AssemblyTitle> <AssemblyTitle>WireMock.Net.Abstractions</AssemblyTitle>
<Authors>Stef Heyenrath</Authors> <Authors>Stef Heyenrath</Authors>
<TargetFrameworks>netstandard1.0;netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard1.0;netstandard2.0;netstandard2.1;net45</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>WireMock.Net.Abstractions</AssemblyName> <AssemblyName>WireMock.Net.Abstractions</AssemblyName>
<PackageId>WireMock.Net.Abstractions</PackageId> <PackageId>WireMock.Net.Abstractions</PackageId>

View File

@@ -4,7 +4,7 @@
<Description>A RestClient using RestEase to access the admin interface.</Description> <Description>A RestClient using RestEase to access the admin interface.</Description>
<AssemblyTitle>WireMock.Net.RestClient</AssemblyTitle> <AssemblyTitle>WireMock.Net.RestClient</AssemblyTitle>
<Authors>Stef Heyenrath</Authors> <Authors>Stef Heyenrath</Authors>
<TargetFrameworks>netstandard1.1;netstandard2.0;net45</TargetFrameworks> <TargetFrameworks>netstandard1.1;netstandard2.0;netstandard2.1;net45</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>WireMock.Net.RestClient</AssemblyName> <AssemblyName>WireMock.Net.RestClient</AssemblyName>
<PackageId>WireMock.Net.RestClient</PackageId> <PackageId>WireMock.Net.RestClient</PackageId>

View File

@@ -3,7 +3,7 @@
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description> <Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle> <AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
<Authors>Stef Heyenrath</Authors> <Authors>Stef Heyenrath</Authors>
<TargetFrameworks>net451;net452;net46;net461;netstandard1.3;netstandard2.0</TargetFrameworks> <TargetFrameworks>net451;net452;net46;net461;netstandard1.3;netstandard2.0;netstandard2.1</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>WireMock.Net.StandAlone</AssemblyName> <AssemblyName>WireMock.Net.StandAlone</AssemblyName>
<PackageId>WireMock.Net.StandAlone</PackageId> <PackageId>WireMock.Net.StandAlone</PackageId>
@@ -36,7 +36,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'netstandard2.0' "> <PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' ">
<DefineConstants>NETSTANDARD;USE_ASPNETCORE</DefineConstants> <DefineConstants>NETSTANDARD;USE_ASPNETCORE</DefineConstants>
</PropertyGroup> </PropertyGroup>

View File

@@ -82,7 +82,7 @@ namespace WireMock.Matchers
object result = null; object result = null;
#if NET451 || NET452 #if (NET451 || NET452)
var compilerParams = new System.CodeDom.Compiler.CompilerParameters var compilerParams = new System.CodeDom.Compiler.CompilerParameters
{ {
GenerateInMemory = true, GenerateInMemory = true,
@@ -122,36 +122,42 @@ namespace WireMock.Matchers
{ {
result = methodInfo.Invoke(helper, new[] { inputValue }); result = methodInfo.Invoke(helper, new[] { inputValue });
} }
catch catch (Exception ex)
{ {
throw new WireMockException("CSharpCodeMatcher: Unable to call method 'IsMatch' in WireMock.CodeHelper"); throw new WireMockException("CSharpCodeMatcher: Unable to call method 'IsMatch' in WireMock.CodeHelper", ex);
} }
} }
#elif NET46 || NET461 #elif (NET46 || NET461)
dynamic script; dynamic script;
try try
{ {
script = CSScriptLibrary.CSScript.Evaluator.CompileCode(source).CreateObject("*"); script = CSScriptLibrary.CSScript.Evaluator.CompileCode(source).CreateObject("*");
} }
catch catch (Exception ex)
{ {
throw new WireMockException("CSharpCodeMatcher: Unable to create compiler for WireMock.CodeHelper"); throw new WireMockException("CSharpCodeMatcher: Unable to create compiler for WireMock.CodeHelper", ex);
} }
try try
{ {
result = script.IsMatch(inputValue); result = script.IsMatch(inputValue);
} }
catch catch (Exception ex)
{ {
throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper"); throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper", ex);
} }
#elif NETSTANDARD2_0
#elif (NETSTANDARD2_0 || NETSTANDARD2_1)
dynamic script; dynamic script;
try try
{ {
var assembly = CSScriptLib.CSScript.Evaluator.CompileCode(source); var assembly = CSScriptLib.CSScript.Evaluator.CompileCode(source);
#if NETSTANDARD2_0
script = csscript.GenericExtensions.CreateObject(assembly, "*"); script = csscript.GenericExtensions.CreateObject(assembly, "*");
#else
script = CSScriptLib.ReflectionExtensions.CreateObject(assembly,"*");
#endif
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -164,10 +170,10 @@ namespace WireMock.Matchers
} }
catch (Exception ex) catch (Exception ex)
{ {
throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper"); throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper", ex);
} }
#else #else
throw new NotSupportedException("The 'CSharpCodeMatcher' cannot be used in netstandard 1.3"); throw new NotSupportedException("The 'CSharpCodeMatcher' cannot be used in netstandard 1.3");
#endif #endif
try try
{ {

View File

@@ -139,6 +139,8 @@ namespace WireMock.Owin
_logger.Info("WireMock.Net server using netstandard1.3"); _logger.Info("WireMock.Net server using netstandard1.3");
#elif NETSTANDARD2_0 #elif NETSTANDARD2_0
_logger.Info("WireMock.Net server using netstandard2.0"); _logger.Info("WireMock.Net server using netstandard2.0");
#elif NETSTANDARD2_1
_logger.Info("WireMock.Net server using netstandard2.1");
#elif NET46 #elif NET46
_logger.Info("WireMock.Net server using .net 4.6.1 or higher"); _logger.Info("WireMock.Net server using .net 4.6.1 or higher");
#endif #endif

View File

@@ -33,7 +33,7 @@ namespace WireMock.Owin
private int FindFreeTcpPort() private int FindFreeTcpPort()
{ {
#if USE_ASPNETCORE || NETSTANDARD2_0 #if USE_ASPNETCORE || NETSTANDARD2_0 || NETSTANDARD2_1
return 0; return 0;
#else #else
return PortUtils.FindFreeTcpPort(); return PortUtils.FindFreeTcpPort();

View File

@@ -5,7 +5,7 @@
<Authors>Stef Heyenrath</Authors> <Authors>Stef Heyenrath</Authors>
<!--<TargetFrameworks>net451;net452;net46;net461;netstandard1.3;netstandard2.0;netcoreapp2.1</TargetFrameworks>--> <!--<TargetFrameworks>net451;net452;net46;net461;netstandard1.3;netstandard2.0;netcoreapp2.1</TargetFrameworks>-->
<!--<TargetFrameworks>net451;net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>--> <!--<TargetFrameworks>net451;net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>-->
<TargetFrameworks>net451;net452;net46;net461;netstandard1.3;netstandard2.0</TargetFrameworks> <TargetFrameworks>net451;net452;net46;net461;netstandard1.3;netstandard2.0;;netstandard2.1</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>WireMock.Net</AssemblyName> <AssemblyName>WireMock.Net</AssemblyName>
<PackageId>WireMock.Net</PackageId> <PackageId>WireMock.Net</PackageId>
@@ -48,7 +48,7 @@
<CodeAnalysisRuleSet>WireMock.Net.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>WireMock.Net.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'netstandard2.0'"> <PropertyGroup Condition="'$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'">
<DefineConstants>NETSTANDARD;USE_ASPNETCORE</DefineConstants> <DefineConstants>NETSTANDARD;USE_ASPNETCORE</DefineConstants>
</PropertyGroup> </PropertyGroup>
@@ -140,6 +140,13 @@
<PackageReference Include="CS-Script.Core" Version="1.1.1" /> <PackageReference Include="CS-Script.Core" Version="1.1.1" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.4" />
<!-- https://github.com/WireMock-Net/WireMock.Net/issues/448 -->
<PackageReference Include="CS-Script.Core" Version="1.3.1" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" /> <ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
</ItemGroup> </ItemGroup>