public ICalendarPeriod DeriveCalendarPeriod(ICalendarPeriod calendarPeriod) { try { string delimiter = "/"; string[] splitMonthYearString = calendarPeriod.Period.Split(delimiter); string month = splitMonthYearString[0]; string year = splitMonthYearString[1]; if (month.Length > 2) { throw new ArgumentOutOfRangeException(nameof(calendarPeriod.Period), $"You are passing more than two characters for the month value your date string is: {calendarPeriod.Period}"); } if (year.Length != 4) { throw new ArgumentOutOfRangeException(nameof(calendarPeriod.Period), $"You are passing wrong number of characters for the year value your date string is: {calendarPeriod.Period}"); } if (month.StartsWith('0') == true) { month = month.Substring(1, 1); } return(new CalendarPeriod { Period = $"{month}{delimiter}{year}" }); } catch (NullReferenceException) { throw new NullReferenceException(calendarPeriod.Period); } }
public DeriveCalendarPeriodSteps() { _baseUrl = "https://amtcalculator.azurewebsites.net/"; _endPointService = "api/GasbCalculator/DeriveCalendarPeriod"; _calendarPeriod = new CalendarPeriod(); _calendarResult = new CalendarPeriod(); _amtErrorMessage = new AMTErrorMessage(); }
public static bool IsChronologyValid(this ICalendarPeriod @this) { if (@this.EndDate == null) { return(true); } return(@this.StartDate <= @this.EndDate.Value); }
public async System.Threading.Tasks.Task WhenIPostTheDataToAPIAsync() { using var httpClient = new HttpClient(); StringContent content = new StringContent(JsonConvert.SerializeObject(_calendarPeriod), Encoding.UTF8, "application/json"); using var response = await httpClient.PostAsync(_baseUrl + _endPointService, content); string apiResponse = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { _calendarResult = JsonConvert.DeserializeObject <CalendarPeriod>(apiResponse); } else { _amtErrorMessage = JsonConvert.DeserializeObject <AMTErrorMessage>(apiResponse); } }
public static bool OverlapsRight(this ICalendarPeriod item, ICalendarPeriod other) { return(item.StartDate >= other.StartDate && (other.EndDate == null || other.EndDate.Value >= item.StartDate)); }
public static bool Contains(this ICalendarPeriod item, ICalendarPeriod other) { return((item.StartDate <= other.StartDate) && (item.EndDate == null || (other.EndDate.HasValue && item.EndDate.Value >= other.EndDate.Value))); }
public void Setup() { _baseCalculatorService = new BaseCalculatorService(); _calendarPeriod = new CalendarPeriod(); }