MouseDragDropTriggerTests ClassDelta Engine Documentation
Inheritance Hierarchy

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

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

public class MouseDragDropTriggerTests : TestWithMocksOrVisually

The MouseDragDropTriggerTests type exposes the following members.

Constructors

  NameDescription
Public methodMouseDragDropTriggerTests
Initializes a new instance of the MouseDragDropTriggerTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodCreate
Public methodCreateFromAttributes
Public methodDragDropCloseToStartPointWillDoNothing
Public methodDragDropInsideStartArea
Public methodDragDropOutsideStartArea
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.)
Public methodSetUp
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test, CloseAfterFirstFrame]
public void Create()
{
    var trigger = new MouseDragDropTrigger(Rectangle.One, MouseButton.Right);
    Assert.AreEqual(Rectangle.One, trigger.StartArea);
    Assert.AreEqual(MouseButton.Right, trigger.Button);
    Assert.AreEqual(Vector2D.Unused, trigger.StartDragPosition);
}
    [Test, CloseAfterFirstFrame]
    public void CreateFromAttributes()
    {
        var trigger = new MouseDragDropTrigger(new Dictionary<string, string>
            {
                { "StartArea", "1.1 2.2 3.3 4.4" },
                { "Button", "Right" }
            });
        Assert.AreEqual(new Rectangle(1.1f, 2.2f, 3.3f, 4.4f), trigger.StartArea);
        Assert.AreEqual(MouseButton.Right, trigger.Button);
        Assert.AreEqual(Vector2D.Unused, trigger.StartDragPosition);
        Assert.Throws<MouseDragDropTrigger.CannotCreateMouseDragDropTriggerWithoutStartArea>(
            () => new MouseDragDropTrigger(new Dictionary<string, string>()));
    }

    [Test, CloseAfterFirstFrame]
    public void DragDropOutsideStartArea()
    {
        if (mouse == null)
            return; //ncrunch: no coverage
        Vector2D startPoint = -Vector2D.One;
        new Command(position => { startPoint = position; }).Add(
            new MouseDragDropTrigger(Rectangle.HalfCentered, MouseButton.Left));
        SetMouseState(State.Pressing, Vector2D.Zero);
        SetMouseState(State.Pressed, Vector2D.One);
        SetMouseState(State.Releasing, Vector2D.One);
        SetMouseState(State.Released, Vector2D.One);
        Assert.AreEqual(-Vector2D.One, startPoint);
    }

    private void SetMouseState(State state, Vector2D position)
    {
        if (mouse == null)
            return; //ncrunch: no coverage
        mouse.SetButtonState(MouseButton.Left, state);
        mouse.SetNativePosition(position);
        AdvanceTimeAndUpdateEntities();
    }

    [Test, CloseAfterFirstFrame]
    public void DragDropInsideStartArea()
    {
        if (mouse == null)
            return; //ncrunch: no coverage
        Vector2D startPoint = -Vector2D.One;
        new Command(position => { startPoint = position; }).Add(
            new MouseDragDropTrigger(Rectangle.HalfCentered, MouseButton.Left));
        SetMouseState(State.Pressing, Vector2D.Half);
        SetMouseState(State.Pressed, Vector2D.One);
        SetMouseState(State.Releasing, Vector2D.One);
        Assert.AreEqual(Vector2D.Half, startPoint);
    }

    [Test, CloseAfterFirstFrame]
    public void DragDropCloseToStartPointWillDoNothing()
    {
        if (mouse == null)
            return; //ncrunch: no coverage
        Vector2D startPoint = -Vector2D.One;
        new Command(position => { startPoint = position; }).Add(
            new MouseDragDropTrigger(Rectangle.HalfCentered, MouseButton.Left));
        SetMouseState(State.Pressing, Vector2D.Half);
        SetMouseState(State.Pressed, Vector2D.Half);
        SetMouseState(State.Releasing, Vector2D.Half);
        Assert.AreEqual(-Vector2D.One, startPoint);
    }
}
[Test, CloseAfterFirstFrame]
public void DragDropOutsideStartArea()
{
    if (mouse == null)
        return; //ncrunch: no coverage
    Vector2D startPoint = -Vector2D.One;
    new Command(position => { startPoint = position; }).Add(
        new MouseDragDropTrigger(Rectangle.HalfCentered, MouseButton.Left));
    SetMouseState(State.Pressing, Vector2D.Zero);
    SetMouseState(State.Pressed, Vector2D.One);
    SetMouseState(State.Releasing, Vector2D.One);
    SetMouseState(State.Released, Vector2D.One);
    Assert.AreEqual(-Vector2D.One, startPoint);
}
[Test, CloseAfterFirstFrame]
public void DragDropInsideStartArea()
{
    if (mouse == null)
        return; //ncrunch: no coverage
    Vector2D startPoint = -Vector2D.One;
    new Command(position => { startPoint = position; }).Add(
        new MouseDragDropTrigger(Rectangle.HalfCentered, MouseButton.Left));
    SetMouseState(State.Pressing, Vector2D.Half);
    SetMouseState(State.Pressed, Vector2D.One);
    SetMouseState(State.Releasing, Vector2D.One);
    Assert.AreEqual(Vector2D.Half, startPoint);
}
[Test, CloseAfterFirstFrame]
public void DragDropCloseToStartPointWillDoNothing()
{
    if (mouse == null)
        return; //ncrunch: no coverage
    Vector2D startPoint = -Vector2D.One;
    new Command(position => { startPoint = position; }).Add(
        new MouseDragDropTrigger(Rectangle.HalfCentered, MouseButton.Left));
    SetMouseState(State.Pressing, Vector2D.Half);
    SetMouseState(State.Pressed, Vector2D.Half);
    SetMouseState(State.Releasing, Vector2D.Half);
    Assert.AreEqual(-Vector2D.One, startPoint);
}
See Also