MouseDragTriggerTests ClassDelta Engine Documentation
Inheritance Hierarchy

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

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

public class MouseDragTriggerTests : TestWithMocksOrVisually

The MouseDragTriggerTests type exposes the following members.

Constructors

  NameDescription
Public methodMouseDragTriggerTests
Initializes a new instance of the MouseDragTriggerTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodCreate
Public methodCreateFromAttributes
Public methodDragMouseHorizontally
Public methodDragMouseHorizontalToCreateRectangles
Public methodDragMouseIsPressingSetPosition
Public methodDragMouseToCreateRectangles
Public methodDragMouseVertically
Public methodDragMouseVerticalToCreateRectangles
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
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 DragMouseToCreateRectangles()
{
    DragToCreateRectangles(new MouseDragTrigger());
}
[Test, CloseAfterFirstFrame]
public void Create()
{
    Assert.AreEqual(MouseButton.Left, new MouseDragTrigger().Button);
    Assert.AreEqual(MouseButton.Right, new MouseDragTrigger(MouseButton.Right).Button);
}
[Test, CloseAfterFirstFrame]
public void CreateFromAttributes()
{
    Assert.AreEqual(MouseButton.Left,
        new MouseDragTrigger(new Dictionary<string, string>()).Button);
    Assert.AreEqual(MouseButton.Right,
        new MouseDragTrigger(new Dictionary<string, string> { { "Button", "Right" } }).Button);
}
[Test]
public void DragMouseHorizontalToCreateRectangles()
{
    var rectangle = new FilledRect(Rectangle.Unused, Color.GetRandomColor());
    //ncrunch: no coverage start 
    new Command((start, end, done) =>
    {
        rectangle.DrawArea = new Rectangle(start.X, start.Y - 0.01f, end.X - start.X, 0.02f);
        if (done)
            rectangle = new FilledRect(Rectangle.Unused, Color.GetRandomColor());
    }).Add(new MouseDragTrigger(MouseButton.Left, DragDirection.Horizontal));
    //ncrunch: no coverage end
}
[Test]
public void DragMouseVerticalToCreateRectangles()
{
    var rectangle = new FilledRect(Rectangle.Unused, Color.GetRandomColor());
    //ncrunch: no coverage start 
    new Command((start, end, done) =>
    {
        rectangle.DrawArea = new Rectangle(start.X - 0.01f, start.Y, 0.02f, end.Y - start.Y);
        if (done)
            rectangle = new FilledRect(Rectangle.Unused, Color.GetRandomColor());
    }).Add(new MouseDragTrigger(MouseButton.Left, DragDirection.Vertical));
    //ncrunch: no coverage end
}
[Test]
public void DragMouseIsPressingSetPosition()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage 
    var mouse = (MockMouse)Resolve<Mouse>();
    var trigger = new MouseDragTrigger();
    new Command(() => { }).Add(trigger);
    mouse.SetButtonState(MouseButton.Left, State.Pressing);
    AdvanceTimeAndUpdateEntities();
    Assert.AreEqual(trigger.StartPosition, mouse.Position);
    mouse.SetNativePosition(Vector2D.One);
    AdvanceTimeAndUpdateEntities();
    Assert.AreEqual(trigger.Movement, mouse.Position);
    mouse.SetButtonState(MouseButton.Left, State.Releasing);
    AdvanceTimeAndUpdateEntities();
    Assert.IsTrue(trigger.DoneDragging);
}
[Test]
public void DragMouseHorizontally()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage 
    var mouse = (MockMouse)Resolve<Mouse>();
    var trigger = new MouseDragTrigger(MouseButton.Left, DragDirection.Horizontal);
    new Command(() => { }).Add(trigger);
    mouse.SetNativePosition(new Vector2D(0.3f, 0.5f));
    mouse.SetButtonState(MouseButton.Left, State.Pressing);
    AdvanceTimeAndUpdateEntities();
    mouse.SetNativePosition(new Vector2D(0.7f, 0.5f));
    AdvanceTimeAndUpdateEntities();
    Assert.AreEqual(trigger.Movement, mouse.Position);
    mouse.SetButtonState(MouseButton.Left, State.Releasing);
    AdvanceTimeAndUpdateEntities();
    Assert.IsTrue(trigger.DoneDragging);
}
[Test]
public void DragMouseVertically()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage 
    var mouse = (MockMouse)Resolve<Mouse>();
    var trigger = new MouseDragTrigger(MouseButton.Left, DragDirection.Vertical);
    new Command(() => {}).Add(trigger);
    mouse.SetNativePosition(new Vector2D(0.3f, ScreenSpace.Current.Top + 0.1f));
    mouse.SetButtonState(MouseButton.Left, State.Pressing);
    AdvanceTimeAndUpdateEntities();
    mouse.SetNativePosition(new Vector2D(0.3f, ScreenSpace.Current.Bottom - 0.1f));
    AdvanceTimeAndUpdateEntities();
    Assert.AreEqual(mouse.Position, trigger.Movement);
    mouse.SetButtonState(MouseButton.Left, State.Releasing);
    AdvanceTimeAndUpdateEntities();
    Assert.IsTrue(trigger.DoneDragging);
}
See Also