public void TestGraphicsDeviceServiceEvents() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService(); Mock <IGraphicsDeviceServiceSubscriber> mockedSubscriber = mockSubscriber(mock); mockedSubscriber.Expects.One.Method( m => m.DeviceCreated(null, null) ).WithAnyArguments(); using (IDisposable keeper = mock.CreateDevice()) { this.mockery.VerifyAllExpectationsHaveBeenMet(); mockedSubscriber.Expects.One.Method( m => m.DeviceResetting(null, null) ).WithAnyArguments(); mockedSubscriber.Expects.One.Method( m => m.DeviceReset(null, null) ).WithAnyArguments(); mock.ResetDevice(); this.mockery.VerifyAllExpectationsHaveBeenMet(); mockedSubscriber.Expects.One.Method( m => m.DeviceDisposing(null, null) ).WithAnyArguments(); } this.mockery.VerifyAllExpectationsHaveBeenMet(); }
public void TestContentAccess() { using(XnaGame game = new XnaGame()) { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(service.CreateDevice()) { game.Services.AddService(typeof(IGraphicsDeviceService), service); string assetPath = writeBytesToTempFile( Resources.UnitTestResources.UnitTestEffect ); try { game.Content.RootDirectory = Path.GetDirectoryName(assetPath); string assetName = Path.GetFileNameWithoutExtension(assetPath); SharedGameContentManager adapter = new SharedGameContentManager(game); Effect loadedFromGame = game.Content.Load<Effect>(assetName); Effect loadedFromShared = adapter.Load<Effect>(assetName); Assert.AreSame(loadedFromGame, loadedFromShared); } finally { File.Delete(assetPath); } } // using graphics device } // using game }
public void TestNotSupportedExceptionForReferenceRasterizer() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService( DeviceType.Reference ); mock.DeviceCreated += delegate(object sender, EventArgs arguments) { #if XNA_4 throw new InvalidOperationException("Simulated error for unit testing"); #else throw new NotSupportedException("Simulated error for unit testing"); #endif }; Console.Error.WriteLine( "The next line should contain an error message indicating that the reference " + "rasterizer could not be created" ); #if XNA_4 Assert.Throws <InvalidOperationException>( #else Assert.Throws <NotSupportedException>( #endif delegate() { mock.CreateDevice(); mock.DestroyDevice(); } ); }
public void TestRenderSkybox() { MockedGraphicsDeviceService mockGraphicsDeviceService = new MockedGraphicsDeviceService(DeviceType.Reference); using(IDisposable keeper = mockGraphicsDeviceService.CreateDevice()) { using( BasicEffect effect = new BasicEffect( #if XNA_4 mockGraphicsDeviceService.GraphicsDevice #else mockGraphicsDeviceService.GraphicsDevice, new EffectPool() #endif ) ) { using( SkyboxCube skyboxCube = new SkyboxCube( mockGraphicsDeviceService.GraphicsDevice ) ) { skyboxCube.AssignVertexBuffer(); #if XNA_4 EffectTechnique technique = effect.CurrentTechnique; for(int pass = 0; pass < technique.Passes.Count; ++pass) { technique.Passes[pass].Apply(); skyboxCube.DrawNorthernFace(); skyboxCube.DrawEasternFace(); skyboxCube.DrawSouthernFace(); skyboxCube.DrawWesternFace(); skyboxCube.DrawUpperFace(); skyboxCube.DrawLowerFace(); } #else effect.Begin(); try { EffectTechnique technique = effect.CurrentTechnique; for(int pass = 0; pass < technique.Passes.Count; ++pass) { technique.Passes[pass].Begin(); try { skyboxCube.DrawNorthernFace(); skyboxCube.DrawEasternFace(); skyboxCube.DrawSouthernFace(); skyboxCube.DrawWesternFace(); skyboxCube.DrawUpperFace(); skyboxCube.DrawLowerFace(); } finally { technique.Passes[pass].End(); } } } finally { effect.End(); } #endif } } } }
public void TestRedundantDestroyInvocation() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService(); using (IDisposable keeper = mock.CreateDevice()) { mock.DestroyDevice(); } // should not cause an exception }
public void TestGraphicsDeviceCreation() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService(); using (IDisposable keeper = mock.CreateDevice()) { Assert.IsNotNull(mock.GraphicsDevice); } }
public void TestConstructor() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using(IDisposable context = new BasicEffectDrawContext(service.GraphicsDevice)) { Assert.IsNotNull(context); } } }
public void TestConstructor() { MockedGraphicsDeviceService mockGraphicsDeviceService = new MockedGraphicsDeviceService(); using(IDisposable keeper = mockGraphicsDeviceService.CreateDevice()) { SkyboxCube theSkybox = new SkyboxCube(mockGraphicsDeviceService.GraphicsDevice); theSkybox.Dispose(); } }
public void TestSimpleConstructor() { MockedGraphicsDeviceService mockGraphicsDeviceService = new MockedGraphicsDeviceService(); using(IDisposable keeper = mockGraphicsDeviceService.CreateDevice()) { WaterGrid theGrid = new WaterGrid( mockGraphicsDeviceService.GraphicsDevice, new Vector2(-10.0f, -10.0f), new Vector2(10.0f, 10.0f) ); theGrid.Dispose(); } }
public void TestEqualsWithDifferentObject() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using( BasicEffectDrawContext test1 = new BasicEffectDrawContext(service.GraphicsDevice) ) { using( BasicEffectDrawContext test2 = new BasicEffectDrawContext(service.GraphicsDevice) ) { Assert.IsTrue(test1.Equals((object)test2)); } } } }
public void TestThrowOnInvalidSegmentCountX() { MockedGraphicsDeviceService mockGraphicsDeviceService = new MockedGraphicsDeviceService(); using(IDisposable keeper = mockGraphicsDeviceService.CreateDevice()) { Assert.Throws<ArgumentException>( delegate() { new WaterGrid( mockGraphicsDeviceService.GraphicsDevice, Vector2.Zero, Vector2.Zero, 0, 20 ); } ); } }
public void TestAutomaticGraphicsDeviceDestruction() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService(); try { using (IDisposable keeper = mock.CreateDevice()) { Assert.IsNotNull(mock.GraphicsDevice); throw new ArithmeticException("Test exception"); } } catch (ArithmeticException) { // Munch } Assert.IsNull(mock.GraphicsDevice); }
public void TestGraphicsDeviceServiceEvents() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService(); IGraphicsDeviceServiceSubscriber mockedSubscriber = mockSubscriber(mock); Expect.Once.On(mockedSubscriber).Method("DeviceCreated").WithAnyArguments(); using (IDisposable keeper = mock.CreateDevice()) { this.mockery.VerifyAllExpectationsHaveBeenMet(); Expect.Once.On(mockedSubscriber).Method("DeviceResetting").WithAnyArguments(); Expect.Once.On(mockedSubscriber).Method("DeviceReset").WithAnyArguments(); mock.ResetDevice(); this.mockery.VerifyAllExpectationsHaveBeenMet(); Expect.Once.On(mockedSubscriber).Method("DeviceDisposing").WithAnyArguments(); } this.mockery.VerifyAllExpectationsHaveBeenMet(); }
public void TestExceptionDuringDeviceCreation() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService(); IGraphicsDeviceServiceSubscriber mockedSubscriber = mockSubscriber(mock); Expect.Once.On(mockedSubscriber).Method("DeviceCreated").WithAnyArguments(); mock.DeviceCreated += (DeviceEventHandler) delegate(object sender, EventArgs arguments) { Assert.IsNotNull(mock.GraphicsDevice); throw new ArithmeticException("Test exception"); }; try { mock.CreateDevice(); } catch (ArithmeticException) { // Munch } Assert.IsNull(mock.GraphicsDevice); }
public void TestGraphicsDeviceReset() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using(TestDrawable drawable = new TestDrawable(service)) { Assert.AreEqual(0, drawable.LoadContentFalseCount); Assert.AreEqual(0, drawable.UnloadContentFalseCount); service.ResetDevice(); Assert.AreEqual(1, drawable.LoadContentFalseCount); Assert.AreEqual(1, drawable.UnloadContentFalseCount); } } }
public void TestDummyGraphicsDeviceServiceEvents() { MockedGraphicsDeviceService originalService = new MockedGraphicsDeviceService(); originalService.CreateDevice(); bool deviceExists = true; try { IGraphicsDeviceService dummyService; dummyService = GraphicsDeviceServiceHelper.MakeDummyGraphicsDeviceService( originalService.GraphicsDevice ); IGraphicsDeviceServiceSubscriber mockedSubscriber = mockSubscriber(dummyService); try { Expect.Once.On(mockedSubscriber).Method("DeviceResetting").WithAnyArguments(); Expect.Once.On(mockedSubscriber).Method("DeviceReset").WithAnyArguments(); originalService.ResetDevice(); this.mockery.VerifyAllExpectationsHaveBeenMet(); Expect.Once.On(mockedSubscriber).Method("DeviceDisposing").WithAnyArguments(); deviceExists = false; originalService.DestroyDevice(); this.mockery.VerifyAllExpectationsHaveBeenMet(); } finally { unmockSubscriber(dummyService, mockedSubscriber); } } finally { if(deviceExists) { originalService.DestroyDevice(); } } }
public void TestDummyGraphicsDeviceService() { MockedGraphicsDeviceService originalService = new MockedGraphicsDeviceService(); using(IDisposable keeper = originalService.CreateDevice()) { IGraphicsDeviceService dummyService; dummyService = GraphicsDeviceServiceHelper.MakeDummyGraphicsDeviceService( originalService.GraphicsDevice ); try { Assert.AreSame(originalService.GraphicsDevice, dummyService.GraphicsDevice); } finally { IDisposable disposable = dummyService as IDisposable; if(disposable != null) { disposable.Dispose(); } } } }
public void TestRenderingProperties() { MockedGraphicsDeviceService mockGraphicsDeviceService = new MockedGraphicsDeviceService(); using(IDisposable keeper = mockGraphicsDeviceService.CreateDevice()) { using( WaterGrid theGrid = new WaterGrid( mockGraphicsDeviceService.GraphicsDevice, new Vector2(-10.0f, -10.0f), new Vector2(10.0f, 10.0f), 20, 20 ) ) { #if !XNA_4 Assert.IsNotNull(theGrid.VertexDeclaration); #endif Assert.IsNotNull(theGrid.VertexBuffer); Assert.IsNotNull(theGrid.IndexBuffer); } } }
public void TestStatisticalProperties() { MockedGraphicsDeviceService mockGraphicsDeviceService = new MockedGraphicsDeviceService(); using(IDisposable keeper = mockGraphicsDeviceService.CreateDevice()) { using( WaterGrid theGrid = new WaterGrid( mockGraphicsDeviceService.GraphicsDevice, new Vector2(-10.0f, -10.0f), new Vector2(10.0f, 10.0f), 4, 4 ) ) { Assert.AreEqual(PrimitiveType.TriangleStrip, theGrid.PrimitiveType); Assert.AreEqual(25, theGrid.VertexCount); // 4x4 segments = 5x5 vertices Assert.AreEqual(37, theGrid.IndexCount); // pick a pen & paper and check it... Assert.AreEqual(35, theGrid.PrimitiveCount); // 8 per row, 3 degenerate polys } } }
public void TestConstructor() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { #if XNA_4 using(BasicEffect effect = new BasicEffect(service.GraphicsDevice)) { TestEffectDrawContext test = new TestEffectDrawContext(effect); Assert.GreaterOrEqual(test.Passes, 1); } #else using(EffectPool pool = new EffectPool()) { using(BasicEffect effect = new BasicEffect(service.GraphicsDevice, pool)) { TestEffectDrawContext test = new TestEffectDrawContext(effect); Assert.GreaterOrEqual(test.Passes, 1); } } #endif } }
public void TestEqualsWithIncpmpatibleDrawContext() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { #if XNA_4 using(BasicEffect effect = new BasicEffect(service.GraphicsDevice)) { TestEffectDrawContext test1 = new TestEffectDrawContext(effect); TestDrawContext test2 = new TestDrawContext(); Assert.IsFalse(test1.Equals((object)test2)); } #else using(EffectPool pool = new EffectPool()) { using(BasicEffect effect = new BasicEffect(service.GraphicsDevice, pool)) { TestEffectDrawContext test1 = new TestEffectDrawContext(effect); TestDrawContext test2 = new TestDrawContext(); Assert.IsFalse(test1.Equals((object)test2)); } } #endif } }
public void TestNotSupportedExceptionForReferenceRasterizer() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService( DeviceType.Reference ); mock.DeviceCreated += delegate(object sender, EventArgs arguments) { throw new InvalidOperationException("Simulated error for unit testing"); }; Console.Error.WriteLine( "The next line should contain an error message indicating that the reference " + "rasterizer could not be created" ); Assert.Throws<InvalidOperationException>( delegate() { mock.CreateDevice(); mock.DestroyDevice(); } ); }
public void TestGraphicsDeviceServiceEvents() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService(); Mock<IGraphicsDeviceServiceSubscriber> mockedSubscriber = mockSubscriber(mock); mockedSubscriber.Expects.One.Method( m => m.DeviceCreated(null, null) ).WithAnyArguments(); using(IDisposable keeper = mock.CreateDevice()) { this.mockery.VerifyAllExpectationsHaveBeenMet(); mockedSubscriber.Expects.One.Method( m => m.DeviceResetting(null, null) ).WithAnyArguments(); mockedSubscriber.Expects.One.Method( m => m.DeviceReset(null, null) ).WithAnyArguments(); mock.ResetDevice(); this.mockery.VerifyAllExpectationsHaveBeenMet(); mockedSubscriber.Expects.One.Method( m => m.DeviceDisposing(null, null) ).WithAnyArguments(); } this.mockery.VerifyAllExpectationsHaveBeenMet(); }
public void TestBeginEnd() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { #if XNA_4 using(BasicEffect effect = new BasicEffect(service.GraphicsDevice)) { TestEffectDrawContext test = new TestEffectDrawContext(effect); for(int pass = 0; pass < test.Passes; ++pass) { test.Apply(pass); } } #else using(EffectPool pool = new EffectPool()) { using(BasicEffect effect = new BasicEffect(service.GraphicsDevice, pool)) { TestEffectDrawContext test = new TestEffectDrawContext(effect); test.Begin(); try { for(int pass = 0; pass < test.Passes; ++pass) { test.BeginPass(pass); test.EndPass(); } } finally { test.End(); } } } #endif } }
public void TestEqualsWithIncompatibleEffect() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using( BasicEffectDrawContext test1 = new BasicEffectDrawContext(service.GraphicsDevice) ) { TestEffectDrawContext test2 = new TestEffectDrawContext(null); Assert.IsFalse(test1.Equals((object)test2)); } } }
public void TestEffectRetrieval() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { #if XNA_4 using(BasicEffect effect = new BasicEffect(service.GraphicsDevice)) { TestEffectDrawContext test = new TestEffectDrawContext(effect); Assert.AreSame(effect, test.Effect); } #else using(EffectPool pool = new EffectPool()) { using(BasicEffect effect = new BasicEffect(service.GraphicsDevice, pool)) { TestEffectDrawContext test = new TestEffectDrawContext(effect); Assert.AreSame(effect, test.Effect); } } #endif } }
public void TestGraphicsDeviceServiceEvents() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService(); IGraphicsDeviceServiceSubscriber mockedSubscriber = mockSubscriber(mock); Expect.Once.On(mockedSubscriber).Method("DeviceCreated").WithAnyArguments(); using(IDisposable keeper = mock.CreateDevice()) { this.mockery.VerifyAllExpectationsHaveBeenMet(); Expect.Once.On(mockedSubscriber).Method("DeviceResetting").WithAnyArguments(); Expect.Once.On(mockedSubscriber).Method("DeviceReset").WithAnyArguments(); mock.ResetDevice(); this.mockery.VerifyAllExpectationsHaveBeenMet(); Expect.Once.On(mockedSubscriber).Method("DeviceDisposing").WithAnyArguments(); } this.mockery.VerifyAllExpectationsHaveBeenMet(); }
public void TestRedundantDestroyInvocation() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService(); using(IDisposable keeper = mock.CreateDevice()) { mock.DestroyDevice(); } // should not cause an exception }
public void TestCreateFromServiceProvider() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); GameServiceContainer container = new GameServiceContainer(); container.AddService(typeof(IGraphicsDeviceService), service); using(IDisposable keeper = service.CreateDevice()) { using(Drawable drawable = new TestDrawable(container)) { Assert.AreSame(drawable.GraphicsDevice, service.GraphicsDevice); } } }
public void TestEffectRetrieval() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using( BasicEffectDrawContext test = new BasicEffectDrawContext(service.GraphicsDevice) ) { Assert.AreSame(test.Effect, test.BasicEffect); } } }
public void TestAutomaticGraphicsDeviceDestruction() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService(); try { using(IDisposable keeper = mock.CreateDevice()) { Assert.IsNotNull(mock.GraphicsDevice); throw new ArithmeticException("Test exception"); } } catch(ArithmeticException) { // Munch } Assert.IsNull(mock.GraphicsDevice); }
public void TestGraphicsDeviceCreation() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService(); using(IDisposable keeper = mock.CreateDevice()) { Assert.IsNotNull(mock.GraphicsDevice); } }
public void TestExceptionDuringDeviceCreation() { MockedGraphicsDeviceService mock = new MockedGraphicsDeviceService(); Mock<IGraphicsDeviceServiceSubscriber> mockedSubscriber = mockSubscriber(mock); mockedSubscriber.Expects.One.Method( m => m.DeviceCreated(null, null) ).WithAnyArguments(); mock.DeviceCreated += (DeviceEventHandler)delegate(object sender, EventArgs arguments) { Assert.IsNotNull(mock.GraphicsDevice); throw new ArithmeticException("Test exception"); }; try { mock.CreateDevice(); } catch(ArithmeticException) { // Munch } Assert.IsNull(mock.GraphicsDevice); }
public void TestCreateGraphicsDeviceBeforeConstructor() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using(Drawable drawable = new TestDrawable(service)) { Assert.AreSame(drawable.GraphicsDevice, service.GraphicsDevice); } } }