public HttpResponseMessage Get(string id, Frequency frequency, int day, decimal time, RunStatus lastRunStatus, int depth) { var trace = new GenericLoggingService("Details"); try { var calculator = new DateCalculator(DateTime.UtcNow, trace); var nextRunDate = calculator.Calculate(frequency, day, time, lastRunStatus, depth); if (!nextRunDate.HasValue) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new SchedulingResult { Message = "Unable to Calculate Next Run Date, ensure you have specified valid scheduling attributes" })); } return(Request.CreateResponse(HttpStatusCode.OK, new SchedulingResult { NextRunDate = nextRunDate.Value.UtcDateTime })); } catch (Exception exp) { var message = $"Error calculating next run date. {exp.Message}"; trace.Trace(TraceEventType.Error, (int)EventId.ScheduleApiError, message, exp); return(Request.CreateResponse(HttpStatusCode.InternalServerError, new SchedulingResult { Message = message })); } }
public void Calculate_DateDifferenceCorrectly_When_DatesAreCorrect(string date1, string date2, int difference) { var dateCalculator = new DateCalculator(); var calculatedDifference = dateCalculator.Calculate(date1, date2); Assert.Equal(difference, calculatedDifference); }
public void Calculate_ThrowsError_When_DateIsIncorrectFormat(string date1, string date2) { var dateCalculator = new DateCalculator(); Assert.Throws <ArgumentException>(() => dateCalculator.Calculate(date1, date2)); }