#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2009 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
#if UNITTEST
using System;
using System.Runtime.InteropServices;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using NUnit.Framework;
using NMock;
using Nuclex.Input;
using Nuclex.UserInterface.Controls.Desktop;
using Nuclex.UserInterface.Input;
using Is = NMock.Is;
namespace Nuclex.UserInterface.Visuals.Flat.Renderers {
/// Unit Test for the flat option control renderer
[TestFixture]
internal class FlatOptionControlRendererTest : ControlRendererTest {
/// Called before each test is run
[SetUp]
public override void Setup() {
base.Setup();
this.option = new OptionControl();
this.option.Text = "Option";
this.option.Bounds = new UniRectangle(10, 10, 100, 50);
Screen.Desktop.Children.Add(this.option);
this.renderer = new FlatOptionControlRenderer();
}
///
/// Verifies that the option control renderer can render disabled options
///
[Test]
public void TestRenderDisabled() {
this.option.Enabled = false;
drawAndExpectState("off.disabled");
this.option.Selected = true;
drawAndExpectState("on.disabled");
}
///
/// Verifies that the option control renderer can render normal options
///
[Test]
public void TestRenderNormal() {
this.option.Enabled = true;
drawAndExpectState("off.normal");
this.option.Selected = true;
drawAndExpectState("on.normal");
}
///
/// Verifies that the option control renderer can render highlighted options
///
[Test]
public void TestRenderHighlighted() {
Screen.InjectMouseMove(15.0f, 15.0f); // Move the mouse cursor over the option
drawAndExpectState("off.highlighted");
this.option.Selected = true;
drawAndExpectState("on.highlighted");
}
///
/// Verifies that the option control renderer can render depressed options
///
[Test]
public void TestRenderDepressed() {
// Move the mouse cursor over the option and press it
Screen.InjectMouseMove(15.0f, 15.0f);
Screen.InjectMousePress(MouseButtons.Left);
drawAndExpectState("off.depressed");
this.option.Selected = true;
drawAndExpectState("on.depressed");
}
///
/// Lets the renderer draw the option control and verifies that the option used
/// the skin elements from the expected state
///
///
/// Expected state the skin elements should be using
///
private void drawAndExpectState(string expectedState) {
// Make sure the renderer draws at least a frame and the option's text
MockedGraphics.Expects.One.Method(m => m.DrawElement(null, RectangleF.Empty)).With(
Is.StringContaining(expectedState), Is.Anything
);
MockedGraphics.Expects.One.Method(m => m.DrawString(null, RectangleF.Empty, null)).With(
Is.StringContaining(expectedState), Is.Anything, Is.EqualTo("Option")
);
// Let the renderer draw the option into the mocked graphics interface
renderer.Render(this.option, MockedGraphics.MockObject);
// And verify the expected drawing commands were issues
Mockery.VerifyAllExpectationsHaveBeenMet();
}
/// Option control renderer being tested
private FlatOptionControlRenderer renderer;
/// Option control used to test the option control renderer
private OptionControl option;
}
} // namespace Nuclex.UserInterface.Visuals.Flat.Renderers
#endif // UNITTEST