Ejemplo n.º 1
0
        public void AddFourTeamsAndMakeOneWinner()
        {
            var tournament = new Tournament("TestTournament");

            tournament.AddTeam("Red");
            tournament.AddTeam("Blue");

            tournament.AddTeam("Green");
            tournament.AddTeam("Yellow");

            tournament.Start();
            tournament.Score(0, 1, 2);
            tournament.Score(1, 3, 2);
            tournament.Score(2, 0, 1);


            Assert.Equal("Red", tournament.Matches[0].Team1);
            Assert.Equal("Blue", tournament.Matches[0].Team2);
            Assert.Equal("Green", tournament.Matches[1].Team1);
            Assert.Equal("Yellow", tournament.Matches[1].Team2);
            Assert.Equal("Blue", tournament.Matches[2].Team1);
            Assert.Equal("Green", tournament.Matches[2].Team2);

            Assert.Equal("Green", tournament.Winner);
        }
Ejemplo n.º 2
0
        public void TestScheduleNewRoundWithOddNumbersOfTeams()
        {
            currentTournament.AddTeam(new Team("The Andals")); // Add the nine'th team
            Assert.AreEqual(9, currentTournament.GetTeams().Count);

            controller.ScheduleNewRound("Vinter Turnering", false);

            Assert.AreEqual(1, currentTournament.GetNumberOfRounds());
            Assert.AreEqual(9, currentTournament.GetTeams().Count);
        }
Ejemplo n.º 3
0
        public void AddTwoTeamsAndMakeOneWinner()
        {
            var tournament = new Tournament("TestTournament");

            tournament.AddTeam("Red");
            tournament.AddTeam("Blue");

            tournament.Start();
            tournament.Score(0, 1, 2);

            Assert.Equal("Red", tournament.Matches[0].Team1);
            Assert.Equal("Blue", tournament.Matches[0].Team2);
            Assert.Equal("Blue", tournament.Winner);
        }
Ejemplo n.º 4
0
        public void TryDrawMatchShouldNotWork()
        {
            var tournament = new Tournament("TestTournament");

            tournament.AddTeam("Red");
            tournament.AddTeam("Blue");

            bool result;

            tournament.Start();

            result = tournament.Score(0, 1, 1);
            Assert.False(result);
        }
Ejemplo n.º 5
0
        public void AddTeam_WhenCalled_ThenOneTeam(Team team)
        {
            var tournament = new Tournament();

            tournament.AddTeam(team);

            tournament.Teams.Count().ShouldBe(1);
        }
Ejemplo n.º 6
0
        public void TryAddTeamsAfterTournamentStartShouldNotWork()
        {
            var  tournament = new Tournament("TestTournament");
            bool result;

            result = tournament.AddTeam("Red");
            Assert.True(result);

            result = tournament.AddTeam("Blue");
            Assert.True(result);

            tournament.Start();

            result = tournament.AddTeam("Green");

            Assert.False(result);
            Assert.Equal(2, tournament.Teams.Count);
        }
Ejemplo n.º 7
0
        public void AddFiveTeamsAndMakeOneWinner()
        {
            var tournament = new Tournament("TestTournament");

            tournament.AddTeam("Red");
            tournament.AddTeam("Blue");

            tournament.AddTeam("Green");
            tournament.AddTeam("Yellow");

            tournament.AddTeam("Purple");

            tournament.Start();
            tournament.Score(0, 1, 2);
            tournament.Score(1, 3, 2);
            tournament.Score(2, 0, 1);
            tournament.Score(3, 0, 4);

            Assert.Equal("Blue", tournament.Winner);
        }
Ejemplo n.º 8
0
 public ActionResult Post([FromBody] string team)
 {
     if (tournament.State == TournamentState.New)
     {
         tournament.AddTeam(team);
         return(Ok());
     }
     else
     {
         return(BadRequest("You can only add teams to a not started Tournament"));
     }
 }
Ejemplo n.º 9
0
        public void AddTeam_Successfull()
        {
            //Arrange
            Tournament testTournament = new Tournament(testDTO, "test");
            string     TeamID         = "1";

            //Act
            var result = testTournament.AddTeam(TeamID);

            //Assert
            Assert.AreEqual(TournamentErrorCode.NoError, result);
        }
Ejemplo n.º 10
0
        public void AddTeam_InputNull()
        {
            //Arrange
            Tournament testTournament = new Tournament(testDTO, "test");
            string     TeamID         = null;

            //Act
            var result = testTournament.AddTeam(TeamID);

            //Assert
            Assert.AreEqual(TournamentErrorCode.CouldntAddTeamToTournament, result);
        }
Ejemplo n.º 11
0
        public void ShowTournamentMenu(Tournament tournament, MenuController control)
        {
            this.control = control;

            Console.WriteLine("Tournament: " + tournament.Name);
            bool       running        = true;
            Tournament openTournament = tournament;

            do
            {
                ShowTournamentMenuOptions();
                string choice = GetUserChoice();

                switch (choice)
                {
                case "0":
                    Console.Clear();
                    running = false;
                    break;

                case "1":
                    AddTeam();
                    break;

                default:
                    Console.WriteLine("Invalid choice");
                    break;
                }
            }while (running == true);

            void AddTeam()
            {
                Console.Clear();
                Console.WriteLine("Choose teams to add:");
                Console.WriteLine();
                control.ShowTeams();

                bool zero = false;

                do
                {
                    string input = Console.ReadLine();

                    if (input == "0")
                    {
                        zero = true;
                    }
                    else
                    {
                        if (int.TryParse(input, out int parsedInput))
                        {
                            control.GetTeam(int.Parse(input));
                            Team team = control.GetTeam(parsedInput);
                            tournament.AddTeam(team);
                        }
                        else
                        {
                            Console.WriteLine("Invalid option");
                        }
                    }
                }while (zero == false);
            }
        }