added tests
This commit is contained in:
parent
83d0c21182
commit
e6e059c9c2
|
|
@ -0,0 +1,66 @@
|
|||
using Fluxor;
|
||||
using KoogleApp.Games;
|
||||
using KoogleApp.Games.Training;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using KoogleApp.Store.Game.ThrowPanel;
|
||||
using Moq;
|
||||
|
||||
namespace Koogle.Tests.GameTraining
|
||||
{
|
||||
public class GameTrainingServiceTest
|
||||
{
|
||||
|
||||
private readonly ServiceProvider _serviceProvider;
|
||||
private readonly Mock<IDispatcher> _mockDispatcher;
|
||||
|
||||
public GameTrainingServiceTest()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
|
||||
// Deine Services registrieren wie in Program.cs
|
||||
services.AddScoped<IGameService, GameTrainingService>();
|
||||
//services.AddSingleton<IConfiguration>(new ConfigurationBuilder()
|
||||
// .AddInMemoryCollection(new Dictionary<string, string>
|
||||
// {
|
||||
// ["Setting"] = "TestValue"
|
||||
// })
|
||||
// .Build());
|
||||
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
_mockDispatcher = new Mock<IDispatcher>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServiceWorksCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var service = _serviceProvider.GetRequiredService<IGameService>();
|
||||
|
||||
// Act & Assert
|
||||
var result = service.InitGameModel(GetSetup(), _mockDispatcher.Object) as TrainingGameModel;
|
||||
result.Throws.Count.Should().Be(3);
|
||||
}
|
||||
|
||||
private IGameSetupModel GetSetup()
|
||||
{
|
||||
return new TrainingSetupState()
|
||||
{
|
||||
DayId = 1,
|
||||
ThrowMode = ThrowMode.Reposition,
|
||||
ThrowsPerRound = 3,
|
||||
Participants = new int[] { 1, 2, 3 },
|
||||
ParticipantsMode = ParticipantsMode.GameLogic,
|
||||
KnownGameType = "Training"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||
<PackageReference Include="FluentAssertions" Version="8.8.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KoogleApp\KoogleApp.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
using KoogleApp.Components.Controls;
|
||||
using KoogleApp.Games.Training;
|
||||
using KoogleApp.Store.Game.ThrowPanel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace Koogle.Tests.ReducerTests
|
||||
{
|
||||
public class ThrowPanelStateTests
|
||||
{
|
||||
[Fact]
|
||||
public void StartStopAction_StartAGame()
|
||||
{
|
||||
// Arrange
|
||||
var initialState = new ThrowPanelState();
|
||||
var action = new StartStopAction(initialState, new TrainingSetupState());
|
||||
|
||||
// Act
|
||||
var newState = ThrowPanelStateReducer.OnStartStop(initialState, action);
|
||||
|
||||
// Assert
|
||||
newState.IsStated.Should().Be(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartStopAction_StopAGame()
|
||||
{
|
||||
// Arrange
|
||||
var initialState = new ThrowPanelState();
|
||||
var action = new StartStopAction(initialState, null);
|
||||
|
||||
// Act
|
||||
var newState = ThrowPanelStateReducer.OnStartStop(initialState, action);
|
||||
|
||||
// Assert
|
||||
newState.IsStated.Should().Be(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
namespace Koogle.Tests
|
||||
{
|
||||
//public class UnitTest1
|
||||
//{
|
||||
// [Fact]
|
||||
// public void Test1()
|
||||
// {
|
||||
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
|
@ -5,6 +5,8 @@ VisualStudioVersion = 17.14.36401.2
|
|||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KoogleApp", "KoogleApp\KoogleApp.csproj", "{6D7E3614-968D-41F5-AD44-84E06C244859}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Koogle.Tests", "Koogle.Tests\Koogle.Tests.csproj", "{0940F5B5-C1FF-4B2C-8E1C-6F1D28BDAD7F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -15,6 +17,10 @@ Global
|
|||
{6D7E3614-968D-41F5-AD44-84E06C244859}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6D7E3614-968D-41F5-AD44-84E06C244859}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6D7E3614-968D-41F5-AD44-84E06C244859}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0940F5B5-C1FF-4B2C-8E1C-6F1D28BDAD7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0940F5B5-C1FF-4B2C-8E1C-6F1D28BDAD7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0940F5B5-C1FF-4B2C-8E1C-6F1D28BDAD7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0940F5B5-C1FF-4B2C-8E1C-6F1D28BDAD7F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
|||
Loading…
Reference in New Issue