#region CPL License /* Nuclex Framework Copyright (C) 2002-2010 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 button control renderer [TestFixture] internal class FlatButtonControlRendererTest : ControlRendererTest { /// Called before each test is run [SetUp] public override void Setup() { base.Setup(); this.button = new ButtonControl(); this.button.Text = "Test"; this.button.Bounds = new UniRectangle(10, 10, 100, 100); Screen.Desktop.Children.Add(this.button); this.renderer = new FlatButtonControlRenderer(); } /// /// Verifies that the button renderer can render disabled buttons /// [Test] public void TestRenderDisabled() { this.button.Enabled = false; drawAndExpectState("disabled"); } /// /// Verifies that the button renderer can render normal buttons /// [Test] public void TestRenderNormal() { this.button.Enabled = true; drawAndExpectState("normal"); } /// /// Verifies that the button renderer can render highlighted buttons /// [Test] public void TestRenderHighlighted() { Screen.InjectMouseMove(15.0f, 15.0f); // Move the mouse cursor over the button drawAndExpectState("highlighted"); } /// /// Verifies that the button renderer can render depressed buttons /// [Test] public void TestRenderDepressed() { // Move the mouse cursor over the button and press it Screen.InjectMouseMove(15.0f, 15.0f); Screen.InjectMousePress(MouseButtons.Left); drawAndExpectState("depressed"); } /// /// Lets the renderer draw the button and verifies that the button 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 button'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("Test") ); // Let the renderer draw the button into the mocked graphics interface renderer.Render(this.button, MockedGraphics.MockObject); // And verify the expected drawing commands were issues Mockery.VerifyAllExpectationsHaveBeenMet(); } /// Button renderer being tested private FlatButtonControlRenderer renderer; /// Button used to test the button renderer private ButtonControl button; } } // namespace Nuclex.UserInterface.Visuals.Flat.Renderers #endif // UNITTEST