Example #1
0
        private void CreateTestData()
        {
            string message;
            bool   createTestData;

            if (DataAlreadyExist(out message))
            {
                Console.WriteLine("-------------------------");
                Console.WriteLine(message);
                Console.WriteLine("-------------------------");
                AskFor(out createTestData, "Do you want to continue?");
                if (!createTestData)
                {
                    return;
                }

                bool replaceData;
                AskFor(out replaceData, "Do you want to replace or add to existing data?", ConsoleKey.R, ConsoleKey.A, false);
                if (replaceData)
                {
                    RemoveCurrentData();
                }
            }
            else
            {
                createTestData = true;
                Console.WriteLine("-------------------------");
                Console.WriteLine(message);
                Console.WriteLine("-------------------------");
            }

            if (createTestData)
            {
                int maxInputAttempts  = DefaultMaxInputAttempts,
                    maxNumberOfSeries = 20,
                    inputAttempts     = 0;
                uint numberOfSeries   = 0;
                Console.WriteLine($"Create test data.\nMaximum number of series to create: {maxNumberOfSeries}.\nEnter '0' to abort.");

                while (inputAttempts < maxInputAttempts)
                {
                    AskFor(out numberOfSeries, "Enter the number of series that you want to create: ");
                    if (0 < numberOfSeries && numberOfSeries <= maxNumberOfSeries)
                    {
                        break;
                    }
                    if (numberOfSeries == 0)
                    {
                        Console.WriteLine("Creating test data was aborted.");
                        inputAttempts = maxInputAttempts;
                        break;
                    }
                    if (numberOfSeries > maxNumberOfSeries)
                    {
                        Console.WriteLine("Will not create that many series. Try again.");
                        inputAttempts++;
                    }
                }
                if (inputAttempts == maxInputAttempts)
                {
                    Console.WriteLine("No test data was created. Returning to main menu.\nPress any key to continue...");
                    Console.ReadKey();
                    return;
                }

                int playerCounter = 1,
                    teamCounter   = 1;

                List <Player> players = new List <Player>();
                List <Team>   teams   = new List <Team>();
                List <Match>  matches = new List <Match>();
                List <Serie>  series  = new List <Serie>();

                for (int s = 0; s < numberOfSeries; s++)
                {
                    List <List <Player> > playerLists = new List <List <Player> >();
                    List <Team>           teamList    = new List <Team>();
                    List <Match>          matchList   = new List <Match>();

                    for (int t = 0; t < 16; t++)
                    {
                        int amount = _Random.Next(24, 31);
                        playerLists.Add(PlayerFactory.CreateListOfPlayerLists(amount, playerCounter));
                        playerCounter += amount;
                    }
                    teamList     = TeamFactory.CreateTeamsAndSetPlayersTeamId(playerLists, teamCounter);
                    teamCounter += Serie.NumberOfTeams;

                    matchList = MatchTableFactory.CreateMatchTable(teamList,
                                                                   GetRandomDate(DateTime.Now, DateTime.Now.AddYears(2)));

                    Serie serie = new Serie(new GeneralName($"Serie-{s + 1}"), teamList.Select(team => team.Id).ToHashSet(),
                                            matchList.Select(match => match.Id).ToHashSet());

                    foreach (Team team in teamList)
                    {
                        team.SerieIds.Add(serie.Id);
                    }

                    foreach (List <Player> playerList in playerLists)
                    {
                        players.AddRange(playerList);
                    }

                    teams.AddRange(teamList);
                    matches.AddRange(matchList);
                    series.Add(serie);
                }

                SaveTestData(players, teams, matches, series);
            }
        }
 private List <Team> GetValidTeamList()
 {
     return(TeamFactory.CreateTeamsAndSetPlayersTeamId(GetValidListOfPlayerLists(), TeamFactory.MinTeamNameStartValue));
 }