Example #1
0
        public Program(IDocumentSession documentSession)
        {
            var competitionRespository = new RavenRepository<Competition>(documentSession);
            var sessionRepository = new RavenRepository<Session>(documentSession);

            this.UnitOfWork = new RavenUnitOfWork(documentSession, competitionRespository, sessionRepository);

            this.OperationChecker = new OperationChecker(competitionRespository);
            this.CompetitionService = new CompetitionService(this.UnitOfWork);
            this.SessionService = new SessionService(this.UnitOfWork);
        }
Example #2
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));
        }
Example #3
0
        public bool MakeDecision(Guid sessionId, Decision decision)
        {
            var session = Get(sessionId);
            if (session == null) return false;
            if (session.IsClosed) return false;

            var operationChecker = new OperationChecker(this.competitionRepository);
            var gateway = new DecisionGateway(this.competitionRepository, operationChecker);
            session.RegisterDecision(decision, gateway);

            this.unitOfWork.Commit();
            return true;
        }
Example #4
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;
        }