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());
        }
        public void CanAssignNewTaskTipTest()
        {
            DateTime recalcTime = DateTime.Now;

            Expect.Call(acceptedTipRepository.SaveOrUpdate(null)).IgnoreArguments();

            mocks.ReplayAll();

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

            var teamTaskState = new TeamTaskState { TeamGameState = new TeamGameState { Game = game, Team = team } };

            var tip = new Tip();
            service.AssignNewTaskTip(teamTaskState, tip, recalcTime);

            mocks.VerifyAll();

            Assert.AreEqual(1, teamTaskState.AcceptedTips.Count());
            Assert.AreEqual(recalcTime, teamTaskState.AcceptedTips[0].AcceptTime);
            Assert.AreEqual(tip, teamTaskState.AcceptedTips[0].Tip);
            Assert.AreEqual(teamTaskState, teamTaskState.AcceptedTips[0].TeamTaskState);
        }
        public void TeamFinishGameTest()
        {
            var service = new TaskService(taskRepository, teamTaskStateRepository, acceptedCodeRepository,
                                          acceptedBadCodeRepository, acceptedTipRepository, dispatcherFactory);

            DateTime recalcTime = DateTime.Now;
            var teamGameState = new TeamGameState { Game = game, Team = team };
            service.TeamFinishGame(teamGameState, recalcTime);

            Assert.AreEqual(recalcTime, teamGameState.GameDoneTime);
            Assert.IsNull(teamGameState.ActiveTaskState);
        }
        public void ShouldNotAssignDuodleTipTest()
        {
            DateTime recalcTime = DateTime.Now;

            DoNotExpect.Call(acceptedTipRepository.SaveOrUpdate(null));

            mocks.ReplayAll();

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

            var teamTaskState = new TeamTaskState { TeamGameState = new TeamGameState { Game = game, Team = team } };
            var tip = new Tip { Name = "Tip 0", SuspendTime = 0 };
            teamTaskState.AcceptedTips.Add(new AcceptedTip { Tip = tip });
            service.AssignNewTaskTip(teamTaskState, tip, recalcTime);

            mocks.VerifyAll();

            Assert.AreEqual(1, teamTaskState.AcceptedTips.Count());
        }
        public void CloseTaskForTeamTest()
        {
            var service = new TaskService(taskRepository, teamTaskStateRepository, acceptedCodeRepository,
                                          acceptedBadCodeRepository, acceptedTipRepository, dispatcherFactory);

            DateTime recalcTime = DateTime.Now;
            var teamTaskState = new TeamTaskState { TeamGameState = new TeamGameState { Game = game, Team = team } };
            service.CloseTaskForTeam(teamTaskState, TeamTaskStateFlag.Success, recalcTime);

            Assert.AreEqual(recalcTime, teamTaskState.TaskFinishTime);
            Assert.AreEqual((int)TeamTaskStateFlag.Success, teamTaskState.State);
            Assert.IsNull(teamTaskState.TeamGameState.ActiveTaskState);
            Assert.True(teamTaskState.TeamGameState.AcceptedTasks.Contains(teamTaskState));
        }
        public void CanNotAssignNewTaskTest()
        {
            var service = new TaskService(taskRepository, teamTaskStateRepository, acceptedCodeRepository,
                                          acceptedBadCodeRepository, acceptedTipRepository, dispatcherFactory);

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

            service.AssignNewTask(teamGameState, oldTask, new DateTime(2011, 1, 1, 21, 0, 0));
        }
        public void CanFinishTeamGameTest()
        {
            Expect.Call(dispatcherFactory.CrearteDispatcher(game)).Return(taskDispatcher);
            Expect.Call(taskDispatcher.GetNextTaskForTeam(null, null, null)).Return(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.IsNull(teamGameState.ActiveTaskState);
            Assert.AreEqual(recalcDateTime, teamGameState.GameDoneTime);
            Assert.AreEqual(0, teamGameState.AcceptedTasks.Count());
        }