Exemplo n.º 1
0
        public void GivenRunningCompetitonAndSession_WhenDuelIsDecided_ThenCompetitionIsUpdated()
        {
            this.session = SessionFactory.Create(this.competition.Id, this.competitionRepository.Object);
            var duel = this.session.NextDuel();

            var stateService = new OperationChecker(this.competitionRepository.Object);
            var transferService = new DecisionGateway(this.competitionRepository.Object, stateService);
            this.session.MakeDecision(duel, duel.Option1, transferService);

            Assert.AreEqual(1, this.competition.GetWinCount(duel.Option1));
            Assert.AreEqual(1, this.competition.GetLossCount(duel.Option2));
        }
Exemplo n.º 2
0
        public static Session Create(Guid competitionId, IRepository<Competition> competitionRepository)
        {
            var operationChecker = new OperationChecker(competitionRepository);
            if (!operationChecker.IsRunning(competitionId))
            {
                throw new Exception("Cannot create session for non-running competition.");
            }

            var session = new Session(operationChecker)
            {
                CompetitionId = competitionId,
                Schedule = Schedule.Create(competitionRepository.Get(competitionId).GetOptions()),
                Outcomes = new List<Outcome>()
            };

            return session;
        }