Ejemplo n.º 1
0
 private IGameDemon GetGameDemon(int gameId)
 {
     if (gameDemon == null)
     {
         gameDemon = GameDemon.GetInstance(new RecalcGameStateService(gameId, gameRepository, this));
     }
     return(gameDemon);
 }
Ejemplo n.º 2
0
        public void CanHandleExceptionTest()
        {
            MockRepository moks = new MockRepository();
            IRecalcGameStateService service = moks.DynamicMock<IRecalcGameStateService>();

            Expect.Call(() => service.RecalcGameState(DateTime.Now))
                .Throw(new Exception("Error"))
                .IgnoreArguments();

            moks.ReplayAll();

            GameDemon demon = new GameDemon(service);
            demon.MinimalRecalcPeriod = 0;
            demon.RecalcGameState(null);

            moks.VerifyAll();
        }
Ejemplo n.º 3
0
        public void CanStartStopTest()
        {
            MockRepository moks = new MockRepository();
            IRecalcGameStateService service = moks.DynamicMock<IRecalcGameStateService>();

            Expect.Call(() => service.RecalcGameState(DateTime.Now))
                .IgnoreArguments();

            moks.ReplayAll();

            GameDemon demon = new GameDemon(service);
            demon.MinimalRecalcPeriod = 0;
            demon.Start();
            Thread.Sleep(1000);
            demon.Stop();

            moks.VerifyAll();
        }
Ejemplo n.º 4
0
        public void CanLockConcurentThreadsTest()
        {
            MockRepository moks = new MockRepository();
            IRecalcGameStateService service = moks.DynamicMock<IRecalcGameStateService>();

            GameDemon demon = new GameDemon(service);
            demon.MinimalRecalcPeriod = 0;

            Expect.Call(() => service.RecalcGameState(DateTime.Now))
                .Do((Action<DateTime>)( dateTime => demon.RecalcGameState(DateTime.Now)))
                .IgnoreArguments();

            moks.ReplayAll();

            demon.RecalcGameState(null);

            moks.VerifyAll();
        }
Ejemplo n.º 5
0
        public void RecalcPeriodTest()
        {
            MockRepository moks = new MockRepository();
            IRecalcGameStateService service = moks.DynamicMock<IRecalcGameStateService>();

            Expect.Call(() => service.RecalcGameState(DateTime.Now))
                .Repeat.Times(1)
                .IgnoreArguments();

            moks.ReplayAll();

            GameDemon demon = new GameDemon(service);
            demon.MinimalRecalcPeriod = 1;
            demon.RecalcGameState(null);
            demon.RecalcGameState(null);

            moks.VerifyAll();
        }