#region CPL License /* Nuclex Framework Copyright (C) 2002-2011 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.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using NUnit.Framework; namespace Nuclex.Game.States { /// Unit test for the game state class [TestFixture] internal class DrawableGameStateTest { #region class TestGameState /// Game state used for unit testing private class TestGameState : DrawableGameState { /// Initializes a new test game state public TestGameState() { } /// /// Allows the game state to run logic such as updating the world, /// checking for collisions, gathering input and playing audio. /// /// Provides a snapshot of timing values public override void Update(GameTime gameTime) { } /// This is called when the game state should draw itself /// Provides a snapshot of timing values public override void Draw(GameTime gameTime) { ++this.DrawCallCount; } /// Number of calls to the DraW() method public int DrawCallCount; } #endregion // class TestGameState /// /// Verifies that the constructor of the drawable game state is working /// [Test] public void TestConstructor() { GameState gameState = new TestGameState(); } /// /// Verifies that the Draw() call can be used on the game state /// [Test] public void TestDraw() { var gameState = new TestGameState(); gameState.Draw(new GameTime()); Assert.AreEqual(1, gameState.DrawCallCount); } /// /// Tests whether the Visible property provided via the IDrawable /// interface is returned correctly /// [Test] public void TestVisibleProperty() { IDrawable drawableState = new TestGameState(); Assert.IsTrue(drawableState.Visible); } /// /// Tests whether the DrawOrder property provided via the IDrawable /// interface is returned correctly /// [Test] public void TestDrawOrderProperty() { IDrawable drawableState = new TestGameState(); Assert.AreEqual(0, drawableState.DrawOrder); } /// /// Tests whether the DrawOrderChanged event can be used /// [Test] public void TestDrawOrderChangedEvent() { IDrawable drawableState = new TestGameState(); // There's no point in doing any testing here because the events are // never triggered, thus no exception on this means the part that // needs to be implemented is working right (ie. doing nothing) drawableState.DrawOrderChanged += delegate(object sender, EventArgs arguments) { }; drawableState.DrawOrderChanged -= delegate(object sender, EventArgs arguments) { }; } /// /// Tests whether the VisibleChanged event can be used /// [Test] public void TestVisibleChangedEvent() { IDrawable drawableState = new TestGameState(); // There's no point in doing any testing here because the events are // never triggered, thus no exception on this means the part that // needs to be implemented is working right (ie. doing nothing) drawableState.VisibleChanged += delegate(object sender, EventArgs arguments) { }; drawableState.VisibleChanged -= delegate(object sender, EventArgs arguments) { }; } } } // namespace Nuclex.Game.States #endif // UNITTEST