public void GetTzDbNameTest() { var zones = new AppSupportedTimeZones(); Assert.Equal("Europe/London", zones.GetTzDbName(AppSupportedTimeZones.AcronymGmt)); Assert.Equal("Europe/Paris", zones.GetTzDbName(AppSupportedTimeZones.AcronymCet)); }
public void ValidateTest() { var zones = new AppSupportedTimeZones(); var form = new IndexFormProc(_clock, zones.GetTzDbName("GMT"), "en-GB", false); Assert.False(form.IsValid()); var paramList = new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>(MxFormProc.ProgramErrorKey, ""), new KeyValuePair <string, object>(IndexFormProc.HasSymptomsKey, "yes"), new KeyValuePair <string, object>(IndexFormProc.StartIsolationKey, StdLocalTime), new KeyValuePair <string, object>(IndexFormProc.StartSymptomsKey, StdLocalTime), }; var errors = form.Validate(paramList.ToArray()); Assert.NotNull(errors); Assert.Empty(errors); Assert.True(form.IsValid()); Assert.True(form.HasSymptoms); Assert.Equal(_clock.GetCurrentInstant(), form.StartIsolation); Assert.Equal(_clock.GetCurrentInstant(), form.StartSymptoms); }
public void ValidateMultipleFailTest() { var zones = new AppSupportedTimeZones(); var form = new IndexFormProc(_clock, zones.GetTzDbName("GMT"), "en-GB", false); Assert.False(form.IsValid()); var paramList = new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>(MxFormProc.ProgramErrorKey, ""), new KeyValuePair <string, object>(IndexFormProc.HasSymptomsKey, "gg"), new KeyValuePair <string, object>(IndexFormProc.StartIsolationKey, "01-01-xx 17:35"), new KeyValuePair <string, object>(IndexFormProc.StartSymptomsKey, "01-01-2020 5:35 PM"), }; var errors = form.Validate(paramList.ToArray()); Assert.NotNull(errors); Assert.True(errors.Count == 3); Assert.True(errors.TryGetValue(IndexFormProc.HasSymptomsKey, out var errHasSymptoms)); Assert.StartsWith("Please enter either 'yes' or 'no'", errHasSymptoms); Assert.True(errors.TryGetValue(IndexFormProc.StartIsolationKey, out var errStartIsolate)); Assert.StartsWith("Please try again with a valid date/time", errStartIsolate); Assert.True(errors.TryGetValue(IndexFormProc.StartSymptomsKey, out var errStartSymptoms)); Assert.StartsWith("You must set the start of your self-isolation", errStartSymptoms); Assert.False(form.IsValid()); }
private void InitialiseSettingsFromCookies() { var cookies = new MxCookies(_httpContextAccessor); SelectedCultureTab = _supportedCultures.GetCultureTab(cookies.GetValue(MxSupportedCultures.CookieName)); SelectedTimeZone = _supportedTimeZones.GetTimeZoneAcronym(cookies.GetValue(MxSupportedTimeZones.CookieName)); WithoutDaylightSavings = _supportedTimeZones.IsDaylightSavingAuto(cookies.GetValue(MxSupportedTimeZones.CookieName)); SelectedTzDbName = _supportedTimeZones.GetTzDbName(SelectedTimeZone); }
public void HasSymptomsNullFailTest() { var zones = new AppSupportedTimeZones(); var form = new IndexFormProc(_clock, zones.GetTzDbName("GMT"), "en-GB", false); Assert.Equal("This value is required", form.ValidateHasSymptoms(null)); Assert.False(form.IsValid()); }
public void StartIsolationAfterCurrentTimeFailTest() { var zones = new AppSupportedTimeZones(); var form = new IndexFormProc(_clock, zones.GetTzDbName("GMT"), "en-GB", false); Assert.Contains("This value is after the current time", form.ValidateStartIsolation("01-01-2050 5:01 PM")); Assert.False(form.IsValid()); }
public void StartIsolationInvalidDateFailTest() { var zones = new AppSupportedTimeZones(); var form = new IndexFormProc(_clock, zones.GetTzDbName("GMT"), "en-GB", false); Assert.Contains("Please try again with a valid date/time like", form.ValidateStartIsolation("01-01-20xx 17:01:59")); Assert.False(form.IsValid()); }
public void StartIsolationEmptyFailTest() { var zones = new AppSupportedTimeZones(); var form = new IndexFormProc(_clock, zones.GetTzDbName("GMT"), "en-GB", false); Assert.Equal("This value is required", form.ValidateStartIsolation("")); Assert.False(form.IsValid()); }
public void HasSymptomsInvalidFailTest() { var zones = new AppSupportedTimeZones(); var form = new IndexFormProc(_clock, zones.GetTzDbName("GMT"), "en-GB", false); Assert.Equal("Please enter either 'yes' or 'no'", form.ValidateHasSymptoms("gg")); Assert.False(form.IsValid()); }
public void StartSymptomsBeforeSelfIsolationFailTest() { var zones = new AppSupportedTimeZones(); var form = new IndexFormProc(_clock, zones.GetTzDbName("GMT"), "en-GB", false); Assert.Null(form.ValidateStartIsolation("01-01-2020 5:01 PM")); Assert.Contains("This value is before the start of your self-isolation", form.ValidateStartSymptoms("01-01-2019 5:01 PM")); Assert.False(form.IsValid()); }
public void SymptomsNotValidatedTest() { var zones = new AppSupportedTimeZones(); var form = new IndexFormProc(_clock, zones.GetTzDbName("GMT"), "en-GB", false); var tim = new LocalDateTime(2020, 01, 1, 17, 35, 00).InZoneStrictly(_zoneGmt).ToInstant(); Assert.Null(form.ValidateStartIsolation("01-01-2020 5:35 PM")); Assert.True(form.IsValid()); Assert.Equal(tim, form.StartIsolation); Assert.Null(form.StartSymptoms); }
private IndexFormProc GetForm(string cultureTag, string timeZoneAcronym, bool withoutDaylightSavings, string stillHasSymptoms, string startIsolation, string startSymptoms, out Dictionary <string, string> errors) { errors = null; var supportedTimeZones = new AppSupportedTimeZones(); var form = new IndexFormProc(_clock, supportedTimeZones.GetTzDbName(timeZoneAcronym), cultureTag, withoutDaylightSavings); var paramList = new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>(MxFormProc.ProgramErrorKey, ""), new KeyValuePair <string, object>(IndexFormProc.HasSymptomsKey, stillHasSymptoms), new KeyValuePair <string, object>(IndexFormProc.StartIsolationKey, startIsolation), new KeyValuePair <string, object>(IndexFormProc.StartSymptomsKey, startSymptoms), }; errors = form.Validate(paramList.ToArray()); return(form); }
public void SymptomsValidatedBeforeIsolationTest() { var zones = new AppSupportedTimeZones(); var form = new IndexFormProc(_clock, zones.GetTzDbName("GMT"), "en-GB", false); var tim = new LocalDateTime(2020, 01, 1, 17, 35, 00).InZoneStrictly(_zoneGmt).ToInstant(); Assert.Contains("You must set the start of your self-isolation before giving the start of your symptoms", form.ValidateStartSymptoms("01-01-2020 5:01 PM")); Assert.False(form.IsValid()); Assert.Null(form.ValidateStartIsolation("01-01-2020 5:35 PM")); Assert.Null(form.ValidateStartSymptoms("01-01-2020 5:35 PM")); Assert.True(form.IsValid()); Assert.Equal(tim, form.StartIsolation); Assert.Equal(tim, form.StartSymptoms); }
public void ValidateMissingKeyFailTest() { var zones = new AppSupportedTimeZones(); var form = new IndexFormProc(_clock, zones.GetTzDbName("GMT"), "en-GB", false); Assert.False(form.IsValid()); var paramList = new List <KeyValuePair <string, object> >() { new KeyValuePair <string, object>(MxFormProc.ProgramErrorKey, ""), new KeyValuePair <string, object>(IndexFormProc.StartSymptomsKey, "01-01-20 17:35"), }; var errors = form.Validate(paramList.ToArray()); Assert.Null(errors); Assert.False(form.IsValid()); }
public IViewComponentResult Invoke() { string text; try { var cookies = new MxCookies(_httpContextAccessor); var value = cookies.GetValue(MxSupportedTimeZones.CookieName); var timeZoneAcronym = _supportedTimeZones.GetTimeZoneAcronym(value); var withoutDaylightSaving = (!_supportedTimeZones.IsDaylightSavingAuto(value)); if (withoutDaylightSaving) { text = timeZoneAcronym; } else { DateTimeZone zone = DateTimeZoneProviders.Tzdb[_supportedTimeZones.GetTzDbName(timeZoneAcronym)]; var daylightSavingNow = zone.IsDaylightSavingsTime(SystemClock.Instance.GetCurrentInstant()); text = (daylightSavingNow) ? _supportedTimeZones.GetDaylightSavingAcronym(timeZoneAcronym) : timeZoneAcronym; } value = cookies.GetValue(MxSupportedCultures.CookieName); var culture = _supportedCultures.GetCultureTab(value); var uiCulture = _supportedCultures.GetUiCultureTab(value); text += ",c="; text += culture; text += "|uic="; text += uiCulture; // Thread.CurrentThread.CurrentCulture = supportedCultures.GetCultureInfo(culture); // Thread.CurrentThread.CurrentUICulture = supportedCultures.GetCultureInfo(uiCulture); } catch (Exception e) { // ReSharper disable once RedundantAssignment text = e.Message; text = "[error]"; } return(View("Default", text)); }