/// <summary>
        /// If you need to communicate to multiple databases, you'd add a line to this method to
        /// initialize the other database as well.
        /// </summary>
        private void InitializeNHibernateSession()
        {
            NHibernateSession.ConfigurationCache = new NHibernateConfigurationFileCache(
                new string[] { "Beavers.Encounter.Core" });
            NHibernateSession.Init(
                webSessionStorage,
                new string[] { Server.MapPath("~/bin/Beavers.Encounter.Data.dll") },
                new AutoPersistenceModelGenerator().Generate(),
                Server.MapPath("~/NHibernate.config"));

            Repository<Game> gameRepository = new Repository<Game>();
            foreach (var game in gameRepository.GetAll().Where(x => x.GameState == GameStates.Started))
            {
                var sl = ServiceLocator.Current.GetInstance<IServiceLocator>();
                var taskService = sl.GetInstance<ITaskService>();
                var teamGameStateRepository = sl.GetInstance<IRepository<TeamGameState>>();

                var gameService = new GameService(gameRepository, teamGameStateRepository, taskService);

                var demon = GameDemon.GetInstance(new RecalcGameStateService(
                    game.Id, gameRepository, gameService));
                demon.Start();
            }
        }
        public void CanStopGameTest()
        {
            IGameDemon gameDemon = mocks.DynamicMock<IGameDemon>();
            GameService gameService = new GameService(gameRepository,
                teamRepository, teamGameStateRepository, taskService, gameDemon);

            Game game = new Game { GameState = GameStates.Started };
            Team team = new Team()
                .CreateTeamGameState(game)
                .AssignTask(task1, new DateTime(2010, 1, 1, 21, 0, 0));

            Expect.Call(gameDemon.Stop);
            Expect.Call(gameRepository.SaveOrUpdate(game));
            Expect.Call(
                () => taskService.CloseTaskForTeam(
                    team.TeamGameState.ActiveTaskState,
                    TeamTaskStateFlag.Overtime));
            Expect.Call(teamRepository.SaveOrUpdate(team));
            Expect.Call(teamGameStateRepository.SaveOrUpdate(team.TeamGameState));
            Expect.Call(teamGameStateRepository.DbContext).Return(dbContext);

            mocks.ReplayAll();

            gameService.StopGame(game);

            mocks.VerifyAll();

            Assert.AreEqual(GameStates.Finished, game.GameState);
        }
        public void SetUp()
        {
            mocks = new MockRepository();
            taskService = mocks.DynamicMock<ITaskService>();
            gameRepository = mocks.DynamicMock<IRepository<Game>>();
            teamRepository = mocks.DynamicMock<IRepository<Team>>();
            teamGameStateRepository = mocks.DynamicMock<IRepository<TeamGameState>>();
            dbContext = mocks.DynamicMock<IDbContext>();

            task1 = new Task();
            task1Tip0 = new Tip { SuspendTime = 0, Task = task1 };
            task1Tip1 = new Tip { SuspendTime = 30, Task = task1 };
            task1Tip2 = new Tip { SuspendTime = 60, Task = task1 };
            task1.Tips.Add(task1Tip0);
            task1.Tips.Add(task1Tip1);
            task1.Tips.Add(task1Tip2);
            task1.Codes.Add(new Code { Name = "1", Task = task1 });

            service = new GameService(gameRepository, teamRepository, teamGameStateRepository, taskService);
        }
        public void CanStartGameTest()
        {
            IGameDemon gameDemon = mocks.DynamicMock<IGameDemon>();
            GameService gameService = new GameService(gameRepository,
                teamRepository, teamGameStateRepository, taskService, gameDemon);

            Game game = new Game { GameState = GameStates.Startup };

            Expect.Call(gameRepository.SaveOrUpdate(game));
            Expect.Call(gameDemon.Start);

            mocks.ReplayAll();

            gameService.StartGame(game);

            mocks.VerifyAll();

            Assert.AreEqual(GameStates.Started, game.GameState);
        }