public void ReplaceRunJudgings_OneEmptyScoringLastOfTwoJudges_NoException() { var dbMock = DatabaseFaker.GetFake(); var db = dbMock.Object; var target = new TournamentJudgeController(null, db, new Mock <NaHub>().Object); var tourney = Factory.CreateStartedTournament(2, 1, 2).WithJudgingCriteria(2).WithJudges(2); db.AddTournament(tourney); var model = new JudgeViewModel(); model.Tournament = tourney; model.Contestants = new List <ContestantRunViewModel>(); // Setup input var contestants = tourney.GetRoundNo(1).ContestantEntries.ToList(); var c1 = new ContestantRunViewModel(); c1.RoundContestantId = contestants[0].Id; c1.TournamentId = tourney.Id; c1.Scores = new List <RunJudging>() { new RunJudging() { JudgeId = 1, CriterionId = 1, RoundContestantId = c1.RoundContestantId, Score = null }, new RunJudging() { JudgeId = 1, CriterionId = 2, RoundContestantId = c1.RoundContestantId, Score = null }, new RunJudging() { JudgeId = 2, CriterionId = 1, RoundContestantId = c1.RoundContestantId, Score = null }, new RunJudging() { JudgeId = 2, CriterionId = 2, RoundContestantId = c1.RoundContestantId, Score = null } }; model.Contestants.Add(c1); // Setup GetRoundContestant to return from tourney-bound object dbMock.Setup(p => p.GetRoundContestantGuarded(It.IsAny <long>())) .Returns <long>(id => contestants.FirstOrDefault(p => p.Id == id)); foreach (var rj in c1.Scores) { contestants[0].RunJudgings.Add(rj); // This will normally be taken care of by Enitity Framework. Not so in mocked context. } // Act & Assert target.JudgeIndex(model); }
public void IT_PostRunJudgingsFromWeb_FinalizingJudgementOfOneContestant() { long?id = null; try { var scores = new ContestantRunViewModel(); var wrappedScores = new JudgeViewModel(); // Setup/Act using (var db = new NordicArenaDataContext()) { var tourney = Factory.CreateInitializedTourney(); tourney.Contestants.Add(new Contestant("Roger")); tourney.Contestants.Add(new Contestant("Hans")); var judge = new Judge("Dommer"); judge.Tournament = tourney; db.Judges.Add(judge); db.Tournaments.Add(tourney); db.SaveChanges(); tourney = db.Tournaments.FirstOrDefault(p => p.Id == tourney.Id); tourney.Start(); db.SaveChanges(); id = tourney.Id; var round1 = tourney.Rounds.FirstOrDefault(); round1.RunsPerContestant = 1; var rc1 = round1.ContestantEntries.FirstOrDefault(); var critList = tourney.JudgingCriteria.ToList(); // Set up scores scores.RoundContestantId = rc1.Id; scores.TournamentId = tourney.Id; for (int i = 0; i < critList.Count; i++) { var score = new RunJudging(); score.CriterionId = critList[i].Id; score.JudgeId = judge.Id; score.RoundContestantId = rc1.Id; score.RunNo = 1; score.Score = (i + 1); scores.Scores.Add(score); } wrappedScores.Contestants = new List <ContestantRunViewModel>(); wrappedScores.Contestants.Add(scores); wrappedScores.Tournament = tourney; } // Act var ctrl = new TournamentJudgeController(null, new EfTournamentService(), ServiceFaker.GetFakeSignalRHub()); ctrl.JudgeIndex(wrappedScores); // Assert using (var db = new EfTournamentService()) { var rc = db.GetRoundContestantGuarded(scores.RoundContestantId); Assert.IsTrue(rc.TotalScore.HasValue); } } catch (DbEntityValidationException exc) { throw DbValidationExceptionWrapper.Wrap(exc); } finally { DatabaseHelper.DeleteTournament(id); ServiceFaker.ResetIocContainer(); } }