Пример #1
0
        public void AssignNewTask(TeamGameState teamGameState, Task oldTask, DateTime recalcTime)
        {
            Check.Require(teamGameState.ActiveTaskState == null, "Невозможно назначить команде новую задачу, т.к. коменде уже назначена задача.");

            // Пытаемся получить следующее задание для команды
            Task newTask = dispatcherFactory.CrearteDispatcher(teamGameState.Game)
                           .GetNextTaskForTeam(taskRepository, teamGameState, oldTask);

            // Если нет нового задания, то команда завершила игру
            if (newTask == null)
            {
                TeamFinishGame(teamGameState, recalcTime);
                return;
            }

            TeamTaskState teamTaskState = new TeamTaskState {
                TaskStartTime  = recalcTime,
                TaskFinishTime = null,
                State          = (int)TeamTaskStateFlag.Execute,
                TeamGameState  = teamGameState,
                Task           = newTask,
                NextTask       = null
            };

            teamGameState.ActiveTaskState = teamTaskState;

            teamTaskStateRepository.SaveOrUpdate(teamTaskState);
            //Сразу же отправляем команде первую подсказку (т.е. текст задания)
            AssignNewTaskTip(teamTaskState, teamTaskState.Task.Tips.First(), recalcTime);
        }
Пример #2
0
        public void CanAssignNewTaskTest()
        {
            var newTask = new Task {
                Name = "New task"
            };

            newTask.Tips.Add(new Tip {
                Name = "Tip 0", SuspendTime = 0
            });
            newTask.Tips.Add(new Tip {
                Name = "Tip 1", SuspendTime = 30
            });
            newTask.Tips.Add(new Tip {
                Name = "Tip 2", SuspendTime = 60
            });

            Expect.Call(dispatcherFactory.CrearteDispatcher(game)).Return(taskDispatcher);
            Expect.Call(taskDispatcher.GetNextTaskForTeam(null, null, null)).Return(newTask).IgnoreArguments();
            Expect.Call(teamTaskStateRepository.SaveOrUpdate(null)).IgnoreArguments();
            Expect.Call(acceptedTipRepository.SaveOrUpdate(null)).IgnoreArguments();

            mocks.ReplayAll();

            var service = new TaskService(taskRepository, teamTaskStateRepository, acceptedCodeRepository,
                                          acceptedBadCodeRepository, acceptedTipRepository, dispatcherFactory);

            var teamGameState = new TeamGameState {
                Game = game, Team = team
            };
            var oldTask = new Task {
                Name = "Old task"
            };

            var recalcDateTime = new DateTime(2011, 1, 1, 21, 0, 0);

            service.AssignNewTask(teamGameState, oldTask, recalcDateTime);

            mocks.VerifyAll();

            Assert.AreEqual(newTask, teamGameState.ActiveTaskState.Task);
            Assert.AreEqual(recalcDateTime, teamGameState.ActiveTaskState.TaskStartTime);
            Assert.AreEqual(1, teamGameState.ActiveTaskState.AcceptedTips.Count());
            Assert.AreEqual(0, teamGameState.AcceptedTasks.Count());
        }