-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from natenho/feature/88-asp-net-core
- Loading branch information
Showing
99 changed files
with
556 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
dotnet restore --verbosity normal | ||
dotnet build --configuration Release --verbosity normal .\src\Mockaco\Mockaco.csproj | ||
dotnet test --configuration Release --verbosity normal .\test\Mockaco.Tests\Mockaco.Tests.csproj | ||
dotnet pack --configuration Nuget --output ./nupkg | ||
docker build -f ./src/Mockaco/Docker/Dockerfile -t mockaco:local . | ||
|
||
$containerName = [guid]::NewGuid().ToString() | ||
try { | ||
docker run --name $containerName -d -p 5000:5000 -v ${PSScriptRoot}/src/Mockaco/Mocks:/app/Mocks mockaco:local | ||
Start-Sleep -Seconds 5 | ||
docker run --rm -v ${PSScriptRoot}/test/_postman:/etc/newman -t postman/newman:alpine run Mockaco.postman_collection.json | ||
} | ||
finally { | ||
docker container stop $containerName | ||
docker container rm $containerName | ||
} |
2 changes: 1 addition & 1 deletion
2
src/Mockaco/Common/HttpContentTypes.cs → ...aco.AspNetCore/Common/HttpContentTypes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Mockaco/Common/HttpHeaders.cs → src/Mockaco.AspNetCore/Common/HttpHeaders.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
29 changes: 29 additions & 0 deletions
29
src/Mockaco.AspNetCore/DependencyInjection/MockacoApplicationBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using Mockaco; | ||
using Mockaco.Verifyer; | ||
|
||
namespace Microsoft.AspNetCore.Builder | ||
{ | ||
public static class MockacoApplicationBuilder | ||
{ | ||
public static IApplicationBuilder UseMockaco(this IApplicationBuilder app, Action<IApplicationBuilder> configure) | ||
{ | ||
var options = app.ApplicationServices.GetRequiredService<IOptions<MockacoOptions>>().Value; | ||
app.UseEndpoints(endpoints => endpoints.Map($"/{options.VerificationEndpointPrefix}/{options.VerificationEndpointName}", VerifyerExtensions.Verify)); | ||
|
||
app.UseMiddleware<ErrorHandlingMiddleware>(); | ||
configure(app); | ||
app | ||
.UseMiddleware<RequestMatchingMiddleware>() | ||
.UseMiddleware<ResponseDelayMiddleware>() | ||
.UseMiddleware<ResponseMockingMiddleware>() | ||
.UseMiddleware<CallbackMiddleware>(); | ||
|
||
return app; | ||
} | ||
|
||
public static IApplicationBuilder UseMockaco(this IApplicationBuilder app) => | ||
app.UseMockaco(_ => { }); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/Mockaco.AspNetCore/DependencyInjection/MockacoServiceCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Options; | ||
using Mockaco; | ||
using Mockaco.Settings; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class MockacoServiceCollection | ||
{ | ||
public static IServiceCollection AddMockaco(this IServiceCollection services) => | ||
services.AddMockaco(_ => { }); | ||
|
||
public static IServiceCollection AddMockaco(this IServiceCollection services, Action<MockacoOptions> config) => | ||
services | ||
.AddOptions<MockacoOptions>().Configure(config).Services | ||
.AddOptions<TemplateFileProviderOptions>() | ||
.Configure<IOptions<MockacoOptions>>((options, parent) => options = parent.Value.TemplateFileProvider) | ||
.Services | ||
.AddCommonServices(); | ||
|
||
|
||
public static IServiceCollection AddMockaco(this IServiceCollection services, IConfiguration config) => | ||
services | ||
.AddConfiguration(config) | ||
.AddCommonServices(); | ||
|
||
private static IServiceCollection AddConfiguration(this IServiceCollection services, IConfiguration config) => | ||
services | ||
.AddOptions() | ||
.Configure<MockacoOptions>(config) | ||
.Configure<TemplateFileProviderOptions>(config.GetSection("TemplateFileProvider")); | ||
|
||
private static IServiceCollection AddCommonServices(this IServiceCollection services) => | ||
services | ||
.AddMemoryCache() | ||
.AddHttpClient() | ||
.AddInternalServices() | ||
.AddHostedService<MockProviderWarmUp>(); | ||
|
||
private static IServiceCollection AddInternalServices(this IServiceCollection services) => | ||
services | ||
.AddSingleton<VerificationRouteValueTransformer>() | ||
.AddScoped<IMockacoContext, MockacoContext>() | ||
.AddScoped<IScriptContext, ScriptContext>() | ||
.AddTransient<IGlobalVariableStorage, ScriptContextGlobalVariableStorage>() | ||
|
||
.AddSingleton<IScriptRunnerFactory, ScriptRunnerFactory>() | ||
|
||
.AddSingleton<IFakerFactory, LocalizedFakerFactory>() | ||
.AddSingleton<IMockProvider, MockProvider>() | ||
.AddSingleton<ITemplateProvider, TemplateFileProvider>() | ||
|
||
.AddScoped<IRequestMatcher, RequestMethodMatcher>() | ||
.AddScoped<IRequestMatcher, RequestRouteMatcher>() | ||
.AddScoped<IRequestMatcher, RequestConditionMatcher>() | ||
|
||
.AddTransient<IRequestBodyFactory, RequestBodyFactory>() | ||
|
||
.AddTransient<IRequestBodyStrategy, JsonRequestBodyStrategy>() | ||
.AddTransient<IRequestBodyStrategy, XmlRequestBodyStrategy>() | ||
.AddTransient<IRequestBodyStrategy, FormRequestBodyStrategy>() | ||
|
||
.AddTransient<IResponseBodyFactory, ResponseBodyFactory>() | ||
|
||
.AddTransient<IResponseBodyStrategy, BinaryResponseBodyStrategy>() | ||
.AddTransient<IResponseBodyStrategy, JsonResponseBodyStrategy>() | ||
.AddTransient<IResponseBodyStrategy, XmlResponseBodyStrategy>() | ||
.AddTransient<IResponseBodyStrategy, DefaultResponseBodyStrategy>() | ||
|
||
.AddTransient<ITemplateTransformer, TemplateTransformer>() | ||
|
||
.AddTemplatesGenerating(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Mockaco.Tests")] | ||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<LangVersion>latest</LangVersion> | ||
<AssemblyName>Mockaco.AspNetCore</AssemblyName> | ||
<RootNamespace>Mockaco</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Configurations>Debug;Release;Nuget</Configurations> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<IsPackable>true</IsPackable> | ||
<PackageOutputPath>./nupkg</PackageOutputPath> | ||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | ||
<Authors>natenho</Authors> | ||
<Description>ASP.NET Core pipeline to mock HTTP requests/responses, useful to stub services and simulate dynamic API responses, leveraging ASP.NET Core features, built-in fake data generation and pure C# scripting</Description> | ||
<PackageProjectUrl>https://github.com/natenho/Mockaco</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/natenho/Mockaco</RepositoryUrl> | ||
<PackageTags>mock http aspnetcore</PackageTags> | ||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||
<PackageIcon>mockaco-icon.png</PackageIcon> | ||
<Product>Mockaco</Product> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<NoWarn>1701;1702</NoWarn> | ||
<WarningsNotAsErrors>AD0001</WarningsNotAsErrors> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<NoWarn>1701;1702</NoWarn> | ||
<WarningsNotAsErrors>AD0001</WarningsNotAsErrors> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Nuget|AnyCPU'"> | ||
<NoWarn>1701;1702</NoWarn> | ||
<WarningsNotAsErrors>AD0001</WarningsNotAsErrors> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Bogus" Version="33.0.2" /> | ||
<PackageReference Include="GitVersion.MsBuild" Version="5.6.10"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="MAB.DotIgnore" Version="3.0.2" /> | ||
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.9.0" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.3"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||
<PackageReference Include="Polly" Version="7.2.2" /> | ||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="Resources\mockaco-icon.png"> | ||
<Pack>True</Pack> | ||
<PackagePath>/</PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.