Skip to content

Instantly share code, notes, and snippets.

@JamesBender
Created May 18, 2016 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesBender/11d566b33b5ed6eda05cf293204af894 to your computer and use it in GitHub Desktop.
Save JamesBender/11d566b33b5ed6eda05cf293204af894 to your computer and use it in GitHub Desktop.
Game Engine Tests for TDD
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