Basic testing framework

This commit is contained in:
jvyden 2021-10-14 23:50:08 -04:00
commit 5052d19656
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
8 changed files with 97 additions and 4 deletions

View 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";
}
}
}

View 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();
}
}
}

View 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>

View file

@ -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>

View 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);
}
}
}