PaddleTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    Breakout.Tests PaddleTests

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

public class PaddleTests : TestWithMocksOrVisually

The PaddleTests type exposes the following members.

Constructors

  NameDescription
Public methodPaddleTests
Initializes a new instance of the PaddleTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodControlPaddleVirtuallyWithGamePad
Public methodControlPaddleVirtuallyWithKeyboard
Public methodControlPaddleVirtuallyWithMouse
Public methodDraw
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodIsBallReleasedAfterSpacePressed
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test]
public void Draw()
{
    var ball = Resolve<TestBall>();
    var paddle = Resolve<Paddle>();
    Assert.AreEqual(0.5f, paddle.Position.X);
    Assert.IsTrue(ball.IsCurrentlyOnPaddle);
    Assert.AreEqual(0.5f, ball.Position.X);
}
[Test]
public void ControlPaddleVirtuallyWithKeyboard()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage
    Resolve<TestBall>();
    var paddle = Resolve<Paddle>();
    var keyboard = Resolve<MockKeyboard>();
    keyboard.SetKeyboardState(Key.CursorLeft, State.Pressed);
    AssertPaddleMovesLeftCorrectly(paddle);
    keyboard.SetKeyboardState(Key.CursorLeft, State.Released);
    keyboard.SetKeyboardState(Key.CursorRight, State.Pressed);
    AssertPaddleMovesRightCorrectly(paddle);
}
[Test, CloseAfterFirstFrame]
public void ControlPaddleVirtuallyWithGamePad()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage 
    var paddle = Resolve<Paddle>();
    var gamePad = Resolve<MockGamePad>();
    gamePad.SetGamePadState(GamePadButton.Left, State.Pressed);
    AssertPaddleMovesLeftCorrectly(paddle);
    gamePad.SetGamePadState(GamePadButton.Left, State.Released);
    gamePad.SetGamePadState(GamePadButton.Right, State.Pressed);
    AssertPaddleMovesRightCorrectly(paddle);
}
[Test, CloseAfterFirstFrame]
public void ControlPaddleVirtuallyWithMouse()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage 
    var paddle = Resolve<Paddle>();
    var mouse = Resolve<MockMouse>();
    mouse.SetNativePosition(new Vector2D(0.45f, 0.76f));
    mouse.SetButtonState(MouseButton.Left, State.Pressed);
    AssertPaddleMovesLeftCorrectly(paddle);
    mouse.SetNativePosition(new Vector2D(0.55f, 0.76f));
    mouse.SetButtonState(MouseButton.Left, State.Released);
    mouse.SetButtonState(MouseButton.Left, State.Pressed);
    AssertPaddleMovesRightCorrectly(paddle);
}
[Test, CloseAfterFirstFrame]
public void IsBallReleasedAfterSpacePressed()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage 
    var ball = Resolve<TestBall>();
    Resolve<Paddle>();
    PressSpaceOneTick();
    Assert.IsFalse(ball.IsCurrentlyOnPaddle);
    Assert.AreNotEqual(0.5f, ball.Position.X);
}
See Also