74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
using Autofac;
|
|
using GameHandler.DeathGame;
|
|
using GameHandler.UnitTests.Mocks;
|
|
using GameModel;
|
|
using GameModel.Contract;
|
|
using GameModel.Contracts;
|
|
using GameModel.Exceptions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GameHandler.UnitTests
|
|
{
|
|
[TestFixture]
|
|
internal class GameServiceTests
|
|
{
|
|
private GameService service;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
|
|
var builder = new ContainerBuilder();
|
|
builder.RegisterType<FakeExpenseRepository>().As<IExpenseRepository>();
|
|
builder.RegisterType<FakeGameRepository>().As<IGameRepository>();
|
|
service = new GameService(builder.Build());
|
|
}
|
|
|
|
[Test]
|
|
public void Start_InvalidStartStatusThrowInvalidGameStateExcpetion()
|
|
{
|
|
service.Start();
|
|
Assert.That(() => service.Start(), Throws.TypeOf<InvalidGameStateExcpetion>());
|
|
}
|
|
|
|
[Test]
|
|
public void Stop_InvalidStopStatusThrowInvalidGameStateExcpetion()
|
|
{
|
|
Assert.That(() => service.Stop(), Throws.TypeOf<InvalidGameStateExcpetion>());
|
|
}
|
|
|
|
|
|
[Test]
|
|
public void HandleThrow_NotPossibleBeforeStart()
|
|
{
|
|
Assert.That(() => service.HandleThrow(null), Throws.TypeOf<InvalidGameStateExcpetion>());
|
|
}
|
|
|
|
[Test]
|
|
public void HandleThrow_NotPossibleAfterStop()
|
|
{
|
|
service.Start();
|
|
service.Stop();
|
|
Assert.That(() => service.HandleThrow(null), Throws.TypeOf<InvalidGameStateExcpetion>());
|
|
}
|
|
|
|
[Test]
|
|
public async Task HandleThrow_UpdatesTheBoardState()
|
|
{
|
|
var ts1 = await service.Start(DeathGameHandler.GAMENAME_DEATHBOX);
|
|
var bs1 = ts1.ThrowState.BoardState;
|
|
|
|
var pinThrow = PinThrow.Create(1,PinPicture.Create(1,PinState.Down), false, false);
|
|
var ts2 = await service.HandleThrow(pinThrow);
|
|
var bs2 = ts2.ThrowState.BoardState;
|
|
|
|
|
|
Assert.That(bs2, Is.Not.EqualTo(bs1));
|
|
}
|
|
}
|
|
}
|