Esempio n. 1
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());
        }
Esempio n. 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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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());
        }
Esempio n. 5
0
        public IndexFormProc ProcessForm(string tzDbName, string cultureTab)
        {
            IndexFormProc rc = null;

            if (ModelState.IsValid)
            {
                var form = new IndexFormProc(_clock, tzDbName, cultureTab, WithoutDaylightSavings);

                var paramList = new List <KeyValuePair <string, object> >()
                {
                    new KeyValuePair <string, object>(nameof(ProgramError), ProgramError),
                    new KeyValuePair <string, object>(nameof(HasSymptoms), HasSymptoms),
                    new KeyValuePair <string, object>(nameof(StartIsolation), StartIsolation),
                    new KeyValuePair <string, object>(nameof(StartSymptoms), StartSymptoms),
                };

                var errors = form.Validate(paramList.ToArray());
                if (errors == null)
                {
                    ModelState.TryAddModelError(nameof(ProgramError), $"{MxFormProc.ProgramErrorMsg} 100: Invalid Property Names");
                }
                else
                {
                    foreach (var error in errors)
                    {
                        ModelState.TryAddModelError(error.Key, error.Value);
                    }

                    if (form.IsValid())
                    {
                        rc = form;
                    }
                }
            }
            return(rc);
        }