﻿using System;
using NUnit.Framework;
using StreetPacMan.Server.Facade;
using StreetPacMan.Server.Tests.Infra;

namespace StreetPacMan.Server.Tests.Integ
{
    [TestFixture]
    public class PacManStartedGame : BddBase
    {
        private readonly IServerFacade ServerFacade;
        private readonly GetGameStateResult GameInstance;

        public PacManStartedGame()
        {
            ServerFacade = ServerFacadeFactory.GetServerFacade();
            ServerFacade.CreateGameX("GameName");
            var pacman = ServerFacade.JoinGameX("GameName", "PacManName", PlayerRole.PacMan);
            ServerFacade.UpdateMyWhereabouts(new ServerPollParameters(pacman.PlayerId, 0, 0, true));
            GameInstance = ServerFacade.GetGameStateForX(pacman.PlayerId);
        }
        [Test]
        public void GameStateShouldBeStarted()
        {
            Assert.AreEqual(GameState.Started, GameInstance.State);
        }
        [Test]
        public void AnotherGhostCannotJoin()
        {
            Assert.Throws<InvalidOperationException>(() => ServerFacade.JoinGameX("GameName", "G1", PlayerRole.Ghost));
        }
        [Test]
        public void AnotherPacManCannotJoin()
        {
            Assert.Throws<InvalidOperationException>(() => ServerFacade.JoinGameX("GameName", "P1", PlayerRole.PacMan));
        }
        [Test]
        public void AnotherObserverCanJoin()
        {
            Assert.AreNotEqual(0,ServerFacade.JoinGameX("GameName", "O1", PlayerRole.Observer).PlayerId);
        }
    }
}