This commit is contained in:
Christian Kauer 2023-12-24 12:53:33 +01:00
parent 477bb12965
commit 670dfcc438
2 changed files with 24 additions and 15 deletions

View File

@ -1,6 +1,9 @@
using GameHandler.DeathGame; using Autofac;
using GameHandler.DeathGame;
using GameModel; using GameModel;
using GameModel.Contract;
using GameModel.Exceptions; using GameModel.Exceptions;
using GameModel.Mocks;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -12,10 +15,20 @@ namespace GameHandler.UnitTests
[TestFixture] [TestFixture]
internal class GameServiceTests internal class GameServiceTests
{ {
private GameService service;
[SetUp]
public void SetUp()
{
var builder = new ContainerBuilder();
builder.RegisterType<FakeExpenseRepository>().As<IExpenseRepository>();
service = new GameService(builder.Build());
}
[Test] [Test]
public void Start_InvalidStartStatusThrowInvalidGameStateExcpetion() public void Start_InvalidStartStatusThrowInvalidGameStateExcpetion()
{ {
GameService service = new GameService();
service.Start(); service.Start();
Assert.That(() => service.Start(), Throws.TypeOf<InvalidGameStateExcpetion>()); Assert.That(() => service.Start(), Throws.TypeOf<InvalidGameStateExcpetion>());
} }
@ -23,7 +36,6 @@ namespace GameHandler.UnitTests
[Test] [Test]
public void Stop_InvalidStopStatusThrowInvalidGameStateExcpetion() public void Stop_InvalidStopStatusThrowInvalidGameStateExcpetion()
{ {
GameService service = new GameService();
Assert.That(() => service.Stop(), Throws.TypeOf<InvalidGameStateExcpetion>()); Assert.That(() => service.Stop(), Throws.TypeOf<InvalidGameStateExcpetion>());
} }
@ -31,14 +43,12 @@ namespace GameHandler.UnitTests
[Test] [Test]
public void HandleThrow_NotPossibleBeforeStart() public void HandleThrow_NotPossibleBeforeStart()
{ {
GameService service = new GameService();
Assert.That(() => service.HandleThrow(null), Throws.TypeOf<InvalidGameStateExcpetion>()); Assert.That(() => service.HandleThrow(null), Throws.TypeOf<InvalidGameStateExcpetion>());
} }
[Test] [Test]
public void HandleThrow_NotPossibleAfterStop() public void HandleThrow_NotPossibleAfterStop()
{ {
GameService service = new GameService();
service.Start(); service.Start();
service.Stop(); service.Stop();
Assert.That(() => service.HandleThrow(null), Throws.TypeOf<InvalidGameStateExcpetion>()); Assert.That(() => service.HandleThrow(null), Throws.TypeOf<InvalidGameStateExcpetion>());
@ -47,7 +57,6 @@ namespace GameHandler.UnitTests
[Test] [Test]
public void HandleThrow_UpdatesTheBoardState() public void HandleThrow_UpdatesTheBoardState()
{ {
GameService service = new GameService();
var ts1 = service.Start(DeathGameHandler.GAMENAME_DEATHBOX); var ts1 = service.Start(DeathGameHandler.GAMENAME_DEATHBOX);
var bs1 = ts1.ThrowState.BoardState; var bs1 = ts1.ThrowState.BoardState;

View File

@ -21,18 +21,18 @@ namespace GameHandler
{ {
public class GameService public class GameService
{ {
private IContainer? _container { get; set; } private IContainer _container { get; set; }
private bool _isStarted = false; private bool _isStarted = false;
private ILifetimeScope? _scope; private ILifetimeScope _scope;
private IGameHandler _gh; private IGameHandler _gh;
private ThrowHandler _th; private ThrowHandler _th;
private ExpenseHandler _eh; private ExpenseHandler _eh;
private GameState _lastState; private GameState _lastState;
public GameState GameModel { get => _lastState; } public GameState GameModel { get => _lastState; }
private IExpenseRepository? _expenseRepository { get => _scope?.Resolve<IExpenseRepository>(); } private IExpenseRepository _expenseRepository { get => _scope.Resolve<IExpenseRepository>(); }
public GameService(IContainer? container =null) public GameService(IContainer container =null)
{ {
_container = container; _container = container;
} }