public void TestSeason() { //I am assuming good inoput so not testing for all possible handling of bad input... //Test an empty Season Season season = new Season(); Assert.AreEqual(0, season.Teams.Count); Assert.AreEqual(0, season.Matches.Count); //Add a match season.AddMatch("team1 3, team2 3"); Assert.AreEqual(2, season.Teams.Count); Assert.AreEqual(1, season.Matches.Count); //add another match with an existing team and a new team season.AddMatch("team1 2, team3 3"); Assert.AreEqual(3, season.Teams.Count); Assert.AreEqual(2, season.Matches.Count); //add another match with both existing season.AddMatch("team1 2, team2 2"); Assert.AreEqual(3, season.Teams.Count); Assert.AreEqual(3, season.Matches.Count); }
static void Main(string[] args) { // if args are invalid print an error and exit if (!isArgsValid(args)) { return; } string inputFilePath = args[0]; //open our file and read it line by line StreamReader fileReader; try { fileReader = new StreamReader(inputFilePath); } catch (Exception exc) { //file connection problem, throw error and exit Console.WriteLine("File connection error: " + exc.Message); Console.WriteLine("Please use a valid input file path as the parameter"); return; } //set up our season Season thisSeason = new Season(); //now read the file line by line string matchData; while ((matchData = fileReader.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(matchData)) { thisSeason.AddMatch(matchData); } } //output to a file if we have a second argument int index = 0; if (args.Length == 2) { using (StreamWriter file = new StreamWriter(args[1], false)) { foreach (Team t in thisSeason.Teams) { file.WriteLine((index + 1).ToString() + ". " + t.ToString()); index++; } } } //output to the console index = 0; foreach (Team t in thisSeason.Teams) { Console.WriteLine((index + 1).ToString() + ". " + t.ToString()); index++; } }