public void CanParseCommand() { //Arrange var cmdStr1 = "Driver Evan"; var cmdStr2 = "Trip James 12:00 14:00 55.8"; //Act Driver parsedCmd1 = (Driver)RootCommandUtil.ParseCommand(cmdStr1, delimiter); Trip parsedCmd2 = (Trip)RootCommandUtil.ParseCommand(cmdStr2, delimiter); //Assert Assert.AreEqual("Evan", parsedCmd1.Name); Assert.AreEqual("James", parsedCmd2.DriverName); Assert.AreEqual(new TimeSpan(12, 0, 0), parsedCmd2.StartTime); Assert.AreEqual(new TimeSpan(14, 0, 0), parsedCmd2.EndTime); Assert.AreEqual(55.8M, parsedCmd2.Distance); }
static void Main(string[] args) { try { #if DEBUG workingDir = Directory.GetParent(Directory.GetParent (Directory.GetCurrentDirectory()).Parent.FullName).FullName; #else workingDir = Directory.GetCurrentDirectory(); #endif #region Initialize Config var builder = new ConfigurationBuilder() .SetBasePath(workingDir) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot config = builder.Build(); #endregion Initialize Config ProgramUtil.ValidateArgs(args, Path.Combine(workingDir, config["inputFolder"])); string inputFilePath = Path.Combine(workingDir, config["inputFolder"], args[0]); Console.WriteLine($"Found input file: {inputFilePath}\n"); Console.WriteLine("Generating Driver Report\n"); List <string> rawInput = ProgramUtil.GetRawInput(inputFilePath); foreach (var s in rawInput) { var cmd = RootCommandUtil.ParseCommand(s, config["delimiter"]); if (cmd.IsValid) { cmds.Add(cmd); } else { invalidCmds.Add(s); } } RootCommandUtil.GroupCommandsByType(cmds, drivers, trips); Driver.CheckForDuplicateDrivers(drivers); trips = Trip.FilterTripsBySpeed(trips); Driver.AssignTripsToDrivers(drivers, trips); reportData = ReportData.PopulateReportData(drivers); ReportData.SortReportDataByMileage(reportData); string outputPath = Path.Combine(workingDir, config["outputFolder"]); ReportData.WriteReport(reportData, outputPath, config["outputFile"]); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } if (invalidCmds.Count > 0) { ProgramUtil.ConsoleColorWriteLine($"!WARNING - INVALID COMMANDS!", ConsoleColor.Yellow); foreach (var cmd in invalidCmds) { ProgramUtil.ConsoleColorWriteLine($"Invalid Command found: {cmd}", ConsoleColor.Yellow); } } ProgramUtil.ConsoleColorWriteLine("COMPLETE!\n", ConsoleColor.Green); Console.WriteLine("Press any key to exit"); Console.ReadLine(); //TODO: log exceptions, log invalid commands? }