Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into cleanupHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson-Williams-15 committed Jan 19, 2024
2 parents ccae365 + c98601e commit 73a7d7f
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .github/workflows/tests-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Builds and runs tests

name: Run tests

on: push

jobs:
test:
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0.x'
include-prerelease: true

- name: Run tests with dotnet
run: |
cd FU.API
dotnet test
shell: pwsh
30 changes: 30 additions & 0 deletions FU.API/FU.API.Tests/FU.API.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.11" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FU.API\FU.API.csproj" />
</ItemGroup>

</Project>
45 changes: 45 additions & 0 deletions FU.API/FU.API.Tests/GameServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace FU.API.Tests;

using FU.API.Data;
using FU.API.Services;
using Microsoft.EntityFrameworkCore;

public class GameServiceTests
{
private readonly DbContextOptions<AppDbContext> _contextOptions;

// adapted from https://github.com/dotnet/EntityFramework.Docs/blob/main/samples/core/Testing/TestingWithoutTheDatabase/InMemoryBloggingControllerTest.cs
public GameServiceTests()
{
_contextOptions = new DbContextOptionsBuilder<AppDbContext>()
.UseInMemoryDatabase("GameServiceTest")
.Options;

using var context = new AppDbContext(_contextOptions);

context.Database.EnsureDeleted();
context.Database.EnsureCreated();

context.SaveChanges();
}

AppDbContext CreateContext() => new(_contextOptions);

[Theory]
[InlineData("")]
[InlineData("Title1")]
[InlineData("Title with space")]
[InlineData("Title with symbols :-={}<>.")]
public async void CreateGame_WithValidString_ReturnsGame(string gameName)
{
// Arrange
using var context = CreateContext();
var gameService = new GameService(context);

// Act
var game = await gameService.CreateGame(gameName);

// Assert
Assert.Equal(game.Name, gameName);
}
}
1 change: 1 addition & 0 deletions FU.API/FU.API.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
6 changes: 6 additions & 0 deletions FU.API/FU.API.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FU.API.Tests", "FU.API.Tests\FU.API.Tests.csproj", "{EECF8E74-3D21-449F-92A9-B3A77B784ADD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -20,6 +22,10 @@ Global
{3126D604-A505-4516-8204-9805A7807DB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3126D604-A505-4516-8204-9805A7807DB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3126D604-A505-4516-8204-9805A7807DB0}.Release|Any CPU.Build.0 = Release|Any CPU
{EECF8E74-3D21-449F-92A9-B3A77B784ADD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EECF8E74-3D21-449F-92A9-B3A77B784ADD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EECF8E74-3D21-449F-92A9-B3A77B784ADD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EECF8E74-3D21-449F-92A9-B3A77B784ADD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dotnet ef database update
### Connect to Postgres
Set the `CONNECTION_STRING` environment variable.
```
CONNECTION_STRING="Host=localhost; Database=ForcesUnite; Username=dev; Password=dev"
CONNECTION_STRING="Host=localhost; Database=fu_dev; Username=dev; Password=dev"
```

### SPA Environment Setup
Expand Down

0 comments on commit 73a7d7f

Please sign in to comment.