Fix tests ..ish.

This commit is contained in:
jvyden 2021-11-18 15:08:51 -05:00
parent 5e27f8c29b
commit e4bb16100d
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
6 changed files with 57 additions and 6 deletions

View file

@ -19,7 +19,7 @@ namespace LBPUnion.ProjectLighthouse.Tests
public LighthouseTest()
{
this.Server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
this.Server = new TestServer(new WebHostBuilder().UseStartup<TestStartup>());
this.Client = this.Server.CreateClient();
}

View file

@ -1,3 +1,4 @@
using System.Net.Http;
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Types;
using LBPUnion.ProjectLighthouse.Types.Levels;
@ -48,10 +49,17 @@ namespace LBPUnion.ProjectLighthouse.Tests
LoginResult loginResult = await this.Authenticate();
string respA = await (await this.AuthenticatedRequest("LITTLEBIGPLANETPS3_XML/slots/by?u=unitTestUser0", loginResult.AuthTicket)).Content
.ReadAsStringAsync();
string respB = await (await this.AuthenticatedRequest("LITTLEBIGPLANETPS3_XML/slots/by?u=unitTestUser1", loginResult.AuthTicket)).Content
.ReadAsStringAsync();
HttpResponseMessage respMessageA = await this.AuthenticatedRequest("LITTLEBIGPLANETPS3_XML/slots/by?u=unitTestUser0", loginResult.AuthTicket);
HttpResponseMessage respMessageB = await this.AuthenticatedRequest("LITTLEBIGPLANETPS3_XML/slots/by?u=unitTestUser1", loginResult.AuthTicket);
Assert.True(respMessageA.IsSuccessStatusCode);
Assert.True(respMessageB.IsSuccessStatusCode);
string respA = await respMessageA.Content.ReadAsStringAsync();
string respB = await respMessageB.Content.ReadAsStringAsync();
Assert.False(string.IsNullOrEmpty(respA));
Assert.False(string.IsNullOrEmpty(respB));
Assert.NotEqual(respA, respB);
Assert.DoesNotContain(respA, "slotB");

View file

@ -73,6 +73,7 @@
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseExplicitType</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseExplicitType</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DLC/@EntryIndexedValue">DLC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IP/@EntryIndexedValue">IP</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LBP/@EntryIndexedValue">LBP</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MM/@EntryIndexedValue">MM</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NAT/@EntryIndexedValue">NAT</s:String>

View file

@ -0,0 +1,24 @@
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace LBPUnion.ProjectLighthouse
{
public class FakeRemoteIPAddressMiddleware
{
private readonly RequestDelegate next;
private readonly IPAddress fakeIpAddress = IPAddress.Parse("127.0.0.1");
public FakeRemoteIPAddressMiddleware(RequestDelegate next)
{
this.next = next;
}
public async Task Invoke(HttpContext httpContext)
{
httpContext.Connection.RemoteIpAddress = this.fakeIpAddress;
await this.next(httpContext);
}
}
}

View file

@ -51,7 +51,7 @@ namespace LBPUnion.ProjectLighthouse
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
bool computeDigests = true;
string serverDigestKey = Environment.GetEnvironmentVariable("SERVER_DIGEST_KEY");

View file

@ -0,0 +1,18 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
namespace LBPUnion.ProjectLighthouse
{
public class TestStartup : Startup
{
public TestStartup(IConfiguration configuration) : base(configuration)
{}
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseMiddleware<FakeRemoteIPAddressMiddleware>();
base.Configure(app, env);
}
}
}