Inheritance Hierarchy
DeltaEngine.Platforms TestWithMocksOrVisually
DeltaEngine.Input.Tests MouseHoldTriggerTests
Namespace: DeltaEngine.Input.Tests
Assembly: DeltaEngine.Input.Tests (in DeltaEngine.Input.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax
The MouseHoldTriggerTests type exposes the following members.
Constructors
Name | Description | |
---|---|---|
MouseHoldTriggerTests | Initializes a new instance of the MouseHoldTriggerTests class |
Methods
Name | Description | |
---|---|---|
AdvanceTimeAndUpdateEntities | (Inherited from TestWithMocksOrVisually.) | |
Create | ||
CreateFromAttributes | ||
HoldLeftClickOnRectangle | ||
HoldMouseHovering | ||
HoldMouseInsideHoldArea | ||
HoldMouseOutsideHoldArea | ||
InitializeResolver | (Inherited from TestWithMocksOrVisually.) | |
MoveMouseInsideHoldArea | ||
RegisterMock T | (Inherited from TestWithMocksOrVisually.) | |
Resolve T | (Inherited from TestWithMocksOrVisually.) | |
RunAfterFirstFrame | (Inherited from TestWithMocksOrVisually.) | |
RunTestAndDisposeResolverWhenDone | (Inherited from TestWithMocksOrVisually.) | |
SetUp |
Properties
Name | Description | |
---|---|---|
IsMockResolver | (Inherited from TestWithMocksOrVisually.) |
Examples
[Test] public void HoldLeftClickOnRectangle() { var drawArea = new Rectangle(0.25f, 0.25f, 0.5f, 0.25f); new FilledRect(drawArea, Color.Blue); var trigger = new MouseHoldTrigger(drawArea); var counter = 0; var text = new FontText(Font.Default, "", drawArea.Move(new Vector2D(0.0f, 0.25f))); new Command(() => text.Text = "MouseHold Triggered " + ++counter + " times.").Add(trigger); }
[Test, CloseAfterFirstFrame] public void Create() { var trigger = new MouseHoldTrigger(Rectangle.One, 0.5f, MouseButton.Right); Assert.AreEqual(Rectangle.One, trigger.HoldArea); Assert.AreEqual(0.5f, trigger.HoldTime); Assert.AreEqual(MouseButton.Right, trigger.Button); }
[Test, CloseAfterFirstFrame] public void CreateFromAttributes() { var trigger = new MouseHoldTrigger(new Dictionary<string, string> { { "HoldArea", "1 2 3 4" }, { "HoldTime", "5.5" }, { "Button", "Right" } }); Assert.AreEqual(new Rectangle(1, 2, 3, 4), trigger.HoldArea); Assert.AreEqual(5.5f, trigger.HoldTime); Assert.AreEqual(MouseButton.Right, trigger.Button); Assert.Throws<MouseHoldTrigger.CannotCreateMouseHoldTriggerWithoutHoldArea>( () => new MouseHoldTrigger(new Dictionary<string, string>())); } [Test, CloseAfterFirstFrame] public void HoldMouseOutsideHoldArea() { if (mouse == null) return; //ncrunch: no coverage Vector2D mousePosition = -Vector2D.One; new Command(position => { mousePosition = position; }).Add( new MouseHoldTrigger(Rectangle.HalfCentered)); SetMouseState(State.Pressing, Vector2D.Zero); SetMouseState(State.Pressed, Vector2D.Zero); AdvanceTimeAndUpdateEntities(1.05f); Assert.AreEqual(-Vector2D.One, mousePosition); } private void SetMouseState(State state, Vector2D position) { if (mouse == null) return; //ncrunch: no coverage mouse.SetNativePosition(position); mouse.SetButtonState(MouseButton.Left, state); AdvanceTimeAndUpdateEntities(); } [Test, CloseAfterFirstFrame] public void HoldMouseHovering() { var drawArea = new Rectangle(0.25f, 0.25f, 0.5f, 0.25f); var rect = new FilledRect(drawArea, Color.Blue); var trigger = new MouseHoldTrigger(drawArea); trigger.Invoked += () => rect.Color = Color.Red; trigger.Movement = new Vector2D(0.3f, 0.3f); Assert.IsFalse(trigger.IsHovering()); AdvanceTimeAndUpdateEntities(1.05f); Assert.IsFalse(trigger.IsHovering()); } [Test, CloseAfterFirstFrame] public void MoveMouseInsideHoldArea() { if (mouse == null) return; //ncrunch: no coverage Vector2D mousePosition = -Vector2D.One; new Command(position => { mousePosition = position; }).Add( new MouseHoldTrigger(Rectangle.HalfCentered)); SetMouseState(State.Pressing, Vector2D.Half); SetMouseState(State.Pressed, Vector2D.Half); AdvanceTimeAndUpdateEntities(0.5f); SetMouseState(State.Pressed, new Vector2D(0.6f, 0.6f)); AdvanceTimeAndUpdateEntities(0.5f); Assert.AreEqual(Vector2D.Half, mousePosition); } //ncrunch: no coverage start [Test, CloseAfterFirstFrame, Category("Slow")] public void HoldMouseInsideHoldArea() { if (mouse == null) return; //ncrunch: no coverage Vector2D mousePosition = -Vector2D.One; new Command(position => { mousePosition = position; }).Add( new MouseHoldTrigger(Rectangle.HalfCentered)); SetMouseState(State.Pressing, Vector2D.Half); SetMouseState(State.Pressed, Vector2D.Half); AdvanceTimeAndUpdateEntities(1.05f); Assert.AreEqual(Vector2D.Half, mousePosition); } }
[Test, CloseAfterFirstFrame] public void HoldMouseOutsideHoldArea() { if (mouse == null) return; //ncrunch: no coverage Vector2D mousePosition = -Vector2D.One; new Command(position => { mousePosition = position; }).Add( new MouseHoldTrigger(Rectangle.HalfCentered)); SetMouseState(State.Pressing, Vector2D.Zero); SetMouseState(State.Pressed, Vector2D.Zero); AdvanceTimeAndUpdateEntities(1.05f); Assert.AreEqual(-Vector2D.One, mousePosition); }
[Test, CloseAfterFirstFrame] public void HoldMouseHovering() { var drawArea = new Rectangle(0.25f, 0.25f, 0.5f, 0.25f); var rect = new FilledRect(drawArea, Color.Blue); var trigger = new MouseHoldTrigger(drawArea); trigger.Invoked += () => rect.Color = Color.Red; trigger.Movement = new Vector2D(0.3f, 0.3f); Assert.IsFalse(trigger.IsHovering()); AdvanceTimeAndUpdateEntities(1.05f); Assert.IsFalse(trigger.IsHovering()); }
[Test, CloseAfterFirstFrame] public void MoveMouseInsideHoldArea() { if (mouse == null) return; //ncrunch: no coverage Vector2D mousePosition = -Vector2D.One; new Command(position => { mousePosition = position; }).Add( new MouseHoldTrigger(Rectangle.HalfCentered)); SetMouseState(State.Pressing, Vector2D.Half); SetMouseState(State.Pressed, Vector2D.Half); AdvanceTimeAndUpdateEntities(0.5f); SetMouseState(State.Pressed, new Vector2D(0.6f, 0.6f)); AdvanceTimeAndUpdateEntities(0.5f); Assert.AreEqual(Vector2D.Half, mousePosition); }
[Test, CloseAfterFirstFrame, Category("Slow")] public void HoldMouseInsideHoldArea() { if (mouse == null) return; //ncrunch: no coverage Vector2D mousePosition = -Vector2D.One; new Command(position => { mousePosition = position; }).Add( new MouseHoldTrigger(Rectangle.HalfCentered)); SetMouseState(State.Pressing, Vector2D.Half); SetMouseState(State.Pressed, Vector2D.Half); AdvanceTimeAndUpdateEntities(1.05f); Assert.AreEqual(Vector2D.Half, mousePosition); }
See Also