ButtonTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    DeltaEngine.Scenes.Tests.Controls ButtonTests

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

public class ButtonTests : TestWithMocksOrVisually

The ButtonTests type exposes the following members.

Constructors

  NameDescription
Public methodButtonTests
Initializes a new instance of the ButtonTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodBeginAndEndClickInside
Public methodBeginClickInside
Public methodBeginClickInsideAndEndOutside
Public methodBeginClickOutside
Public methodBeginClickOutsideAndEndInside
Public methodDefaultNames
Public methodDefaultsToEnabled
Public methodDisabledControlDoesNotRespondToClick
Public methodDrawLoadedButton
Public methodHiddenControlDoesNotRespondToClick
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodLoadFromFile
Public methodLoadSceneWithAButton
Public methodLoadWithoutBinaryDataExtensions
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Public methodRenderButtonAttachedToMouse
Public methodRenderButtonWithRelativePosition
Public methodRenderOneButtonEnablingAndDisablingAnother
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodSaveAndLoad
Public methodSetUp
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test, ApproveFirstFrameScreenshot]
public void RenderButtonWithRelativePosition()
{
    button.Add(new List<FontText>
    {
        new FontText(Font.Default, "", new Rectangle(0.4f, 0.7f, 0.2f, 0.1f))
    });
    button.Start<UpdateTextWithRelativePosition>();
}
[Test]
public void RenderOneButtonEnablingAndDisablingAnother()
{
    var button2 = new Button(Rectangle.FromCenter(0.5f, 0.3f, 0.2f, 0.1f));
    button2.Clicked += () => button.IsEnabled = !button.IsEnabled;
}
[Test, CloseAfterFirstFrame]
public void DefaultsToEnabled()
{
    Assert.IsTrue(button.IsEnabled);
}
[Test, CloseAfterFirstFrame]
public void BeginClickInside()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage
    SetMouseState(State.Pressing, Vector2D.Half);
    Assert.IsTrue(button.State.IsPressed);
}
[Test, CloseAfterFirstFrame]
public void BeginClickOutside()
{
    SetMouseState(State.Pressing, Vector2D.One);
    Assert.IsFalse(button.State.IsPressed);
}
[Test, CloseAfterFirstFrame]
public void BeginAndEndClickInside()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage 
    bool clicked = false;
    button.Clicked += () => clicked = true;
    PressAndReleaseMouse(new Vector2D(0.53f, 0.52f), new Vector2D(0.53f, 0.52f));
    Assert.IsTrue(clicked);
    Assert.IsTrue(button.State.RelativePointerPosition.IsNearlyEqual(new Vector2D(0.6f, 0.7f)));
    Assert.IsFalse(button.State.IsPressed);
}
[Test, CloseAfterFirstFrame]
public void BeginClickInsideAndEndOutside()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage 
    bool clicked = false;
    button.Clicked += () => clicked = true;
    PressAndReleaseMouse(Vector2D.Half, Vector2D.Zero);
    Assert.IsFalse(clicked);
    Assert.IsTrue(button.State.IsPressed);
}
[Test, CloseAfterFirstFrame]
public void BeginClickOutsideAndEndInside()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage 
    bool clicked = false;
    button.Clicked += () => clicked = true;
    PressAndReleaseMouse(Vector2D.Zero, Vector2D.Half);
    Assert.IsFalse(clicked);
    Assert.IsFalse(button.State.IsPressed);
}
[Test, CloseAfterFirstFrame]
public void DisabledControlDoesNotRespondToClick()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage
    button.IsEnabled = false;
    bool clicked = false;
    button.Clicked += () => clicked = true;
    PressAndReleaseMouse(new Vector2D(0.53f, 0.52f), new Vector2D(0.53f, 0.52f));
    Assert.IsFalse(clicked);
    Assert.IsFalse(button.State.IsInside);
    Assert.AreEqual(Vector2D.Zero, button.State.RelativePointerPosition);
}
[Test, CloseAfterFirstFrame]
public void HiddenControlDoesNotRespondToClick()
{
    if (!IsMockResolver)
        return; //ncrunch: no coverage
    button.IsVisible = false;
    bool clicked = false;
    button.Clicked += () => clicked = true;
    PressAndReleaseMouse(new Vector2D(0.53f, 0.52f), new Vector2D(0.53f, 0.52f));
    Assert.IsFalse(clicked);
    Assert.IsFalse(button.State.IsInside);
    Assert.AreEqual(Vector2D.Zero, button.State.RelativePointerPosition);
}
[Test]
public void RenderButtonAttachedToMouse()
{
    new Command(point => button.DrawArea = Rectangle.FromCenter(point, button.DrawArea.Size)).
        Add(new MouseMovementTrigger());
}
[Test, CloseAfterFirstFrame]
public void LoadSceneWithAButton()
{
    var loadedScene = ContentLoader.Load<Scene>("SceneWithAButton");
    CheckSceneWithAButton(loadedScene);
}
[Test, CloseAfterFirstFrame]
public void LoadFromFile()
{
    var loadedScene = ContentLoader.Load<Scene>("SceneWithAButton");
    var newScene = new Scene();
    newScene.LoadFromFile(BinaryDataExtensions.SaveToMemoryStream(loadedScene));
    CheckSceneWithAButton(newScene);
}
[Test, CloseAfterFirstFrame]
public void DefaultNames()
{
    var button2 = new Button(Center, "Click Me");
    Assert.IsTrue(button.Name.StartsWith("Button"));
    Assert.IsTrue(button2.Name.StartsWith("Button"));
    Assert.Greater(int.Parse(button2.Name.Replace("Button", "")),
        int.Parse(button.Name.Replace("Button", "")));
}
[Test, CloseAfterFirstFrame]
public void SaveAndLoad()
{
    button.Name = "New Name";
    var stream = BinaryDataExtensions.SaveToMemoryStream(button);
    var loadedButton = (Button)stream.CreateFromMemoryStream();
    Assert.AreEqual(Center, loadedButton.DrawArea);
    Assert.AreEqual("Click Me", loadedButton.Text);
    Assert.AreEqual("New Name", loadedButton.Name);
}
[Test]
public void DrawLoadedButton()
{
    button.Text = "Original";
    var stream = BinaryDataExtensions.SaveToMemoryStream(button);
    var loadedButton = (Button)stream.CreateFromMemoryStream();
    loadedButton.Text = "Loaded";
    loadedButton.DrawArea = loadedButton.DrawArea.Move(0.0f, 0.15f);
}
[Test, Ignore] //ncrunch: no coverage start 
public void LoadWithoutBinaryDataExtensions()
{
    var stream = BinaryDataExtensions.SaveToMemoryStream(button);
    button.Text = "Original";
    var loadedButton = new Button();
    loadedButton.LoadFromStream(stream);
    Assert.AreEqual(Center, loadedButton.DrawArea);
    Assert.AreEqual("Click Me", loadedButton.Text);
    loadedButton.DrawArea = loadedButton.DrawArea.Move(new Vector2D(0.0f, 0.2f));
}
See Also