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.Contract;
using GameModel.Exceptions;
using GameModel.Mocks;
using System;
using System.Collections.Generic;
using System.Linq;
@ -12,33 +15,40 @@ namespace GameHandler.UnitTests
[TestFixture]
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]
public void Start_InvalidStartStatusThrowInvalidGameStateExcpetion()
{
GameService service = new GameService();
{
service.Start();
Assert.That(() => service.Start(), Throws.TypeOf<InvalidGameStateExcpetion>());
}
[Test]
public void Stop_InvalidStopStatusThrowInvalidGameStateExcpetion()
{
GameService service = new GameService();
{
Assert.That(() => service.Stop(), Throws.TypeOf<InvalidGameStateExcpetion>());
}
[Test]
public void HandleThrow_NotPossibleBeforeStart()
{
GameService service = new GameService();
{
Assert.That(() => service.HandleThrow(null), Throws.TypeOf<InvalidGameStateExcpetion>());
}
[Test]
public void HandleThrow_NotPossibleAfterStop()
{
GameService service = new GameService();
{
service.Start();
service.Stop();
Assert.That(() => service.HandleThrow(null), Throws.TypeOf<InvalidGameStateExcpetion>());
@ -46,8 +56,7 @@ namespace GameHandler.UnitTests
[Test]
public void HandleThrow_UpdatesTheBoardState()
{
GameService service = new GameService();
{
var ts1 = service.Start(DeathGameHandler.GAMENAME_DEATHBOX);
var bs1 = ts1.ThrowState.BoardState;

View File

@ -21,18 +21,18 @@ namespace GameHandler
{
public class GameService
{
private IContainer? _container { get; set; }
private IContainer _container { get; set; }
private bool _isStarted = false;
private ILifetimeScope? _scope;
private ILifetimeScope _scope;
private IGameHandler _gh;
private ThrowHandler _th;
private ExpenseHandler _eh;
private GameState _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;
}