/// <summary>
        /// Initializes the server and game.
        /// </summary>
        /// <param name="startedCallback">The callback to invoke when initalization is completed.</param>
        public void Initialize(Action<IGame, StandardServer> startedCallback)
        {
            var serverConfig = new ServerConfiguration();
            var server = new StandardServer(new TestPlayerFactory(), new ConnectionFactory());
            server.Configure(serverConfig);
            server.Owner = "@Scionwest";
			this.Server = server;

            var gameConfig = new GameConfiguration();
            gameConfig.UseAdapter(server);

            var game = new MudGame();
            game.Configure(gameConfig);
			this.Game = game;

            game.BeginStart(runningGame => startedCallback(runningGame, server));
        }
Beispiel #2
0
        public async Task BeginStart_with_null_synchronizationcontext_does_not_throw_exception()
        {
            // Arrange
            var configuration = Mock.Of<IGameConfiguration>();
            var game = new MudGame();
            await game.Configure(configuration);

            // We must ensure the synchronization context is null to test that the MudGame creates one itself
            SynchronizationContext.SetSynchronizationContext(null);

            // Act
            var taskCompletionSource = new TaskCompletionSource<bool>();
            game.BeginStart(g => taskCompletionSource.TrySetResult(true));

            bool callbackHit = await taskCompletionSource.Task;

            // Assert
            Assert.IsTrue(callbackHit, "Callback was not hit.");
            Assert.IsTrue(game.IsRunning);
        }
Beispiel #3
0
        public async Task BeginStart_invokes_callback()
        {
            // Arrange
            var configuration = Mock.Of<IGameConfiguration>();
            var game = new MudGame();
            await game.Configure(configuration);
            bool callbackHit = false;

            // We must create a synchronization context as the BeginStart needs one to exist.
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

            // Act
            game.BeginStart(g => callbackHit = true);

            await Task.Delay(100);

            // Assert
            Assert.IsTrue(callbackHit, "Callback was not hit.");
            Assert.IsTrue(game.IsRunning);
        }
Beispiel #4
0
        public async Task Delete_game_will_delete_adapter()
        {
            // Arrange
            var configuration = Mock.Of<IGameConfiguration>(mock => mock.GetAdapters() == new IAdapter[1] { new AdapterFixture() });
            var game = new MudGame();
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            await game.Configure(configuration);

            IAdapter[] adapters = game.Configuration.GetAdapters();

            // Act
            game.BeginStart(async (runningGame) => await game.Delete());
            var timer = new EngineTimer<AdapterFixture>((AdapterFixture)adapters[0]);
            timer.Start(TimeSpan.FromSeconds(20).TotalMilliseconds, 0, 1, (fixture, runningTimer) =>
            {
                runningTimer.Stop();
            });

            while (!((AdapterFixture)adapters[0]).IsDeleted)
            {
                await Task.Delay(1);
                if (!timer.IsRunning)
                {
                    break;
                }
            }

            // Assert
            Assert.IsTrue(((AdapterFixture)adapters[0]).IsDeleted);
        }
Beispiel #5
0
        public async Task Start_game_will_start_adapter()
        {
            // Arrange
            var configuration = Mock.Of<IGameConfiguration>(mock => mock.GetAdapters() == new IAdapter[1] 
            {
                new AdapterFixture()
            });
            var game = new MudGame();
            await game.Configure(configuration);

            IAdapter[] adapter = game.Configuration.GetAdapters();

            // Act
            game.BeginStart(runningGame => { });
            
            while (!game.IsRunning)
            {
                await Task.Delay(1);
            }

            // Assert
            Assert.IsTrue(((AdapterFixture)adapter[0]).IsInitialized);
            Assert.IsTrue(((AdapterFixture)adapter[0]).IsStarted);
        }