public void Ref2NoSymptoms1DayTest() //Ref# 2 { Instant startIsolation = new LocalDateTime(2020, 04, 21, 14, 43, 00).InZoneStrictly(_zoneGmt).ToInstant(); var stillHasSymptoms = "no"; var resultDaysRemaining = 1; var resultComment = $"The time remaining for your self-isolation is {resultDaysRemaining} day"; var resultColor = colorNotDone; var resultSlider = 0.07; var form = GetForm(cultureTagDefault, timeZoneAcronymDefault, false, stillHasSymptoms, startIsolation.ToString(cultureTagDefault, _zoneGmt), null, out var errors); Assert.NotNull(errors); Assert.Empty(errors); var calc = new CalcUk(new IsolateRecord("Fred", form.StartIsolation, form.HasSymptoms, form.StartSymptoms)); Assert.Equal(14, calc.GetIsolationPeriodMax()); Assert.Equal(stillHasSymptoms.Equals("yes", StringComparison.OrdinalIgnoreCase), calc.IsSymptomatic()); Assert.Equal(resultDaysRemaining, calc.GetIsolationDaysRemaining(_clock.GetCurrentInstant(), out var colourName, out var comment)); Assert.Equal(resultComment, comment); Assert.Equal(resultSlider, ((double)resultDaysRemaining / (double)calc.GetIsolationPeriodMax()), 2); Assert.Equal(resultColor, colourName); }
public void Ref10SymptomsAtStartDoneAfter7DaysTest() //Ref# 10 { var startIsolation = new LocalDateTime(2020, 04, 24, 14, 43, 00).InZoneStrictly(_zoneGmt).ToInstant(); var startSymptoms = new LocalDateTime(2020, 04, 24, 14, 43, 00).InZoneStrictly(_zoneGmt).ToInstant(); var stillHasSymptoms = "no"; string resultSymptoms = startSymptoms.ToString(cultureTagDefault, _zoneGmt); var resultDaysRemaining = 0; var resultComment = $"Your self-isolation is now COMPLETE unless you have been advised otherwise"; var resultColor = colorDone; var resultSlider = 0.0; var form = GetForm(cultureTagDefault, timeZoneAcronymDefault, false, stillHasSymptoms, startIsolation.ToString(cultureTagDefault, _zoneGmt), startSymptoms.ToString(cultureTagDefault, _zoneGmt), out var errors); Assert.NotNull(errors); Assert.Empty(errors); var calc = new CalcUk(new IsolateRecord("Fred", form.StartIsolation, form.HasSymptoms, form.StartSymptoms)); Assert.Equal(14, calc.GetIsolationPeriodMax()); Assert.Equal(stillHasSymptoms.Equals("yes", StringComparison.OrdinalIgnoreCase), calc.IsSymptomatic()); Assert.Equal(resultSymptoms, form.StartSymptoms?.ToString(form.CultureTag, DateTimeZoneProviders.Tzdb[form.TzDbName])); Assert.Equal(resultDaysRemaining, calc.GetIsolationDaysRemaining(_clock.GetCurrentInstant(), out var colourName, out var comment)); Assert.Equal(resultComment, comment); Assert.Equal(resultSlider, ((double)resultDaysRemaining / (double)calc.GetIsolationPeriodMax()), 2); Assert.Equal(resultColor, colourName); }
public void GetIsolationPeriodMaxTest() { var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant(); var fred = new IsolateRecord("Fred", startQuarantine, false); var calc = new CalcUk(fred); Assert.Equal(14, calc.GetIsolationPeriodMax()); }
public IActionResult OnPost() { IActionResult rc = Page(); SampleDateTime = GetText("ExampleDateTime"); TextColor = "red"; ShowRange = true; InitialiseSettingsFromCookies(); var form = ProcessForm(SelectedTzDbName ?? AppSupportedTimeZones.DefaultTzDbName, SelectedCultureTab ?? AppSupportedCultures.DefaultTab); //get time and culture from dropdowns on form if (ModelState.IsValid && (form != null)) { try { var nowInstance = _clock.GetCurrentInstant(); var record = new IsolateRecord("Fred", form.StartIsolation, form.HasSymptoms, form.StartSymptoms); var calc = new CalcUk(record); IsolationDaysMax = calc.GetIsolationPeriodMax(); if (calc.IsSymptomatic() && (form.StartSymptoms == null)) { StartSymptoms = nowInstance.ToString(SelectedCultureTab, DateTimeZoneProviders.Tzdb[SelectedTzDbName], WithoutDaylightSavings); } var isolationDaysRemaining = calc.GetIsolationDaysRemaining(nowInstance, out var colour, out var comment); if (isolationDaysRemaining == -1) { ModelState.TryAddModelError(nameof(ProgramError), $"{MxFormProc.ProgramErrorMsg} 101: An internal error has been detected. Please report this problem"); } else { TextColor = colour; Result = comment; IsolationDaysRemaining = isolationDaysRemaining; } } catch (Exception e) { ModelState.TryAddModelError(nameof(ProgramError), $"{MxFormProc.ProgramErrorMsg} 102: {e.Message}. Please report this problem."); } } return(rc); }