public void RootMotorVehicleSystem_AddTrip_DriverNotRegistered() { //Arrange var motorVehicleSystem = new RootMotorVehicleSystem(); //Act motorVehicleSystem.AddTrip("Janes", "11:35", "11:45", 234); //Assert //Exception }
public void RootMotorVehicleSystem_RegisterDriver_EmptyString_Throws() { //Arrange var motorVehicleSystem = new RootMotorVehicleSystem(); //Act motorVehicleSystem.RegisterDriver(string.Empty); //Assert //Exception }
public void RootMotorVehicleSystem_RegisterDriver_NameAlreadyExists_Throws() { //Arrange var motorVehicleSystem = new RootMotorVehicleSystem(); motorVehicleSystem.RegisterDriver("Janes"); //Act motorVehicleSystem.RegisterDriver("Janes"); //Assert //Exception }
public void RootMotorVehicleSystem_RegisterNewDriverTest() { //Arrange var motorVehicleSystem = new RootMotorVehicleSystem(); motorVehicleSystem.RegisterDriver("Janes"); //Act bool result = motorVehicleSystem.GetAllDrivers().Any(t => t.Name.Equals("Janes", StringComparison.OrdinalIgnoreCase)); //Assert Assert.IsTrue(result, "Driver Janes should exist"); }
public void RootMotorVehicleSystem_GetListOfDrivers_ExcludeDriversMoreThan100Mph() { //Arrange var motorVehicleSystem = new RootMotorVehicleSystem(); motorVehicleSystem.RegisterDriver("Janes"); //Act motorVehicleSystem.AddTrip("Janes", "11:35", "12:35", 250); //Assert Assert.AreEqual(0, motorVehicleSystem.GetDriversForReport().Count); }
public void RootMotorVehicleSystem_AddTrip_DriverRegistered() { //Arrange var motorVehicleSystem = new RootMotorVehicleSystem(); motorVehicleSystem.RegisterDriver("Janes"); //Act motorVehicleSystem.AddTrip("Janes", "11:35", "11:45", 234); //Assert bool result = motorVehicleSystem.GetAllDrivers().Any(t => t.Name.Equals("Janes", StringComparison.OrdinalIgnoreCase)); Assert.IsTrue(result, "Driver Janes should exist"); }
static void Main(string[] args) { if (!File.Exists(args[0].Trim())) { Console.WriteLine("Cannot find file. Please try again."); Environment.Exit(0); } var motorVehicleSystem = new RootMotorVehicleSystem(); // Processes file line by line. foreach (string line in File.ReadLines(args[0])) { string[] commandString = line.Split(' '); // Space demilited. // Checks if the commands given are valid. if (!IsStringCommandValid(commandString)) { continue; } CommandEnum command; // If command cannot parse to defined command list in the enum, it will skip line. if (!Enum.TryParse(commandString[0], out command)) { continue; } else { try { switch (command) { case CommandEnum.Driver: motorVehicleSystem.RegisterDriver(commandString[1]); break; case CommandEnum.Trip: motorVehicleSystem.AddTrip(commandString[1], commandString[2], commandString[3], double.Parse(commandString[4])); break; } } catch { //Errors encountered will be ignored. continue; } } } // Output report. foreach (IDriver driver in motorVehicleSystem.GetDriversForReport()) { var report = string.Empty; if (driver.GetTotalMiles() == 0) { report = string.Format("{0}: {1} miles", driver.Name, driver.GetTotalMiles()); } else { report = string.Format("{0}: {1} miles @ {2} mph.", driver.Name, driver.GetTotalMiles(), driver.GetAverageSpeed()); } Console.WriteLine(report); } Console.WriteLine(); System.Console.WriteLine("Press <ENTER> to close the console."); System.Console.ReadLine(); }