mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-21 09:49:34 +00:00
Basic testing framework
This commit is contained in:
parent
bce6d1e2ef
commit
5052d19656
8 changed files with 97 additions and 4 deletions
11
ProjectLighthouse.Tests/DatabaseFact.cs
Normal file
11
ProjectLighthouse.Tests/DatabaseFact.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using ProjectLighthouse.Types;
|
||||
using Xunit;
|
||||
|
||||
namespace ProjectLighthouse.Tests {
|
||||
public sealed class DatabaseFact : FactAttribute {
|
||||
public DatabaseFact() {
|
||||
ServerSettings.DbConnectionString = "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse";
|
||||
if(!ServerSettings.DbConnected) Skip = "Database not available";
|
||||
}
|
||||
}
|
||||
}
|
19
ProjectLighthouse.Tests/LighthouseTest.cs
Normal file
19
ProjectLighthouse.Tests/LighthouseTest.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using ProjectLighthouse.Types;
|
||||
|
||||
namespace ProjectLighthouse.Tests {
|
||||
public class LighthouseTest {
|
||||
public readonly TestServer Server;
|
||||
public readonly HttpClient Client;
|
||||
|
||||
public LighthouseTest() {
|
||||
this.Server = new TestServer(new WebHostBuilder()
|
||||
.UseStartup<Startup>());
|
||||
this.Client = this.Server.CreateClient();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
29
ProjectLighthouse.Tests/ProjectLighthouse.Tests.csproj
Normal file
29
ProjectLighthouse.Tests/ProjectLighthouse.Tests.csproj
Normal file
|
@ -0,0 +1,29 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.11" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.0.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ProjectLighthouse\ProjectLighthouse.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,2 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tests/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
28
ProjectLighthouse.Tests/Tests/AuthenticationTest.cs
Normal file
28
ProjectLighthouse.Tests/Tests/AuthenticationTest.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace ProjectLighthouse.Tests {
|
||||
public class AuthenticationTest : LighthouseTest {
|
||||
[Fact]
|
||||
public async Task ShouldReturnErrorOnNoPostData() {
|
||||
var response = await this.Client.PostAsync("/LITTLEBIGPLANETPS3_XML/login", null!);
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
#if NET6_0_OR_GREATER
|
||||
Assert.True(response.StatusCode == HttpStatusCode.BadRequest);
|
||||
#else
|
||||
Assert.True(response.StatusCode == HttpStatusCode.NotAcceptable);
|
||||
#endif
|
||||
}
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task ShouldAuthenticateWithValidData() {
|
||||
const char nullChar = (char)0x00;
|
||||
const char sepChar = (char)0x20;
|
||||
|
||||
var response = await this.Client.PostAsync("/LITTLEBIGPLANETPS3_XML/login", new StringContent($"{nullChar}{sepChar}jvyden{nullChar}"));
|
||||
Assert.True(response.StatusCode == HttpStatusCode.OK);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue