示例#1
0
        public void Ref5SymptomsAfter7DaysTest()  //Ref# 5
        {
            var startIsolation   = new LocalDateTime(2020, 04, 20, 14, 50, 00).InZoneStrictly(_zoneGmt).ToInstant();
            var stillHasSymptoms = "yes";

            var resultDaysRemaining = 10;
            var resultComment       = $"The time remaining for your self-isolation is {resultDaysRemaining} days";
            var resultColor         = colorNotDone;
            var resultSlider        = 0.71;

            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);
        }
示例#2
0
        public void Ref12SymptomsAtStart25042020Test()    //Ref# 12
        {
            var startIsolation = new LocalDateTime(2020, 04, 22, 14, 43, 00).InZoneStrictly(_zoneGmt).ToInstant();
            var startSymptoms  = new LocalDateTime(2020, 04, 23, 14, 43, 00).InZoneStrictly(_zoneGmt).ToInstant();

            var stillHasSymptoms = "yes";

            string resultSymptoms      = startSymptoms.ToString(cultureTagDefault, _zoneGmt);
            var    resultDaysRemaining = 1;
            var    resultComment       = "The time remaining for your self-isolation is 1 day";
            var    resultColor         = colorNotDone;
            var    resultSlider        = 0.07;

            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);
        }
示例#3
0
        public void Ref4NoSymptomsDoneTest()  //Ref# 4
        {
            Instant startIsolation   = new LocalDateTime(2020, 04, 20, 14, 43, 00).InZoneStrictly(_zoneGmt).ToInstant();
            var     stillHasSymptoms = "no";

            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), 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);
        }
示例#4
0
        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);
        }