Example #1
0
        public void Ref2NoSymptoms1DayTest() //Ref# 2
        {
            Instant startIsolation   = new LocalDateTime(2020, 04, 21, 14, 43, 00).InZoneStrictly(_zoneGmt).ToInstant();
            var     stillHasSymptoms = "no";

            var resultDaysRemaining = 1;
            var resultComment       = $"The time remaining for your self-isolation is {resultDaysRemaining} day";
            var resultColor         = colorNotDone;
            var resultSlider        = 0.07;

            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);
        }
Example #2
0
        public void Ref10SymptomsAtStartDoneAfter7DaysTest()    //Ref# 10
        {
            var startIsolation = new LocalDateTime(2020, 04, 24, 14, 43, 00).InZoneStrictly(_zoneGmt).ToInstant();
            var startSymptoms  = new LocalDateTime(2020, 04, 24, 14, 43, 00).InZoneStrictly(_zoneGmt).ToInstant();

            var stillHasSymptoms = "no";

            string resultSymptoms      = startSymptoms.ToString(cultureTagDefault, _zoneGmt);
            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), 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);
        }
Example #3
0
        public void NowEarlierStartIsolationFailTest()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant().Plus(Duration.FromHours(3));

            var fred = new IsolateRecord("Fred", startQuarantine, false);
            var calc = new CalcUk(fred);

            Assert.Equal(ExtNodatime.DurationError, calc.GetIsolationRemaining(_clock.GetCurrentInstant())); //now is earlier than start
        }
Example #4
0
        public void SymptomsTest()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant();

            var fred = new IsolateRecord("Fred", startQuarantine, true);
            var calc = new CalcUk(fred);

            Assert.Equal(Duration.FromDays(10), calc.GetIsolationRemaining(_clock.GetCurrentInstant())); //now same as startQuarantine
        }
Example #5
0
        public void GetIsolationPeriodMaxTest()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant();

            var fred = new IsolateRecord("Fred", startQuarantine, false);
            var calc = new CalcUk(fred);

            Assert.Equal(14, calc.GetIsolationPeriodMax());
        }
Example #6
0
        public void SymptomsFeverAfterStartTest()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant().Minus(Duration.FromHours(3));
            var startFever      = startQuarantine.Plus(Duration.FromHours(1));

            var fred = new IsolateRecord("Fred", startQuarantine, true, startFever);
            var calc = new CalcUk(fred);

            Assert.Equal(Duration.FromHours((9 * 24) + 22), calc.GetIsolationRemaining(_clock.GetCurrentInstant())); //now 3 hours after startQuarantine and 2 hours after startFever
        }
Example #7
0
        public void NoSymptomsAtDay14Test()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant().Minus(Duration.FromDays(14));
            var expected        = Duration.FromTimeSpan(new TimeSpan(0, 0, 0, 0));

            var fred = new IsolateRecord("Fred", startQuarantine, false);
            var calc = new CalcUk(fred);

            Assert.Equal(expected, calc.GetIsolationRemaining(_clock.GetCurrentInstant()));
        }
Example #8
0
        public void StartFeverEarlierStartIsolationFailTest()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant().Minus(Duration.FromHours(3));   //3 hours before _clock (now)
            var startFever      = startQuarantine.Minus(Duration.FromHours(1));                                    //1 hour before startQuarantine

            var fred = new IsolateRecord("Fred", startQuarantine, false, startFever);
            var calc = new CalcUk(fred);

            Assert.Equal(ExtNodatime.DurationError, calc.GetIsolationRemaining(_clock.GetCurrentInstant())); //startFever is earlier than startQuarantine
        }
Example #9
0
        public void SymptomsAtDay14Test() //It could be argued that the self-isolation is complete so fever is irrelevant, but side with caution
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant().Minus(Duration.FromDays(14));
            var startFever      = startQuarantine.Plus(Duration.FromDays(14));
            var expected        = Duration.FromTimeSpan(new TimeSpan(10, 0, 0, 0));

            var fred = new IsolateRecord("Fred", startQuarantine, true, startFever);
            var calc = new CalcUk(fred);

            Assert.Equal(expected, calc.GetIsolationRemaining(_clock.GetCurrentInstant()));
        }
Example #10
0
        public void SymptomsAtDay0Test()
        {
            var startQuarantine = _localClock.InZoneStrictly(_zoneGmt).ToInstant();
            var startFever      = startQuarantine;
            var expected        = Duration.FromTimeSpan(new TimeSpan(10, 0, 0, 0));

            var fred = new IsolateRecord("Fred", startQuarantine, true, startFever);
            var calc = new CalcUk(fred);

            Assert.Equal(expected, calc.GetIsolationRemaining(_clock.GetCurrentInstant()));
        }
Example #11
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);
        }