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);
        }
Esempio n. 2
0
        public void Start_sets_is_running()
        {
            // Arrange
            var fixture     = new ComponentFixture();
            var engineTimer = new EngineTimer <ComponentFixture>(fixture);

            // Act
            engineTimer.Start(0, 1, 0, (component, timer) => { });

            // Assert
            Assert.IsTrue(engineTimer.IsRunning, "Engine Timer was not started.");
        }
Esempio n. 3
0
        public void Start_sets_is_running()
        {
            // Arrange
            var fixture = new ComponentFixture();
            var engineTimer = new EngineTimer<ComponentFixture>(fixture);

            // Act
            engineTimer.Start(0, 1, 0, (component, timer) => { });

            // Assert
            Assert.IsTrue(engineTimer.IsRunning, "Engine Timer was not started.");
        }
Esempio n. 4
0
        public async Task Stop_disables_the_timer()
        {
            // Arrange
            var fixture     = new ComponentFixture();
            var engineTimer = new EngineTimer <ComponentFixture>(fixture);

            // Act
            engineTimer.Start(0, 1, 0, (component, timer) => timer.Stop());
            await Task.Delay(20);

            // Assert
            Assert.IsFalse(engineTimer.IsRunning, "Engine Timer was not started.");
        }
Esempio n. 5
0
        public async Task Stop_disables_the_timer()
        {
            // Arrange
            var fixture = new ComponentFixture();
            var engineTimer = new EngineTimer<ComponentFixture>(fixture);

            // Act
            engineTimer.Start(0, 1, 0, (component, timer) => timer.Stop());
            await Task.Delay(20);

            // Assert
            Assert.IsFalse(engineTimer.IsRunning, "Engine Timer was not started.");
        }
Esempio n. 6
0
        public void Callback_invoked_when_running()
        {
            // Arrange
            var  fixture         = new ComponentFixture();
            var  engineTimer     = new EngineTimer <ComponentFixture>(fixture);
            bool callbackInvoked = false;

            // Act
            engineTimer.Start(0, 1, 0, (component, timer) => { callbackInvoked = true; });
            Task.Delay(20);

            // Assert
            Assert.IsTrue(callbackInvoked, "Engine Timer did not invoke the callback as expected.");
        }
Esempio n. 7
0
        public async Task Timer_stops_when_number_of_fires_is_hit()
        {
            // Arrange
            var fixture       = new ComponentFixture();
            var engineTimer   = new EngineTimer <ComponentFixture>(fixture);
            int callbackCount = 0;

            // Act
            engineTimer.Start(0, 1, 2, (component, timer) => { callbackCount += 1; });
            await Task.Delay(TimeSpan.FromSeconds(2));

            // Assert
            Assert.IsFalse(engineTimer.IsRunning, "Timer was not stopped.");
            Assert.AreEqual(2, callbackCount, "Engine Timer did not invoke the callback as expected.");
        }
Esempio n. 8
0
        /// <summary>
        /// Initializes the zone with the supplied realm.
        /// </summary>
        /// <param name="realm">The realm.</param>
        public virtual void Initialize(DefaultRealm realm)
        {
            this.realm = realm;

            if (this.weatherStates.Count > 0)
            {
                // Set up our weather clock and start performing weather changes.
                var weatherClock = new EngineTimer <IWeatherState>(this.CurrentWeather);

                // Convert the minutes specified with WeatherUpdateFrequency to in-game minutes using the GameTimeRatio.
                weatherClock.Start(
                    0,
                    TimeSpan.FromMinutes(this.WeatherUpdateFrequency * this.realm.World.GameTimeAdjustmentFactor).TotalMilliseconds,
                    0,
                    this.SetupWeather);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes the zone with the supplied realm.
        /// </summary>
        /// <param name="realm">The realm.</param>
        public virtual void Initialize(DefaultRealm realm)
        {
            this.realm = realm;

            if (this.weatherStates.Count > 0)
            {
                // Set up our weather clock and start performing weather changes.
                var weatherClock = new EngineTimer<IWeatherState>(this.CurrentWeather);

                // Convert the minutes specified with WeatherUpdateFrequency to in-game minutes using the GameTimeRatio.
                weatherClock.Start(
                    0,
                    TimeSpan.FromMinutes(this.WeatherUpdateFrequency * this.realm.World.GameTimeAdjustmentFactor).TotalMilliseconds,
                    0,
                    this.SetupWeather);
            }
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
        public void Callback_invoked_when_running()
        {
            // Arrange
            var fixture = new ComponentFixture();
            var engineTimer = new EngineTimer<ComponentFixture>(fixture);
            bool callbackInvoked = false;

            // Act
            engineTimer.Start(0, 1, 0, (component, timer) => { callbackInvoked = true; });
            Task.Delay(20);

            // Assert
            Assert.IsTrue(callbackInvoked, "Engine Timer did not invoke the callback as expected.");
        }
Esempio n. 12
0
        public async Task Timer_stops_when_number_of_fires_is_hit()
        {
            // Arrange
            var fixture = new ComponentFixture();
            var engineTimer = new EngineTimer<ComponentFixture>(fixture);
            int callbackCount = 0;

            // Act
            engineTimer.Start(0, 1, 2, (component, timer) => { callbackCount += 1; });
            await Task.Delay(TimeSpan.FromSeconds(2));

            // Assert
            Assert.IsFalse(engineTimer.IsRunning, "Timer was not stopped.");
            Assert.AreEqual(2, callbackCount, "Engine Timer did not invoke the callback as expected.");
        }