SnakeTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    Snake.Tests SnakeTests

Namespace: Snake.Tests
Assembly: Snake.Tests (in Snake.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class SnakeTests : TestWithMocksOrVisually

The SnakeTests type exposes the following members.

Constructors

  NameDescription
Public methodSnakeTests
Initializes a new instance of the SnakeTests class
Top
Methods

  NameDescription
Public methodAddToSnake
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodCheckTrailingVector
Public methodCreateSnakeAtOrigin
Public methodDisposeSnake
Public methodInit
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Public methodRemovingAllBodyPartsStillGivesAPosition
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodSnakeCollidingWithItselfWillRestart
Public methodSnakeHasTwoParts
Public methodTouchBottomBorder
Public methodTouchLeftBorder
Public methodTouchRightBorder
Public methodTouchTopBorder
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test, CloseAfterFirstFrame]
public void CreateSnakeAtOrigin()
{
    var snake = new Snake(gridSize, Color.Green);
    Assert.AreEqual(Vector2D.Half, snake.Get<Body>().HeadPosition);
    Assert.AreEqual(new Vector2D(startPosition, startPosition),
        snake.Get<Body>().BodyParts[0].TopLeft);
}
[Test, CloseAfterFirstFrame]
public void SnakeHasTwoParts()
{
    var game = new Game(Resolve<Window>());
    game.StartGame();
    Assert.AreEqual(2, game.Snake.Get<Body>().BodyParts.Count);
}
[Test, CloseAfterFirstFrame]
public void AddToSnake()
{
    var game = new Game(Resolve<Window>());
    game.StartGame();
    Assert.AreEqual(2, game.Snake.Get<Body>().BodyParts.Count);
}
[Test, CloseAfterFirstFrame]
public void TouchTopBorder()
{
    new Game(Resolve<Window>());
    AdvanceTimeAndUpdateEntities(moveSpeed * gridSize / 2);
}
[Test, CloseAfterFirstFrame]
public void TouchLeftBorder()
{
    var game = new Game(Resolve<Window>());
    game.StartGame();
    game.MoveLeft();
    AdvanceTimeAndUpdateEntities(moveSpeed * gridSize / 2);
}
[Test, CloseAfterFirstFrame]
public void TouchRightBorder()
{
    var game = new Game(Resolve<Window>());
    game.StartGame();
    game.MoveRight();
    AdvanceTimeAndUpdateEntities(moveSpeed * gridSize / 2);
}
[Test, CloseAfterFirstFrame]
public void TouchBottomBorder()
{
    var game = new Game(Resolve<Window>());
    game.StartGame();
    game.MoveLeft();
    AdvanceTimeAndUpdateEntities(moveSpeed);
    game.MoveDown();
    AdvanceTimeAndUpdateEntities(moveSpeed * gridSize / 2);
}
[Test, CloseAfterFirstFrame]
public void CheckTrailingVector()
{
    var snake = new Snake(gridSize, Color.Green);
    Assert.IsTrue(snake.Get<Body>().GetTrailingVector().IsNearlyEqual(new Vector2D(0, blockSize)));
}
[Test, CloseAfterFirstFrame]
public void SnakeCollidingWithItselfWillRestart()
{
    var game = new Game(Resolve<Window>());
    game.StartGame();
    game.Snake.Get<Body>().AddSnakeBody();
    game.Snake.Get<Body>().AddSnakeBody();
    game.Snake.Get<Body>().AddSnakeBody();
    game.MoveLeft();
    AdvanceTimeAndUpdateEntities(moveSpeed);
    game.MoveDown();
    AdvanceTimeAndUpdateEntities(moveSpeed);
    game.MoveRight();
    AdvanceTimeAndUpdateEntities(moveSpeed);
}
[Test, CloseAfterFirstFrame]
public void DisposeSnake()
{
    var snake = new Snake(gridSize, Color.Green) { IsActive = false };
    Assert.AreEqual(2, snake.Get<Body>().BodyParts.Count);
    snake.Dispose();
    Assert.Throws<Entity.ComponentNotFound>(() => snake.Get<Body>());
}
[Test, CloseAfterFirstFrame]
public void RemovingAllBodyPartsStillGivesAPosition()
{
    var snake = new Snake(gridSize, Color.Green);
    snake.Get<Body>().BodyParts.Clear();
    AdvanceTimeAndUpdateEntities();
    Assert.AreEqual(Vector2D.Half, snake.Get<Body>().HeadPosition);
}
See Also