#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; using Nuclex.Graphics; using Nuclex.Testing.Xna; using DeviceEventHandler = System.EventHandler; namespace Nuclex.Game { /// Unit test for the drawable component class [TestFixture] internal class GraphicsDeviceGraphicsDeviceDrawableComponentTest { /// Called before each test is run [SetUp] public void Setup() { this.mockedGraphicsDeviceService = new MockedGraphicsDeviceService(); GameServiceContainer services = new GameServiceContainer(); services.AddService( typeof(IGraphicsDeviceService), this.mockedGraphicsDeviceService ); this.testComponent = new GraphicsDeviceDrawableComponent(services); } /// Called after each test has run [TearDown] public void Teardown() { if (this.testComponent != null) { this.testComponent.Dispose(); this.testComponent = null; } if (this.mockedGraphicsDeviceService != null) { this.mockedGraphicsDeviceService.DestroyDevice(); this.mockedGraphicsDeviceService = null; } } /// /// Verifies that the constructor of the drawable component is working /// [Test] public void TestConstructor() { // This should work even without a graphics device service since the services // should only be queried in Initialize() to allow for order-free initialization GraphicsDeviceDrawableComponent testComponent = new GraphicsDeviceDrawableComponent( new GameServiceContainer() ); } /// /// Tests whether the Initialize() method throws an exception if the drawable /// component is initialized without a graphics device service present. /// [Test] public void TestThrowOnInitializeWithoutGraphicsDeviceService() { GraphicsDeviceDrawableComponent testComponent = new GraphicsDeviceDrawableComponent( new GameServiceContainer() ); Assert.Throws( delegate() { testComponent.Initialize(); } ); } /// /// Tests whether the Initialize() method is working when it is called before /// the graphics device has been created /// [Test] public void TestInitializeBeforeGraphicsDeviceCreation() { this.testComponent.Initialize(); Assert.IsNull(testComponent.GraphicsDevice); this.mockedGraphicsDeviceService.CreateDevice(); Assert.AreSame( this.mockedGraphicsDeviceService.GraphicsDevice, this.testComponent.GraphicsDevice ); } /// /// Tests whether the Initialize() method is working when it is called after /// the graphics device has been created /// [Test] public void TestInitializeAfterGraphicsDeviceCreation() { this.mockedGraphicsDeviceService.CreateDevice(); this.testComponent.Initialize(); Assert.AreSame( this.mockedGraphicsDeviceService.GraphicsDevice, this.testComponent.GraphicsDevice ); } /// /// Tests whether the drawable component survives a graphics device reset /// [Test] public void TestGraphicsDeviceReset() { this.mockedGraphicsDeviceService.CreateDevice(); this.testComponent.Initialize(); this.mockedGraphicsDeviceService.ResetDevice(); // No exception means success } /// Component being tested private GraphicsDeviceDrawableComponent testComponent; /// Mock of the graphics device service private MockedGraphicsDeviceService mockedGraphicsDeviceService; } } // namespace Nuclex.Game #endif // UNITTEST