-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX Using WebApplicationFactory for tests to follow latest guidance regarding integration tests and Asp.Net
- Loading branch information
1 parent
afb5661
commit 047b92f
Showing
12 changed files
with
124 additions
and
183 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
27 changes: 0 additions & 27 deletions
27
tests/TurnerSoftware.RobotsExclusionTools.Tests.TestSite/Controllers/RobotsController.cs
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
tests/TurnerSoftware.RobotsExclusionTools.Tests.TestSite/Program.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,35 @@ | ||
using System.IO; | ||
|
||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
using TurnerSoftware.RobotsExclusionTools.Tests.TestSite; | ||
|
||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
var app = builder.Build(); | ||
|
||
app.UseRouting(); | ||
|
||
|
||
app.MapGet("robots.txt", async (ctx) => | ||
{ | ||
var context = ctx.RequestServices.GetRequiredService<SiteContext>(); | ||
if (context.ExpectedStatusCode == 200) | ||
{ | ||
ctx.Response.Headers.ContentType = new("text/plain"); | ||
ctx.Response.StatusCode = 200; | ||
await ctx.Response.WriteAsync("# This file is used by the Test Server\n# This allows testing loading by URI\nUser-agent: MyCustom-UserAgent\nDisallow: "); | ||
} | ||
else | ||
{ | ||
ctx.Response.StatusCode = context.ExpectedStatusCode; | ||
} | ||
await ctx.Response.CompleteAsync(); | ||
|
||
}); | ||
|
||
app.Run(); | ||
public partial class Program { } |
10 changes: 3 additions & 7 deletions
10
tests/TurnerSoftware.RobotsExclusionTools.Tests.TestSite/SiteContext.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 |
---|---|---|
@@ -1,11 +1,7 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace TurnerSoftware.RobotsExclusionTools.Tests.TestSite | ||
namespace TurnerSoftware.RobotsExclusionTools.Tests.TestSite | ||
{ | ||
public class SiteContext | ||
public class SiteContext(int expectedStatusCode) | ||
{ | ||
public int StatusCode { get; set; } | ||
public int ExpectedStatusCode { get; set; } = expectedStatusCode; | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
tests/TurnerSoftware.RobotsExclusionTools.Tests.TestSite/Startup.cs
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
tests/TurnerSoftware.RobotsExclusionTools.Tests.TestSite/TestSiteManager.cs
This file was deleted.
Oops, something went wrong.
42 changes: 18 additions & 24 deletions
42
...tsExclusionTools.Tests.TestSite/TurnerSoftware.RobotsExclusionTools.Tests.TestSite.csproj
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 |
---|---|---|
@@ -1,25 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="Resources\*.*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="Resources\*.*"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" /> | ||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.9" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Remove="Resources\*.*" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="Resources\*.*"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="9.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" /> | ||
</ItemGroup> | ||
</Project> |
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
Oops, something went wrong.