MouseButtonTriggerTests ClassDelta Engine Documentation
Inheritance Hierarchy

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

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

public class MouseButtonTriggerTests : TestWithMocksOrVisually

The MouseButtonTriggerTests type exposes the following members.

Constructors

  NameDescription
Public methodMouseButtonTriggerTests
Initializes a new instance of the MouseButtonTriggerTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodClickAndHoldToShowRedEllipseAtMousePosition
Public methodCreate
Public methodCreateFromAttributes
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodIsTriggered
Public methodPressLeftMouseButtonToCloseWindow
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 PressLeftMouseButtonToCloseWindow()
{
    new FontText(Font.Default, "Press Left Mouse Button to close window", Rectangle.One);
    new Command(() => Resolve<Window>().CloseAfterFrame()).Add(new MouseButtonTrigger());
}
[Test]
public void ClickAndHoldToShowRedEllipseAtMousePosition()
{
    var ellipse = new Ellipse(new Rectangle(-0.1f, -0.1f, 0.1f, 0.1f), Color.Red);
    new Command(position => ellipse.Center = position).Add(new MouseButtonTrigger(State.Pressed));
}
[Test, CloseAfterFirstFrame]
public void Create()
{
    var trigger = new MouseButtonTrigger(MouseButton.Right, State.Pressed);
    Assert.AreEqual(MouseButton.Right, trigger.Button);
    Assert.AreEqual(State.Pressed, trigger.State);
    Assert.AreEqual(MouseButton.Left, new MouseButtonTrigger().Button);
    Assert.AreEqual(State.Pressing, new MouseButtonTrigger().State);
    Assert.AreEqual(MouseButton.Left, new MouseButtonTrigger(State.Pressed).Button);
    Assert.AreEqual(State.Pressed, new MouseButtonTrigger(State.Pressed).State);
}
    [Test, CloseAfterFirstFrame]
    public void CreateFromAttributes()
    {
        var trigger = new MouseButtonTrigger(new Dictionary<string, string>
            {
                { "Button", "Right" },
                { "State", " Pressed" }
            });
        Assert.AreEqual(MouseButton.Right, trigger.Button);
        Assert.AreEqual(State.Pressed, trigger.State);
        Assert.Throws<MouseButtonTrigger.CannotCreateMouseButtonTriggerWithoutButton>(
            () => new MouseButtonTrigger(new Dictionary<string, string>()));
    }

    [Test, CloseAfterFirstFrame]
    public void IsTriggered()
    {
        if (!IsMockResolver)
            return; //ncrunch: no coverage 
        var trigger = new MouseButtonTrigger(MouseButton.Right, State.Pressed);
        bool invoked = false;
        trigger.Invoked += () => invoked = true;
        var mouse = Resolve<MockMouse>();
        mouse.SetButtonState(MouseButton.Right, State.Pressed);
        AdvanceTimeAndUpdateEntities();
        Assert.True(invoked);
    }
}
[Test, CloseAfterFirstFrame]
public void IsTriggered()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage 
    var trigger = new MouseButtonTrigger(MouseButton.Right, State.Pressed);
    bool invoked = false;
    trigger.Invoked += () => invoked = true;
    var mouse = Resolve<MockMouse>();
    mouse.SetButtonState(MouseButton.Right, State.Pressed);
    AdvanceTimeAndUpdateEntities();
    Assert.True(invoked);
}
See Also