Esempio n. 1
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. 2
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. 3
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);
        }
Esempio n. 4
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());
        }
Esempio n. 5
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. 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());
        }
Esempio n. 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());
        }
Esempio n. 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());
        }
Esempio n. 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());
        }
Esempio n. 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());
        }
Esempio n. 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);
        }
Esempio n. 12
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);
        }