Пример #1
0
        public void GetTzDbNameTest()
        {
            var zones = new AppSupportedTimeZones();

            Assert.Equal("Europe/London", zones.GetTzDbName(AppSupportedTimeZones.AcronymGmt));
            Assert.Equal("Europe/Paris", zones.GetTzDbName(AppSupportedTimeZones.AcronymCet));
        }
Пример #2
0
        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);
        }
Пример #3
0
        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());
        }
Пример #4
0
        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);
        }
Пример #5
0
        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());
        }
Пример #6
0
        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());
        }
Пример #7
0
        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());
        }
Пример #8
0
        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());
        }
Пример #9
0
        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());
        }
Пример #10
0
        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());
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        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);
        }
Пример #14
0
        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());
        }
Пример #15
0
        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));
        }