Created
May 18, 2016 16:40
-
-
Save JamesBender/11d566b33b5ed6eda05cf293204af894 to your computer and use it in GitHub Desktop.
Game Engine Tests for TDD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using GameNetworkInterfaces; | |
using Moq; | |
using NUnit.Framework; | |
using TicTacToe.Core; | |
namespace TicTacToe.UnitTests | |
{ | |
[TestFixture] | |
class GameEngineTests | |
{ | |
private GameEngine _gameEngine; | |
private string[,] _board; | |
private Mock<ICommonGameNetworkControl> _networkMock; | |
[SetUp] | |
public void SetUpTests() | |
{ | |
_board = new string[3, 3] { { " ", " ", " " }, { " ", " ", " " }, { " ", " ", " " } }; | |
_networkMock = new Mock<ICommonGameNetworkControl>(); | |
_gameEngine = new GameEngine(_networkMock.Object); | |
} | |
[Test] | |
public void WhenTheBoardIsEmptyThenThereIsNotWinnerYet() | |
{ | |
//Arrainge | |
var expectedResult = " "; | |
//Act | |
var result = _gameEngine.GetWinner(_board); | |
//Assert | |
Assert.AreEqual(expectedResult, result); | |
} | |
[Test] | |
public void WhenTheTopRowIsAllXThenXWins() | |
{ | |
//Arrainge | |
_board[0,0] ="X"; | |
_board[0,1] ="X"; | |
_board[0,2] ="X"; | |
var expectedResult = "X"; | |
//Act | |
var result = _gameEngine.GetWinner(_board); | |
//Assert | |
Assert.AreEqual(expectedResult, result); | |
} | |
[Test] | |
public void WhenILogInIShoulGetASessionToken() | |
{ | |
//arr | |
var userName = "bob"; | |
var password = "12345"; | |
var expectedResult = Guid.NewGuid(); | |
_networkMock.Setup(x => x.Login(userName, password)).Returns(expectedResult); | |
//act | |
var result = _gameEngine.Login(userName, password); | |
//assert | |
Assert.AreEqual(expectedResult, result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment