KeyTriggerTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    DeltaEngine.Input.Tests KeyTriggerTests

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

public class KeyTriggerTests : TestWithMocksOrVisually

The KeyTriggerTests type exposes the following members.

Constructors

  NameDescription
Public methodKeyTriggerTests
Initializes a new instance of the KeyTriggerTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodCreate
Public methodCreateFromAttributes
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodPressCursorKeysToShowCircles
Public methodPressEscapeToCloseWindow
Public methodPressEscapeToCloseWindowViaRegisteredCommands
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodUseMoveDirectlyCommandToMoveCircleAround
Public methodZoomCircleWithPageUpPageDown
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test]
public void PressEscapeToCloseWindow()
{
    new FontText(Font.Default, "Press ESC to close the window", Rectangle.One);
    new Command(() => Resolve<Window>().CloseAfterFrame()).Add(new KeyTrigger(Key.Escape,
        State.Pressed));
}
[Test]
public void PressEscapeToCloseWindowViaRegisteredCommands()
{
    new FontText(Font.Default, "Press ESC to close the window", Rectangle.One);
    Command.Register("Exit", new KeyTrigger(Key.Escape, State.Pressed));
    new Command("Exit", () => Resolve<Window>().CloseAfterFrame());
}
[Test]
public void PressCursorKeysToShowCircles()
{
    var centers = new[]
    {
        new Vector2D(0.5f, 0.4f), new Vector2D(0.5f, 0.6f), new Vector2D(0.3f, 0.6f),
        new Vector2D(0.7f, 0.6f)
    };
    var size = new Size(0.1f, 0.1f);
    CreateFontTexts(centers, size);
    AddCirclesAndInputCommands(centers, size);
}
[Test, CloseAfterFirstFrame]
public void Create()
{
    var trigger = new KeyTrigger(Key.Z, State.Pressed);
    Assert.AreEqual(Key.Z, trigger.Key);
    Assert.AreEqual(State.Pressed, trigger.State);
}
    [Test, CloseAfterFirstFrame]
    public void CreateFromAttributes()
    {
        var trigger = new KeyTrigger(new Dictionary<string, string>
            {
                { "Key", "Z" },
                { "State", " Pressed" }
            });
        Assert.AreEqual(Key.Z, trigger.Key);
        Assert.AreEqual(State.Pressed, trigger.State);
        Assert.Throws<KeyTrigger.CannotCreateKeyTriggerWithoutKey>(
            () => new KeyTrigger(new Dictionary<string, string>()));
    }

    [Test]
    public void UseMoveDirectlyCommandToMoveCircleAround()
    {
        var circle = new Ellipse(Vector2D.Half, 0.25f, 0.25f, Color.Orange);
        new Command(Command.MoveDirectly, position =>
            circle.DrawArea = circle.DrawArea.Move(position / 24.0f)); //ncrunch: no coverage
    }

    [Test]
    public void ZoomCircleWithPageUpPageDown()
    {
        var circle = new Ellipse(Vector2D.Half, 0.25f, 0.25f, Color.Orange);
        new Command(Command.Zoom, zoom =>
            circle.DrawArea = circle.DrawArea.Increase(new Size(zoom / 24.0f))); //ncrunch: no coverage
    }
}
[Test]
public void UseMoveDirectlyCommandToMoveCircleAround()
{
    var circle = new Ellipse(Vector2D.Half, 0.25f, 0.25f, Color.Orange);
    new Command(Command.MoveDirectly, position =>
        circle.DrawArea = circle.DrawArea.Move(position / 24.0f)); //ncrunch: no coverage
}
[Test]
public void ZoomCircleWithPageUpPageDown()
{
    var circle = new Ellipse(Vector2D.Half, 0.25f, 0.25f, Color.Orange);
    new Command(Command.Zoom, zoom =>
        circle.DrawArea = circle.DrawArea.Increase(new Size(zoom / 24.0f))); //ncrunch: no coverage
}
See Also