public void CheckAppliesForMondayStartOutOfRangeAndEndOutOfRange_ExpectTrue() { //Arrange var longTermRule = new LongStayRule { ActiveDays = new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday }, StartTime = new TimeSpan(0, 0, 0), EndTime = new TimeSpan(23, 59, 59), Increment = new TimeSpan(23, 59, 59), Scheme = ChargingScheme.LongStay, PeriodRate = 7.5m }; var parkingMeter = new ParkingMeter.ParkingMeter(); parkingMeter.ActiveSchemes = new IChargeRule[] { longTermRule }; var entryTime = new DateTime(2020, 5, 21, 07, 30, 0); var exitTime = new DateTime(2020, 5, 23, 16, 30, 0); //Act var parkingCharge = parkingMeter.ProcessParkingCharge(CustomerSelection, entryTime, exitTime); //Assert parkingCharge.Should().Be(longTermRule.PeriodRate * 3); }
public void CheckAppliesForMondayStartOutOfRangeAndEndOutOfRange_ExpectTrue() { //Arrange var shortTermRule = new ShortStayRule { ActiveDays = new[] { DayOfWeek.Monday }, StartTime = new TimeSpan(8, 0, 0), EndTime = new TimeSpan(18, 0, 0), Increment = new TimeSpan(1, 0, 0), Scheme = ChargingScheme.ShortStay, PeriodRate = 1.1m }; var parkingMeter = new ParkingMeter.ParkingMeter(); parkingMeter.ActiveSchemes = new IChargeRule[] { shortTermRule }; var entryTime = new DateTime(2020, 05, 25, 07, 30, 0); var exitTime = new DateTime(2020, 5, 25, 18, 30, 0); //Act var parkingCharge = parkingMeter.ProcessParkingCharge(CustomerSelection, entryTime, exitTime); //Assert parkingCharge.Should().Be(11m); }
static void Main(string[] args) { var parkingMeter = new ParkingMeter(); parkingMeter.ActiveSchemes = new IChargeRule[] { ShortStayRule(), LongStayRule() }; var exampleAEntryTime = new DateTime(2017, 9, 7, 18, 50, 0); var exampleAExitTime = new DateTime(2017, 9, 7, 20, 50, 0); var exampleAResult = parkingMeter.ProcessParkingCharge(ChargingScheme.ShortStay, exampleAEntryTime, exampleAExitTime); Console.WriteLine($"Example A: {exampleAEntryTime} - {exampleAExitTime} incurred a charge of {exampleAResult:C2}"); var exampleBEntryTime = new DateTime(2017, 9, 7, 16, 50, 0); // 07/09/2017 16:50:00 var exampleBExitTime = new DateTime(2017, 9, 9, 19, 15, 0); // 09/09/2017 19:15:00 var exampleBResult = parkingMeter.ProcessParkingCharge(ChargingScheme.ShortStay, exampleBEntryTime, exampleBExitTime); Console.WriteLine($"Example B: {exampleBEntryTime} - {exampleBExitTime} incurred a charge of {exampleBResult:C2}"); var exampleCEntryTime = new DateTime(2017, 9, 7, 7, 50, 0); // 07/09/2017 07:50:00 var exampleCExitTime = new DateTime(2017, 9, 9, 5, 20, 0); // 09/09/2017 05:20:00 var exampleCResult = parkingMeter.ProcessParkingCharge(ChargingScheme.LongStay, exampleCEntryTime, exampleCExitTime); Console.WriteLine($"Example C: {exampleCEntryTime} - {exampleCExitTime} incurred a charge of {exampleCResult:C2}"); }
static void Main(string[] args) { double numHours = 0.5; double timeToAdd = 0.0; double amountCharged = 0.0; bool validMeterTypeEntered = false; bool validTimeEntered = false; string welcomeMessage = "Please enter the type of parking meter in hours. Valid options are .5, 1, 2, 3, and 5"; Console.WriteLine(DateTime.Now.DayOfWeek); Console.WriteLine(welcomeMessage); while (!validMeterTypeEntered) { try { numHours = Double.Parse(Console.ReadLine()); validMeterTypeEntered = true; } catch (FormatException e) { Console.WriteLine("ERROR: Your input was not in the correct format. Please try again\n"); Console.WriteLine(welcomeMessage); } } // Create a generic parking meter based on the user's scenario. Default to half hour parking meter if no input. ParkingMeter meter = new ParkingMeter(numHours); /** * Ask the user how much time they want. * ASSUMPTION: Since problem description did not explicitly state time intervals, will assume 30 minute intervals for simplicity. */ meter.printAddTimePrompt(); // Handle naively, knowing user might add a bad value. String input = Console.ReadLine(); while (!validTimeEntered) { try { timeToAdd = Double.Parse(input); if (timeToAdd > numHours) { Console.WriteLine("You requested more time than is allowed. Defaulting to maximum time."); timeToAdd = numHours * 60; } validTimeEntered = true; } catch (Exception e) { if (input.Equals("max")) { timeToAdd = numHours * 60; validTimeEntered = true; } else { meter.printErrorInAddingTime(); meter.printAddTimePrompt(); } } } /** * Convert the number of minutes to hours charged. * Round to nearest penny. */ amountCharged = Math.Round((((meter.pricePerHour * timeToAdd) / 60) ), 2); DateTime endTime = DateTime.Now.AddMinutes(timeToAdd); if (!meter.isValidTime(endTime.Hour)) { Console.WriteLine("Sorry, this time is outside of working hours..."); Console.WriteLine("Transaction cancelled."); } else { meter.ExpirationTime = endTime; Console.WriteLine("Printing ticket..."); Console.WriteLine("Expiration time: " + meter.ExpirationTime); Console.WriteLine("Amount charged: $" + amountCharged); Console.WriteLine("Minutes purchased: " + timeToAdd); } }