Esempio n. 1
0
        public void ServiceRepoInstanceIsTheSame()
        {
            var service1 = new MatchService();
            var service2 = new MatchService();

            service1.Add(this.match);
            var matchs = service2.GetAll();

            Assert.IsTrue(matchs.Contains(this.match));
        }
Esempio n. 2
0
        public void GetGameFromMatchTest()
        {
            var service      = new GameService();
            var matchService = new MatchService();
            var match        = new Match(new ArenaName("test"), Guid.NewGuid(), Guid.NewGuid(), dummySeries.SeriesDummy);
            var game         = service.GetGameFromMatch(match);

            Assert.IsTrue(game == null);
            matchService.Add(match);
            service.Add(match.Id);
            game = service.GetGameFromMatch(match);
            Assert.IsTrue(game != null);
        }
Esempio n. 3
0
        public void AddGameListTest()
        {
            Match matchOne     = new Match(this.teamRed.ArenaName, this.teamRed.Id, this.teamGreen.Id, this.series, this.date);
            var   gameIsAdded  = false;
            var   matchService = new MatchService();

            matchService.Add(matchOne);
            var gameId = this.gameService.Add(matchOne.Id);

            foreach (var gameItem in this.gameService.GetAll())
            {
                if (gameId == gameItem.Id)
                {
                    gameIsAdded = true;
                }
            }

            Assert.IsTrue(gameIsAdded);
        }
Esempio n. 4
0
        public void AddListOfMatchesTest()
        {
            var series     = new DummySeries();
            var matchOne   = new Match(new ArenaName("ullevi"), Guid.NewGuid(), Guid.NewGuid(), series.SeriesDummy);
            var matchTwo   = new Match(new ArenaName("ullevi"), Guid.NewGuid(), Guid.NewGuid(), series.SeriesDummy);
            var matchThree = new Match(new ArenaName("ullevi"), Guid.NewGuid(), Guid.NewGuid(), series.SeriesDummy);

            var matches = new List <Match>
            {
                matchOne,
                matchTwo
            };

            service.Add(matches);
            var allMatches = DomainService.GetAllMatches();

            Assert.IsTrue(allMatches.Contains(matchOne));
            Assert.IsTrue(allMatches.Contains(matchTwo));
            Assert.IsFalse(allMatches.Contains(matchThree));
        }
Esempio n. 5
0
        private SerializableDictionary <int, MatchWeek> ListMatches(List <Team> listTeam, bool revert)
        {
            if (listTeam.Count % 2 != 0)
            {
                throw new InvalidNumberOfTeamsException("There must be a even nunmber of teams to do this!");
            }

            var numRounds = listTeam.Count - 1;
            var halfSize  = listTeam.Count / 2;

            var teams = new List <Team>();

            teams.AddRange(listTeam.Skip(halfSize).Take(halfSize));
            teams.AddRange(listTeam.Skip(1).Take(halfSize - 1).ToArray().Reverse());

            int teamsSize = teams.Count;

            var rounds = new SerializableDictionary <int, MatchWeek>();

            for (int round = 0; round < numRounds; round++)
            {
                var currentRoundNr = round + 1; // round starts @ index 0, our rounds start at 1

                rounds.Add(currentRoundNr, new MatchWeek());

                var currentRound = rounds[currentRoundNr];

                int teamIdx = round % teamsSize;

                var match = new Match
                {
                    AwayTeamId = teams[teamIdx].Id,
                    HomeTeamId = listTeam[0].Id
                };

                currentRound.MatchIds.Add(match.Id);

                if (revert)
                {
                    match.Swap();
                }

                _matchService.Add(match);


                for (int idx = 1; idx < halfSize; idx++)
                {
                    int firstTeam  = (round + idx) % teamsSize;
                    int secondTeam = (round + teamsSize - idx) % teamsSize;

                    var newMatch = new Match
                    {
                        AwayTeamId = teams[firstTeam].Id,
                        HomeTeamId = teams[secondTeam].Id
                    };
                    currentRound.MatchIds.Add(newMatch.Id);

                    if (revert)
                    {
                        newMatch.Swap();
                    }

                    _matchService.Add(newMatch);
                }
            }

            return(rounds);
        }