dev
This commit is contained in:
parent
477bb12965
commit
670dfcc438
|
|
@ -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,33 +15,40 @@ 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>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[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>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[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>());
|
||||||
|
|
@ -46,8 +56,7 @@ 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;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue