Ejemplo n.º 1
0
        public void OnRenderForGamesShouldBeCalledWhenPlatformAndGameIsInRunState()
        {
            var platform = new FakePlatform();
            var objectFactoryMock = new Mock<IObjectFactory>();
            var assetLoaderServiceMock = new Mock<IAssetLoaderService>();
            var runtime = new Core.Runtime(platform, objectFactoryMock.Object, assetLoaderServiceMock.Object, null);
            var displayMock = new Mock<IDisplay>();
            var gameMock = new Mock<Game>();
            var onRenderCalled = false;

            gameMock.Expect(g => g.OnRender()).Callback(() => onRenderCalled = true);
            runtime.RegisterGame(displayMock.Object, gameMock.Object);
            platform.ChangeState(PlatformState.Run);
            gameMock.Object.ChangeState(ActorState.Run);
            ((FakeDisplayDevice)platform.DisplayDevice).FireRenderEvent(displayMock.Object);
            Assert.That(onRenderCalled, Is.True);
        }
Ejemplo n.º 2
0
        private static void EventShouldBeCalledForStateDuringRegistration(Expression<Action<Game>> eventExpression, PlatformState state, bool changeStateFirst)
        {
            var eventCalled = false;
            var stateChanged = false;
            var platform = new FakePlatform();
            var objectFactoryMock = new Mock<IObjectFactory>();

            platform.StateChanged +=
                (p, s) =>
                {
                    if (s == state)
                    {
                        stateChanged = true;
                    }
                };

            var gameMock = new Mock<Game>();
            gameMock.Expect(g => g.OnInitialize());
            gameMock.Expect(g => g.OnBeforeInitialize());
            gameMock.Expect(g => g.OnLoadContent());
            gameMock.Expect(g => g.OnBeforeUpdate());
            gameMock.Expect(g => g.OnUpdate());
            gameMock.Expect(g => g.OnAfterUpdate());
            gameMock.Expect(g => g.OnStopped());
            gameMock.Expect(eventExpression).Callback(

                () =>
                {
                    Assert.That(stateChanged, Is.True);
                    eventCalled = true;
                });

            var assetLoaderServiceMock = new Mock<IAssetLoaderService>();
            var runtime = new Core.Runtime(platform, objectFactoryMock.Object, assetLoaderServiceMock.Object, null);

            if (changeStateFirst)
            {
                platform.ChangeState(state);
            }

            var displayMock = new Mock<IDisplay>();
            runtime.RegisterGame(displayMock.Object, gameMock.Object);

            if (!changeStateFirst)
            {
                platform.ChangeState(state);
            }

            Assert.That(eventCalled, Is.True);
        }
Ejemplo n.º 3
0
        public void OnUpdateForGamesShouldNotBeCalledBeforeGameIsInRunState()
        {
            var platform = new FakePlatform();
            var objectFactoryMock = new Mock<IObjectFactory>();
            var assetLoaderServiceMock = new Mock<IAssetLoaderService>();
            var runtime = new Core.Runtime(platform, objectFactoryMock.Object, assetLoaderServiceMock.Object, null);
            var displayMock = new Mock<IDisplay>();
            var gameMock = new Mock<Game>();
            var onUpdateCalled = false;

            gameMock.Expect(g => g.OnUpdate()).Callback(() => onUpdateCalled = true);

            runtime.RegisterGame(displayMock.Object, gameMock.Object);
            platform.ChangeState(PlatformState.Run);

            ((FakeDisplayDevice)platform.DisplayDevice).FireUpdateEvent(displayMock.Object);
            if (onUpdateCalled)
            {
                Assert.That(gameMock.Object.State, Is.EqualTo(ActorState.Run));
            }
        }