GameTests ClassDelta Engine Documentation
Unit tests for Game View code on GitHub
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    Blocks.Tests GameTests

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

public class GameTests : TestWithMocksOrVisually

The GameTests type exposes the following members.

Constructors

  NameDescription
Public methodGameTests
Initializes a new instance of the GameTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodAffixingBlockAddsToScore
Public methodBottomHalfClickDropsBlockFast
Public methodBottomHalfTouchDropsBlockFast
Public methodCreateGameInLandscape
Public methodCreateGameInPortrait
Public methodCursorDownDropsBlockFast
Public methodCursorLeftMovesBlockLeft
Public methodCursorRightMovesBlockRight
Public methodHoldingCursorLeftEventuallyMovesBlockLeftTwice
Public methodHoldingCursorRightEventuallyMovesBlockRightTwice
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodLeftHalfClickMovesBlockLeft
Public methodLeftHalfTouchMovesBlockLeft
Public methodMoveBlockLeftIsNotPossible
Public methodMoveBlockRightIsNotPossible
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Public methodRightHalfClickMovesBlockRight
Public methodRightHalfTouchMovesBlockRight
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodSetUp
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test, CloseAfterFirstFrame]
public void CreateGameInPortrait()
{
    var window = Resolve<Window>();
    window.ViewportPixelSize = new Size(600, 800);
    AdvanceTimeAndUpdateEntities();
}
[Test, CloseAfterFirstFrame]
public void CreateGameInLandscape()
{
    var window = Resolve<Window>();
    window.ViewportPixelSize = new Size(800, 600);
    AdvanceTimeAndUpdateEntities();
}
[Test, CloseAfterFirstFrame]
public void AffixingBlockAddsToScore()
{
    game.StartGame();
    Assert.AreEqual(0, game.UserInterface.Score);
    AdvanceTimeAndUpdateEntities(10.0f);
    Assert.AreEqual(1, game.UserInterface.Score);
}
[Test, CloseAfterFirstFrame]
public void CursorLeftMovesBlockLeft()
{
    game.StartGame();
    InitializeBlocks(game.Controller, content);
    mockKeyboard.SetKeyboardState(Key.CursorLeft, State.Pressing);
    AdvanceTimeAndUpdateEntities(0.01f);
    if (IsMockResolver)
    //ncrunch: no coverage start 
        return; 
    Assert.AreEqual(4, game.Controller.FallingBlock.Left);
    //ncrunch: no coverage end
}
[Test, CloseAfterFirstFrame]
public void HoldingCursorLeftEventuallyMovesBlockLeftTwice()
{
    game.StartGame();
    InitializeBlocks(game.Controller, content);
    mockKeyboard.SetKeyboardState(Key.CursorLeft, State.Pressing);
    AdvanceTimeAndUpdateEntities(0.01f);
    if (IsMockResolver)
    //ncrunch: no coverage start 
        return; 
    Assert.AreEqual(4, game.Controller.FallingBlock.Left);
    AdvanceTimeAndUpdateEntities(0.02f);
    Assert.AreEqual(3, game.Controller.FallingBlock.Left);
    //ncrunch: no coverage end
}
[Test, CloseAfterFirstFrame]
public void CursorRightMovesBlockRight()
{
    game.StartGame();
    InitializeBlocks(game.Controller, content);
    mockKeyboard.SetKeyboardState(Key.CursorRight, State.Pressing);
    AdvanceTimeAndUpdateEntities(0.01f);
    if (IsMockResolver)
    //ncrunch: no coverage start 
        return; 
    Assert.AreEqual(8, game.Controller.FallingBlock.Left);
    //ncrunch: no coverage end
}
[Test, CloseAfterFirstFrame]
public void HoldingCursorRightEventuallyMovesBlockRightTwice()
{
    game.StartGame();
    InitializeBlocks(game.Controller, content);
    mockKeyboard.SetKeyboardState(Key.CursorRight, State.Pressing);
    AdvanceTimeAndUpdateEntities(0.01f);
    if (IsMockResolver)
    //ncrunch: no coverage start 
        return;
    Assert.AreEqual(8, game.Controller.FallingBlock.Left);
    AdvanceTimeAndUpdateEntities(0.02f);
    Assert.AreEqual(9, game.Controller.FallingBlock.Left);
    //ncrunch: no coverage end
}
[Test, CloseAfterFirstFrame]
public void CursorDownDropsBlockFast()
{
    game.StartGame();
    InitializeBlocks(game.Controller, content);
    mockKeyboard.SetKeyboardState(Key.CursorDown, State.Pressing);
    AdvanceTimeAndUpdateEntities(0.01f);
    Assert.IsTrue(game.Controller.IsFallingFast);
}
[Test, CloseAfterFirstFrame]
public void LeftHalfClickMovesBlockLeft()
{
    game.StartGame();
    InitializeBlocks(game.Controller, content);
    mockMouse.SetNativePosition(new Vector2D(0.35f, 0.0f));
    mockMouse.SetButtonState(MouseButton.Left, State.Pressing);
    AdvanceTimeAndUpdateEntities(0.05f);
    Assert.AreEqual(IndexOfSpawnColumn, game.Controller.FallingBlock.Left);
}
[Test, CloseAfterFirstFrame]
public void RightHalfClickMovesBlockRight()
{
    game.StartGame();
    InitializeBlocks(game.Controller, content);
    mockMouse.SetNativePosition(new Vector2D(0.65f, 0.0f));
    mockMouse.SetButtonState(MouseButton.Left, State.Pressing);
    AdvanceTimeAndUpdateEntities(0.01f);
    Assert.AreEqual(IndexOfSpawnColumn, game.Controller.FallingBlock.Left);
}
[Test, CloseAfterFirstFrame]
public void BottomHalfClickDropsBlockFast()
{
    game.StartGame();
    InitializeBlocks(game.Controller, content);
    mockMouse.SetNativePosition(new Vector2D(0.5f, 0.6f));
    mockMouse.SetButtonState(MouseButton.Left, State.Pressing);
    AdvanceTimeAndUpdateEntities(0.01f);
    Assert.IsTrue(game.Controller.IsFallingFast);
}
[Test, CloseAfterFirstFrame]
public void LeftHalfTouchMovesBlockLeft()
{
    game.StartGame();
    InitializeBlocks(game.Controller, content);
    mockTouch.SetTouchState(0, State.Pressing, new Vector2D(0.35f, 0.0f));
    AdvanceTimeAndUpdateEntities(0.01f);
    Assert.AreEqual(IndexOfSpawnColumn, game.Controller.FallingBlock.Left);
}
[Test, CloseAfterFirstFrame]
public void RightHalfTouchMovesBlockRight()
{
    game.StartGame();
    InitializeBlocks(game.Controller, content);
    mockTouch.SetTouchState(0, State.Pressing, new Vector2D(0.65f, 0.0f));
    AdvanceTimeAndUpdateEntities(0.01f);
    Assert.AreEqual(IndexOfSpawnColumn, game.Controller.FallingBlock.Left);
}
[Test, CloseAfterFirstFrame]
public void BottomHalfTouchDropsBlockFast()
{
    game.StartGame();
    InitializeBlocks(game.Controller, content);
    mockTouch.SetTouchState(0, State.Pressing, new Vector2D(0.5f, 0.6f));
    AdvanceTimeAndUpdateEntities(0.01f);
    Assert.IsTrue(game.Controller.IsFallingFast);
}
[Test, CloseAfterFirstFrame]
public void MoveBlockLeftIsNotPossible()
{
    game.StartGame();
    InitializeBlocks(game.Controller, content);
    game.Controller.FallingBlock = null;
    mockKeyboard.SetKeyboardState(Key.CursorLeft, State.Pressing);
}
[Test, CloseAfterFirstFrame]
public void MoveBlockRightIsNotPossible()
{
    game.StartGame();
    InitializeBlocks(game.Controller, content);
    game.Controller.FallingBlock = null;
    mockKeyboard.SetKeyboardState(Key.CursorRight, State.Pressing);
}
See Also