mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-29 05:11:46 +02:00
webapp (work in progress)
This commit is contained in:
22
src/WireMock.Net.WebApp/App.cs
Normal file
22
src/WireMock.Net.WebApp/App.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace WireMock.Net.WebApp
|
||||
{
|
||||
public class App
|
||||
{
|
||||
private readonly IWireMockService _service;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public App(IWireMockService service, ILogger logger)
|
||||
{
|
||||
_service = service;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
_logger.LogInformation("WireMock.Net WebApp running");
|
||||
_service.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/WireMock.Net.WebApp/IWireMockService.cs
Normal file
7
src/WireMock.Net.WebApp/IWireMockService.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace WireMock.Net.WebApp
|
||||
{
|
||||
public interface IWireMockService
|
||||
{
|
||||
void Run();
|
||||
}
|
||||
}
|
||||
52
src/WireMock.Net.WebApp/Program.cs
Normal file
52
src/WireMock.Net.WebApp/Program.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace WireMock.Net.WebApp
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// Create service collection
|
||||
var serviceCollection = new ServiceCollection();
|
||||
ConfigureServices(serviceCollection);
|
||||
|
||||
// Create service provider
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
// Run app
|
||||
serviceProvider.GetService<App>().Run();
|
||||
}
|
||||
|
||||
private static void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Build configuration
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(AppContext.BaseDirectory)
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.AddEnvironmentVariables() // <-- this is needed to to override settings via the Azure Portal App Settings
|
||||
.Build();
|
||||
|
||||
services.AddLogging(loggingBuilder =>
|
||||
{
|
||||
loggingBuilder.AddConfiguration(configuration.GetSection("Logging"));
|
||||
loggingBuilder.AddConsole();
|
||||
});
|
||||
|
||||
// Add access to IFluentMockServerSettings
|
||||
var settings = configuration.GetSection("FluentMockServerSettings").Get<FluentMockServerSettings>();
|
||||
services.AddSingleton<IFluentMockServerSettings>(settings);
|
||||
|
||||
// Add services
|
||||
services.AddTransient<IWireMockLogger, WireMockLogger>();
|
||||
services.AddTransient<IWireMockService, WireMockService>();
|
||||
|
||||
// Add app
|
||||
services.AddTransient<App>();
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/WireMock.Net.WebApp/Properties/launchSettings.json
Normal file
38
src/WireMock.Net.WebApp/Properties/launchSettings.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iis": {
|
||||
"applicationUrl": "http://localhost//wiremock",
|
||||
"sslPort": 0
|
||||
},
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:56513/",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchUrl": "__admin/settings",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"WireMock.Net.WebApp": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "__admin/settings",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "http://localhost:56514/"
|
||||
},
|
||||
"IIS": {
|
||||
"commandName": "IIS",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
src/WireMock.Net.WebApp/WireMock.Net.WebApp.csproj
Normal file
25
src/WireMock.Net.WebApp/WireMock.Net.WebApp.csproj
Normal file
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net.StandAlone\WireMock.Net.StandAlone.csproj" />
|
||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
43
src/WireMock.Net.WebApp/WireMockLogger.cs
Normal file
43
src/WireMock.Net.WebApp/WireMockLogger.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Admin.Requests;
|
||||
using WireMock.Logging;
|
||||
|
||||
namespace WireMock.Net.WebApp
|
||||
{
|
||||
public class WireMockLogger : IWireMockLogger
|
||||
{
|
||||
private readonly ILogger<WireMockService> _logger;
|
||||
|
||||
public WireMockLogger(ILogger<WireMockService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Debug(string formatString, params object[] args)
|
||||
{
|
||||
_logger.LogDebug(formatString, args);
|
||||
}
|
||||
|
||||
public void Info(string formatString, params object[] args)
|
||||
{
|
||||
_logger.LogInformation(formatString, args);
|
||||
}
|
||||
|
||||
public void Warn(string formatString, params object[] args)
|
||||
{
|
||||
_logger.LogWarning(formatString, args);
|
||||
}
|
||||
|
||||
public void Error(string formatString, params object[] args)
|
||||
{
|
||||
_logger.LogError(formatString, args);
|
||||
}
|
||||
|
||||
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
|
||||
{
|
||||
string message = JsonConvert.SerializeObject(logEntryModel, Formatting.Indented);
|
||||
_logger.LogDebug("Admin[{0}] {1}", isAdminRequest, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
src/WireMock.Net.WebApp/WireMockService.cs
Normal file
39
src/WireMock.Net.WebApp/WireMockService.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Net.StandAlone;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace WireMock.Net.WebApp
|
||||
{
|
||||
public class WireMockService : IWireMockService
|
||||
{
|
||||
private static int sleepTime = 30000;
|
||||
|
||||
private readonly IWireMockLogger _logger;
|
||||
private readonly IFluentMockServerSettings _settings;
|
||||
|
||||
public WireMockService(IWireMockLogger logger, IFluentMockServerSettings settings)
|
||||
{
|
||||
_logger = logger;
|
||||
_settings = settings;
|
||||
|
||||
_settings.Logger = logger;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
_logger.Info("WireMock.Net server starting");
|
||||
|
||||
StandAloneApp.Start(_settings);
|
||||
|
||||
_logger.Info($"WireMock.Net server settings {JsonConvert.SerializeObject(_settings)}");
|
||||
|
||||
while (true)
|
||||
{
|
||||
_logger.Info("WireMock.Net server running");
|
||||
Thread.Sleep(sleepTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
9
src/WireMock.Net.WebApp/appsettings.Development.json
Normal file
9
src/WireMock.Net.WebApp/appsettings.Development.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/WireMock.Net.WebApp/appsettings.json
Normal file
21
src/WireMock.Net.WebApp/appsettings.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"Logging": {
|
||||
"IncludeScopes": false,
|
||||
"Debug": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug"
|
||||
}
|
||||
},
|
||||
"Console": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug"
|
||||
}
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"FluentMockServerSettings": {
|
||||
"AdminUsername": "a",
|
||||
"AdminPassword": "b",
|
||||
"StartAdminInterface": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user