Пример #1
0
        public void GetMatchingJudge_MultiplePiobJudges_ReturnsLeastBusyJudge()
        {
            // Test: Four piob judges - piob event should be assigned to the piob judge with the least amount of events in terms of time required

            // Setup here is 2 piob judges and 2 competitors registered for 2 different piob events.
            // Judge 1 (busyJudge) will be set up to already be judging the one event, so Judge 2 (availableJudge)
            // should be selected to judge the other event.
            Contest contest = this.Contest;

            contest.ContestJudges = this.GetContestJudges(contest, Instrument.Bagpipe, Idiom.Piobaireachd, Idiom.Piobaireachd);
            Judge busyJudge      = contest.ContestJudges.First().Judge;
            Judge availableJudge = contest.ContestJudges.Last().Judge;

            contest.Competitors.Add(TestBase.GetFakeCompetitor(1, contest, Grade.FourJunior, Instrument.Bagpipe, Idiom.Piobaireachd));
            contest.Competitors.Add(TestBase.GetFakeCompetitor(2, contest, Grade.FourSenior, Instrument.Bagpipe, Idiom.Piobaireachd));

            // Add the first Piob event to this judge in order to make him busy
            ContestJudge contestJudge   = contest.ContestJudges.Single(x => x.JudgeId == busyJudge.JudgeId);
            SoloEvent    busyJudgeEvent = contest.SoloEvents.Single(x => x.Idiom == Idiom.Piobaireachd && x.Grade == Grade.FourJunior);

            busyJudgeEvent.Judge = busyJudge;

            // This is the event that should get assigned to availableJudge
            SoloEvent availableJudgeEvent = contest.SoloEvents.Single(x => x.Idiom == Idiom.Piobaireachd && x.Grade == Grade.FourSenior);

            // Call the method being tested
            Judge result = this.service.GetMatchingJudge(contest, availableJudgeEvent);

            // Ensure that the judge picked for the event is the available one
            Assert.That(result.JudgeId, Is.EqualTo(availableJudge.JudgeId));
        }
Пример #2
0
        public Judge GetMatchingJudge(Contest contest, SoloEvent soloEvent)
        {
            // Is a judge already set to adjudicate this event?
            if (soloEvent.Judge != null)
            {
                // yes - find the judge
                return(contest.ContestJudges.Single(x => x.SoloEvents.Any(y => y.SoloEventId == soloEvent.SoloEventId)).Judge);
            }

            // Look for judges certified to the event who aren't already set to adjudicate it, selecting the least-busy judge
            ContestJudge contestJudge = contest.ContestJudges
                                        .OrderBy(x => x.SoloEvents.Sum(y => y.DurationMinutes))
                                        .FirstOrDefault(x => x.Judge.Instruments.Contains(soloEvent.Instrument) &&
                                                        x.Judge.Idioms.Contains(soloEvent.Idiom) &&
                                                        !x.SoloEvents.Any(y => y.SoloEventId == soloEvent.SoloEventId));

            if (contestJudge == null)
            {
                // No matching judge found
                throw new InvalidOperationException($"No judge is available to adjudicate event: {soloEvent.ToString()}");
            }

            // We found a judge.  Return him/her.
            return(contestJudge.Judge);
        }