Example #1
0
        public void AdvanceHours()
        {
            FakeClock clock = new FakeClock(Instant.FromUnixTimeTicks(100L));

            clock.AdvanceHours(3);
            Assert.AreEqual(100 + 3 * NodaConstants.TicksPerHour, clock.GetCurrentInstant().ToUnixTimeTicks());
        }
Example #2
0
        public void AdvanceHours()
        {
            FakeClock clock = new FakeClock(new Instant(100L));

            clock.AdvanceHours(3);
            Assert.AreEqual(100 + 3 * NodaConstants.TicksPerHour, clock.Now.Ticks);
        }
        public async Task DailyGoalStreak_CalculatesCorrectly()
        {
            #region Day 1
            FakeClock.SetToIso("2020-03-01T11:00:00+08:00");

            var preferenceDataBase = new UserPreferenceData()
            {
                // +08:00
                DailyGoalResetTimeTimeZone = "Asia/Taipei",
                DailyGoalResetTimePartial  = "12:00:00",
                DailyGoalNewlyCreatedWordFamiliarityCount = 1,
            };

            await UserPreferencesController.Upsert(new()
            {
                Data = preferenceDataBase with
                {
                    DailyGoalNewlyCreatedWordFamiliarityCount = 1,
                },
            });

            (await DailyGoalStreak())
            .CurrentStreakDays
            .ShouldBe(0);

            await SetupWordFamiliarity(1, "sv", new() { "a" });

            (await DailyGoalStreak())
            .CurrentStreakDays
            .ShouldBe(1);
            #endregion


            #region Day 2
            FakeClock.AdvanceDays(1);
            await SetupWordFamiliarity(1, "sv", new() { "b" });

            (await DailyGoalStreak())
            .CurrentStreakDays
            .ShouldBe(2);

            await UserPreferencesController.Upsert(new()
            {
                Data = preferenceDataBase with
                {
                    DailyGoalNewlyCreatedWordFamiliarityCount = 2,
                },
            });

            (await DailyGoalStreak())
            .CurrentStreakDays
            .ShouldBe(1);

            await SetupWordFamiliarity(1, "sv", new() { "c" });

            (await DailyGoalStreak())
            .CurrentStreakDays
            .ShouldBe(2);

            await UserPreferencesController.Upsert(new()
            {
                Data = preferenceDataBase with
                {
                    DailyGoalNewlyCreatedWordFamiliarityCount = 1,
                },
            });

            (await DailyGoalStreak())
            .CurrentStreakDays
            .ShouldBe(2);


            using (User(2))
            {
                await UserPreferencesController.Upsert(new()
                {
                    Data = preferenceDataBase with
                    {
                        DailyGoalNewlyCreatedWordFamiliarityCount = 1,
                    },
                });

                (await DailyGoalStreak())
                .CurrentStreakDays
                .ShouldBe(0);

                await SetupWordFamiliarity(1, "sv", new() { "a" });

                (await DailyGoalStreak())
                .CurrentStreakDays
                .ShouldBe(1);
            }
            #endregion

            #region Day 3 - before daily goal reset
            FakeClock.AdvanceDays(1);

            (await DailyGoalStreak())
            .CurrentStreakDays
            .ShouldBe(2);
            #endregion

            #region Day 3 - after daily goal reset
            FakeClock.AdvanceHours(2);

            (await DailyGoalStreak())
            .CurrentStreakDays
            .ShouldBe(0);

            await SetupWordFamiliarity(1, "sv", new() { "d" });

            (await DailyGoalStreak())
            .CurrentStreakDays
            .ShouldBe(1);
            #endregion

            #region Day 4 - before daily goal reset
            FakeClock.AdvanceHours(-2);
            FakeClock.AdvanceDays(1);
            await SetupWordFamiliarity(1, "sv", new() { "e" });

            (await DailyGoalStreak())
            .CurrentStreakDays
            .ShouldBe(1);
            #endregion

            #region Day 5
            FakeClock.AdvanceDays(1);
            #endregion

            #region Day 6
            FakeClock.AdvanceDays(1);
            await SetupWordFamiliarity(1, "sv", new() { "f" });

            (await DailyGoalStreak())
            .CurrentStreakDays
            .ShouldBe(1);
            #endregion
        }