mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-07-08 22:05:13 +02:00
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -6,6 +6,8 @@ using System.Threading;
|
|||||||
using log4net;
|
using log4net;
|
||||||
using log4net.Config;
|
using log4net.Config;
|
||||||
using log4net.Repository;
|
using log4net.Repository;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
@@ -33,11 +35,39 @@ namespace WireMock.Net.StandAlone.NETCoreApp
|
|||||||
|
|
||||||
settings.Logger.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
settings.Logger.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
||||||
|
|
||||||
|
/* https://stackoverflow.com/questions/31942037/how-to-enable-cors-in-asp-net-core */
|
||||||
|
/* Enable Cors */
|
||||||
|
var policyName = "MyPolicy";
|
||||||
|
settings.AdditionalServiceRegistration = services =>
|
||||||
|
{
|
||||||
|
services.AddCors(corsOptions =>
|
||||||
|
corsOptions.AddPolicy(policyName,
|
||||||
|
corsPolicyBuilder =>
|
||||||
|
{
|
||||||
|
corsPolicyBuilder
|
||||||
|
.AllowAnyHeader()
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowAnyOrigin();
|
||||||
|
}));
|
||||||
|
|
||||||
|
settings.Logger.Debug("Enable Cors");
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Use Cors */
|
||||||
|
settings.PreWireMockMiddlewareInit = app =>
|
||||||
|
{
|
||||||
|
var appBuilder = (IApplicationBuilder)app;
|
||||||
|
appBuilder.UseCors(policyName);
|
||||||
|
|
||||||
|
settings.Logger.Debug("Use Cors");
|
||||||
|
};
|
||||||
|
|
||||||
_server = WireMockServer.Start(settings);
|
_server = WireMockServer.Start(settings);
|
||||||
|
|
||||||
_server.Given(Request.Create().WithPath("/api/sap")
|
_server.Given(Request.Create().WithPath("/api/sap")
|
||||||
.UsingPost()
|
.UsingPost()
|
||||||
.WithBody((IBodyData xmlData) => {
|
.WithBody((IBodyData xmlData) =>
|
||||||
|
{
|
||||||
//xmlData is always null
|
//xmlData is always null
|
||||||
return true;
|
return true;
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#if USE_ASPNETCORE
|
#if USE_ASPNETCORE
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -8,10 +9,10 @@ using JetBrains.Annotations;
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Stef.Validation;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Owin.Mappers;
|
using WireMock.Owin.Mappers;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using Stef.Validation;
|
|
||||||
|
|
||||||
namespace WireMock.Owin
|
namespace WireMock.Owin
|
||||||
{
|
{
|
||||||
@@ -54,7 +55,7 @@ namespace WireMock.Owin
|
|||||||
// a filesystem handler).
|
// a filesystem handler).
|
||||||
if (string.IsNullOrEmpty(AppContext.BaseDirectory))
|
if (string.IsNullOrEmpty(AppContext.BaseDirectory))
|
||||||
{
|
{
|
||||||
builder.UseContentRoot(System.IO.Directory.GetCurrentDirectory());
|
builder.UseContentRoot(Directory.GetCurrentDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
_host = builder
|
_host = builder
|
||||||
|
|||||||
@@ -46,10 +46,7 @@ namespace WireMock.Owin
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public Task StartAsync()
|
public Task StartAsync()
|
||||||
{
|
{
|
||||||
return Task.Run(() =>
|
return Task.Run(StartServers, _cts.Token);
|
||||||
{
|
|
||||||
StartServers();
|
|
||||||
}, _cts.Token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
|
|||||||
Reference in New Issue
Block a user