public string execute(string[] args) { StringBuilder result = new StringBuilder(); DateTime startTime, bedTime, endTime; if (args.Length != 3 || !DateTime.TryParse(args[0], out startTime) || !DateTime.TryParse(args[1], out bedTime) || !DateTime.TryParse(args[2], out endTime) ) { result.AppendLine("Bad arguments.") .AppendLine(help()); return(result.ToString()); } Decimal salary = new Decimal(0); var calculator = new BabysitterWageCalculator(); try { salary = calculator.calculate(startTime, bedTime, endTime); result.Append(string.Format("Your salary is {0}", salary)); } catch (ArgumentOutOfRangeException) { result.AppendLine(MSG_BAD_TIMELINE).AppendLine(help()); } catch (NotSupportedException e) { result.AppendLine(e.Message).AppendLine(help()); } catch { result.AppendLine("Error.").AppendLine(help()); } return(result.ToString()); }
public string execute(string[] args) { StringBuilder result = new StringBuilder(); DateTime startTime, bedTime, endTime; if (args.Length != 3 || !DateTime.TryParse(args[0], out startTime) || !DateTime.TryParse(args[1], out bedTime) || !DateTime.TryParse(args[2], out endTime) ) { result.AppendLine("Bad arguments.") .AppendLine(help()); return result.ToString(); } Decimal salary = new Decimal(0); var calculator = new BabysitterWageCalculator(); try { salary = calculator.calculate(startTime, bedTime, endTime); result.Append(string.Format("Your salary is {0}", salary)); } catch (ArgumentOutOfRangeException ) { result.AppendLine(MSG_BAD_TIMELINE).AppendLine(help()); } catch (NotSupportedException e) { result.AppendLine(e.Message).AppendLine(help()); } catch { result.AppendLine("Error.").AppendLine(help()); } return result.ToString(); }
public void TestInitialize() { calculator = new BabysitterWageCalculator(); }