Esempio n. 1
0
        public RoundRobinResult Handle(RoundRobinRequest request)
        {
            List <List <Team> > tournamentList = ConstructTournamentList(request);
            var matchResults = PlayTournament(request, tournamentList);
            var result       = RoundRobinFactory.CreateResult(matchResults, request);

            return(result);
        }
Esempio n. 2
0
        public async Task <IEnumerable <string> > PostAsync()
        {
            var    bodyRequest = Request.Body;
            string streamresult;

            using (StreamReader reader = new StreamReader(bodyRequest, Encoding.UTF8))
            {
                streamresult = await reader.ReadToEndAsync();
            }
            var jsonObjects        = JObject.Parse(streamresult);
            var teams              = jsonObjects["teams"].ToObject <List <Team> >();
            var historyLeagueStats = jsonObjects["historyleaguestats"].ToObject <HistoryLeagueStats>();
            var request            = RoundRobinFactory.CreateRoundRobinRequest(teams.ToList(), historyLeagueStats);
            var result             = _RRSelector.Handle(request);


            var list = new List <string>();

            foreach (var res in result.matchResults)
            {
                var matchresult = JsonConvert.SerializeObject(res, Formatting.Indented, new JsonSerializerSettings {
                    ContractResolver = JsonContractResolvers.IgnoreIsSpecifiedMembersResolver, MaxDepth = 10
                });
                list.Add(matchresult);
            }
            foreach (var compscore in result.competitionScore)
            {
                var competitionscore = JsonConvert.SerializeObject(compscore, Formatting.Indented, new JsonSerializerSettings {
                    ContractResolver = JsonContractResolvers.IgnoreIsSpecifiedMembersResolver, MaxDepth = 10
                });
                list.Add(competitionscore);
            }


            return(list);
        }
        public void TestLeague()
        {
            Initialize();
            MatchTests.SetupFootballMatchTests(out List <Team> teams, out _, out HistoryLeagueStats leagueStats);


            var request = RoundRobinFactory.CreateRoundRobinRequest(teams.Take(4).ToList(), leagueStats);
            var result  = _RRSelector.Handle(request);

            Assert.IsTrue(result.GetType() == typeof(RoundRobinResult));
            Assert.IsNotNull(result.matchResults);

            #region Round Robin Asserts
            // Round Robin should be the following matchups
            // Round       Match one          Match two
            // Round 1     Team A v.Team D    Team B v.Team C
            // Round 2     Team C v.Team A    Team D v.Team B
            // Round 3     Team A v.Team B    Team C v.Team D

            // Noticed with the switching etc, that round 3 is round 1 and visa versa, but that's ok, all the matchups are still the same
            Team TeamA = request.teams[0];
            Team TeamB = request.teams[1];
            Team TeamC = request.teams[2];
            Team TeamD = request.teams[3];

            // Round 1: Team A v.Team B
            try
            {
                Assert.IsTrue(result.matchResults[0].Scores[TeamA] == 1);
                Assert.IsTrue(result.matchResults[0].Scores[TeamB] == 0);
            }
            catch (KeyNotFoundException)
            {
                Assert.Fail("Round 1 didn't have the correct teams: Team A v.Team B");
            }

            try
            {
                // Round 1: Team C v.Team D
                Assert.IsTrue(result.matchResults[1].Scores[TeamC] == 1);
                Assert.IsTrue(result.matchResults[1].Scores[TeamD] == 0);
            }
            catch (KeyNotFoundException)
            {
                Assert.Fail("Round 1 didn't have the correct teams: Team C v.Team D");
            }

            // Round 2: Team C v.Team A
            try
            {
                Assert.IsTrue(result.matchResults[2].Scores[TeamC] == 1);
                Assert.IsTrue(result.matchResults[2].Scores[TeamA] == 0);
            }
            catch (KeyNotFoundException)
            {
                Assert.Fail("Round 2 didn't have the correct teams: Team C v.Team A");
            }

            // Round 2: Team D v.Team B
            try
            {
                Assert.IsTrue(result.matchResults[3].Scores[TeamD] == 1);
                Assert.IsTrue(result.matchResults[3].Scores[TeamB] == 0);
            }
            catch (KeyNotFoundException)
            {
                Assert.Fail("Round 2 didn't have the correct teams: Team D v.Team B");
            }

            // Round 3: Team A v.Team D
            try
            {
                Assert.IsTrue(result.matchResults[4].Scores[TeamA] == 1);
                Assert.IsTrue(result.matchResults[4].Scores[TeamD] == 0);
            }
            catch (KeyNotFoundException)
            {
                Assert.Fail("Round 3 didn't have the correct teams: Team A v.Team D");
            }

            // Round 3: Team B v.Team C
            try
            {
                Assert.IsTrue(result.matchResults[5].Scores[TeamB] == 1);
                Assert.IsTrue(result.matchResults[5].Scores[TeamC] == 0);
            }
            catch (KeyNotFoundException)
            {
                Assert.Fail("Round 3 didn't have the correct teams: Team B v.Team C");
            }
            #endregion


            Assert.IsTrue(result.matchResults[0].winRemarks.Name == "NoRemarks");
        }