public void LoadData(string fileName) { if (this.isDataInitialized) { throw new DataException("Data is already initialized!"); } OutputWriter.DisplayWaitingMessage("Reading data..."); this.courses = new Dictionary <string, ICourse>(); this.students = new Dictionary <string, IStudent>(); this.ReadData(fileName); }
public void CompareContent(string userOutputPath, string expectedOutputPath) { try { OutputWriter.DisplayWaitingMessage("Reading files..."); string mismatchPath = this.GetMismatchPath(expectedOutputPath); string[] actualOutputLines = File.ReadAllLines(userOutputPath); string[] expectedOutputLines = File.ReadAllLines(expectedOutputPath); bool hasMismatch; string[] mismatches = this.GetLinesWithPossibleMismatches(actualOutputLines, expectedOutputLines, out hasMismatch); this.PrintOutput(mismatches, hasMismatch, mismatchPath); OutputWriter.DisplaySuccessfulMessage("Files read!"); } catch (IOException ioException) { OutputWriter.DisplayMessage(ioException.Message); } }
private string[] GetLinesWithPossibleMismatches(string[] actualOutputLines, string[] expectedOutputLines, out bool hasMismatch) { hasMismatch = false; string output = string.Empty; string[] mismatches = new string[actualOutputLines.Length]; OutputWriter.DisplayWaitingMessage("Comparing files..."); int minOutputLines = actualOutputLines.Length; if (actualOutputLines.Length != expectedOutputLines.Length) { hasMismatch = true; minOutputLines = Math.Min(actualOutputLines.Length, expectedOutputLines.Length); OutputWriter.DisplayMessage(ExceptionMessages.ComparisonOfFilesWithDifferentSizes); } for (int i = 0; i < minOutputLines; i++) { string actualLine = actualOutputLines[i]; string expectedLine = expectedOutputLines[i]; if (actualLine != expectedLine) { output = $"Mismatch at line {i} -- expected: \"{expectedLine}\", actual: \"{actualLine}\""; output += Environment.NewLine; hasMismatch = true; } else { output = actualLine; output += Environment.NewLine; } mismatches[i] = output; } return(mismatches); }