Esempio n. 1
0
        private void TestPerfectSchedule(
            Mock <ITalkScheduleService> scheduleService,
            MockDateTimeService dateTimeService,
            DateTime mtgStart,
            AdaptiveTimerService service)
        {
            var living1 = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.LivingPart1);

            dateTimeService.Set(mtgStart + living1.StartOffsetIntoMeeting);

            var adaptedDuration1 = service.CalculateAdaptedDuration(living1.Id);

            Assert.IsNull(adaptedDuration1);

            var study = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.CongBibleStudy);

            dateTimeService.Set(mtgStart + study.StartOffsetIntoMeeting);

            var adaptedDuration2 = service.CalculateAdaptedDuration(study.Id);

            Assert.IsNull(adaptedDuration2);

            var concluding = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.ConcludingComments);

            dateTimeService.Set(mtgStart + concluding.StartOffsetIntoMeeting);

            var adaptedDuration3 = service.CalculateAdaptedDuration(concluding.Id);

            Assert.IsNull(adaptedDuration3);
        }
Esempio n. 2
0
        private void TestManuallyAdjustedSchedule2(
            Mock <ITalkScheduleService> scheduleService,
            MockDateTimeService dateTimeService,
            DateTime mtgStart,
            AdaptiveTimerService service)
        {
            var living1    = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.LivingPart1);
            var study      = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.CongBibleStudy);
            var concluding = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.ConcludingComments);

            // add 5 mins to Study and remove 3 mins from Living1 and 2 minutes from concluding
            study.ModifiedDuration      = study.OriginalDuration.Add(TimeSpan.FromMinutes(5));
            living1.ModifiedDuration    = study.OriginalDuration.Add(-TimeSpan.FromMinutes(3));
            concluding.ModifiedDuration = study.OriginalDuration.Add(-TimeSpan.FromMinutes(2));

            dateTimeService.Set(mtgStart + living1.StartOffsetIntoMeeting);

            var adaptedDuration1 = service.CalculateAdaptedDuration(living1.Id);

            Assert.IsNull(adaptedDuration1);

            dateTimeService.Set(mtgStart + study.StartOffsetIntoMeeting + TimeSpan.FromMinutes(-3));

            var adaptedDuration2 = service.CalculateAdaptedDuration(study.Id);

            Assert.IsNull(adaptedDuration2);

            dateTimeService.Set(mtgStart + concluding.StartOffsetIntoMeeting + TimeSpan.FromMinutes(5));

            var adaptedDuration3 = service.CalculateAdaptedDuration(concluding.Id);

            Assert.IsNull(adaptedDuration3);
        }
        public void SetUp()
        {
            _diagnosticsViewModel = new Mock <IDiagnosticsViewModel>();

            _data = new Subject <IEnumerable <DynamicData> >();
            _tabularDataService = new Mock <ITabularDataService>();
            _tabularDataService.Setup(x => x.GetAsync())
            .Returns(_data);

            _columnsChanged     = new Subject <string>();
            _columnsInitialised = new Subject <string>();

            _columnsService = new Mock <IColumnsService>();
            _columnsService.Setup(x => x.Changed)
            .Returns(_columnsChanged);
            _columnsService.Setup(x => x.Initialised)
            .Returns(_columnsInitialised);
            _columnsService.Setup(x => x.InitialiseColumns(It.IsAny <string>(), It.IsAny <IEnumerable <string> >()))
            .Callback <string, IEnumerable <string> >((y, z) =>
            {
                _columnsService.Setup(x => x.VisibleColumns(It.IsAny <string>()))
                .Returns(z);
            });

            _overlayService  = new Mock <IOverlayService>();
            _dateTimeService = new MockDateTimeService(TestScheduler);

            TestScheduler.AdvanceTo(DateTime.Now.Ticks);
        }
        public async Task WhenSecurityStampUpdated_Invalidates()
        {
            var uniqueData = "SecurityStampUpd_Inval";

            var seedDate        = DateTimeOffset.UtcNow;
            var dateTimeService = new MockDateTimeService(seedDate);

            using var app     = _webApplicationFactory.CreateApp();
            using var client1 = _webApplicationFactory.CreateClientWithServices(s => s.AddSingleton <IDateTimeService>(dateTimeService));
            using var client2 = _webApplicationFactory.CreateClientWithServices(s => s.AddSingleton <IDateTimeService>(dateTimeService));
            var userId = await app.TestData.Users().AddAsync(uniqueData, UNIQUE_PREFIX);

            await client1.ImpersonateUserAsync(userId);

            await client2.ImpersonateUserAsync(userId);

            var response = await client1.PutAsync($"/tests/users/password/{userId}", null);

            response.EnsureSuccessStatusCode();

            dateTimeService.MockDateTime = seedDate.AddMinutes(35);
            var client1UserId = await GetCurrentlySignedInUserId(client1);

            var client2UserId = await GetCurrentlySignedInUserId(client2);

            client1UserId.Should().Be(userId);
            client2UserId.Should().BeNull();
        }
        public void BaseSetup()
        {
            TestScheduler = new TestScheduler();

            SchedulerService = new MockSchedulerService(TestScheduler);

            DateTimeService = new MockDateTimeService(TestScheduler);
        }
        public async Task WhenNoChange_Validates()
        {
            var seedDate        = DateTimeOffset.UtcNow;
            var dateTimeService = new MockDateTimeService(seedDate);

            using var app    = _webApplicationFactory.CreateApp();
            using var client = _webApplicationFactory.CreateClientWithServices(s => s.AddSingleton <IDateTimeService>(dateTimeService));
            var user = app.SeededEntities.TestUserArea1.RoleA.User;

            await client.ImpersonateUserAsync(user);

            dateTimeService.MockDateTime = seedDate.AddMinutes(35);
            var userId = await GetCurrentlySignedInUserId(client);

            userId.Should().Be(user.UserId);
        }
Esempio n. 7
0
        private void TestLateSchedule2(
            Mock <ITalkScheduleService> scheduleService,
            MockDateTimeService dateTimeService,
            DateTime mtgStart,
            AdaptiveTimerService service)
        {
            var living1    = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.LivingPart1);
            var concluding = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.ConcludingComments);
            var study      = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.CongBibleStudy);

            // 10 mins late starting the "Living" section.
            dateTimeService.Set(mtgStart + living1.StartOffsetIntoMeeting + TimeSpan.FromMinutes(10));

            var adaptedDuration1 = service.CalculateAdaptedDuration(living1.Id);

            Assert.IsNotNull(adaptedDuration1);
            AssertTimeSpansAboutEqual(adaptedDuration1.Value, new TimeSpan(0, 11, 52));
            living1.AdaptedDuration = adaptedDuration1;

            // at start of study we're only 5 mins behind
            dateTimeService.Set(mtgStart + study.StartOffsetIntoMeeting + TimeSpan.FromMinutes(5));

            // remove 5 mins from study and add to conclusion.
            study.ModifiedDuration      = study.OriginalDuration.Add(TimeSpan.FromMinutes(-5));
            concluding.ModifiedDuration = concluding.OriginalDuration.Add(TimeSpan.FromMinutes(5));

            // remaining meeting duration = 28 mins shared between study of 25 mins and conc of 8 mins (total 33 mins)
            // adapted duration of study = 21 mins 12 secs, conc = 6 mins 47 secs

            var adaptedDuration2 = service.CalculateAdaptedDuration(study.Id);

            Assert.IsNotNull(adaptedDuration2);
            AssertTimeSpansAboutEqual(adaptedDuration2.Value, new TimeSpan(0, 21, 12));
            study.AdaptedDuration = adaptedDuration2;

            dateTimeService.Set(mtgStart + study.StartOffsetIntoMeeting + TimeSpan.FromMinutes(5) + study.AdaptedDuration.Value);

            var adaptedDuration3 = service.CalculateAdaptedDuration(concluding.Id);

            Assert.IsNotNull(adaptedDuration3);
            AssertTimeSpansAboutEqual(adaptedDuration3.Value, new TimeSpan(0, 6, 47));
            concluding.AdaptedDuration = adaptedDuration3;
        }
Esempio n. 8
0
        public void InitializeTests()
        {
            _items = GenerateTalkItems(_theDate);

            var options = MockOptions.Create();

            options.GenerateTimingReports = false;
            options.MidWeekAdaptiveMode   = AdaptiveMode.TwoWay;
            options.MidWeekOrWeekend      = MidWeekOrWeekend.MidWeek;
            options.OperatingMode         = OperatingMode.Automatic;

            Mock <IOptionsService> optionsService = new Mock <IOptionsService>();

            optionsService.Setup(o => o.Options).Returns(options);
            optionsService.Setup(x => x.GetAdaptiveMode()).Returns(options.MidWeekAdaptiveMode);

            _scheduleService = new Mock <ITalkScheduleService>();
            _scheduleService.Setup(x => x.GetTalkScheduleItems()).Returns(_items);
            _scheduleService.Setup(x => x.GetTalkScheduleItem(It.IsAny <int>())).Returns((int id) => _items.Single(y => y.Id == id));

            _dateTimeService = new MockDateTimeService();
            _mtgStart        = _theDate + TimeSpan.FromHours(19); // 7pm
            _dateTimeService.Set(_mtgStart);

            _adaptiveTimerService = new AdaptiveTimerService(
                optionsService.Object, _scheduleService.Object, _dateTimeService);

            _adaptiveTimerService.SetMeetingStartTimeForTesting(_dateTimeService.UtcNow());

            // complete most of the timers...
            foreach (var item in _items)
            {
                if (item.Id == (int)TalkTypesAutoMode.LivingPart1)
                {
                    break;
                }

                // each item exactly on time
                item.CompletedTimeSecs = (int)item.ActualDuration.TotalSeconds;
            }
        }
Esempio n. 9
0
        private void TestManuallyAdjustedSchedule4(
            Mock <ITalkScheduleService> scheduleService,
            MockDateTimeService dateTimeService,
            DateTime mtgStart,
            AdaptiveTimerService service)
        {
            var living1    = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.LivingPart1);
            var study      = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.CongBibleStudy);
            var concluding = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.ConcludingComments);

            // take 5 mins from study but don't compensate elsewhere
            study.ModifiedDuration = study.OriginalDuration.Add(-TimeSpan.FromMinutes(5));

            dateTimeService.Set(mtgStart + living1.StartOffsetIntoMeeting);

            var adaptedDuration1 = service.CalculateAdaptedDuration(living1.Id);

            Assert.IsNotNull(adaptedDuration1);
            AssertTimeSpansAboutEqual(adaptedDuration1.Value, new TimeSpan(0, 16, 44));
            living1.AdaptedDuration = adaptedDuration1;

            dateTimeService.Set(mtgStart + living1.StartOffsetIntoMeeting + adaptedDuration1.Value);

            var adaptedDuration2 = service.CalculateAdaptedDuration(study.Id);

            Assert.IsNotNull(adaptedDuration2);
            AssertTimeSpansAboutEqual(adaptedDuration2.Value, new TimeSpan(0, 28, 12));
            study.AdaptedDuration = adaptedDuration2;

            dateTimeService.Set(mtgStart + study.StartOffsetIntoMeeting + adaptedDuration2.Value);

            var adaptedDuration3 = service.CalculateAdaptedDuration(concluding.Id);

            Assert.IsNotNull(adaptedDuration3);
            AssertTimeSpansAboutEqual(adaptedDuration3.Value, new TimeSpan(0, 4, 47));
            concluding.AdaptedDuration = adaptedDuration3;
        }
Esempio n. 10
0
        private void TestEarlySchedule(
            Mock <ITalkScheduleService> scheduleService,
            MockDateTimeService dateTimeService,
            DateTime mtgStart,
            AdaptiveTimerService service)
        {
            // 10 mins early starting this section.
            var living1 = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.LivingPart1);

            dateTimeService.Set(mtgStart + living1.StartOffsetIntoMeeting - TimeSpan.FromMinutes(10));

            var adaptedDuration1 = service.CalculateAdaptedDuration(living1.Id);

            Assert.IsNotNull(adaptedDuration1);
            AssertTimeSpansAboutEqual(adaptedDuration1.Value, new TimeSpan(0, 18, 7));
            living1.AdaptedDuration = adaptedDuration1;

            var study = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.CongBibleStudy);

            dateTimeService.Set(mtgStart + study.StartOffsetIntoMeeting - TimeSpan.FromMinutes(5));

            var adaptedDuration2 = service.CalculateAdaptedDuration(study.Id);

            Assert.IsNotNull(adaptedDuration2);
            AssertTimeSpansAboutEqual(adaptedDuration2.Value, new TimeSpan(0, 34, 32));
            study.AdaptedDuration = adaptedDuration2;

            var concluding = scheduleService.Object.GetTalkScheduleItem((int)TalkTypesAutoMode.ConcludingComments);

            dateTimeService.Set(mtgStart + concluding.StartOffsetIntoMeeting - TimeSpan.FromMinutes(1));

            var adaptedDuration3 = service.CalculateAdaptedDuration(concluding.Id);

            Assert.IsNotNull(adaptedDuration3);
            AssertTimeSpansAboutEqual(adaptedDuration3.Value, new TimeSpan(0, 4, 0));
            concluding.AdaptedDuration = adaptedDuration3;
        }
Esempio n. 11
0
        public void TestOperatorViewStartStop()
        {
            const int TalkIdStart = 500;
            const int NumTalks    = 3;

            var options = MockOptions.Create();

            options.GenerateTimingReports = false;
            options.MidWeekAdaptiveMode   = AdaptiveMode.TwoWay;
            options.MidWeekOrWeekend      = MidWeekOrWeekend.MidWeek;
            options.OperatingMode         = OperatingMode.Automatic;

            var optionsService = new Mock <IOptionsService>();

            optionsService.Setup(o => o.Options).Returns(options);
            optionsService.Setup(x => x.GetAdaptiveMode()).Returns(options.MidWeekAdaptiveMode);

            var timerService                     = new Mock <ITalkTimerService>();
            var adaptiveTimerService             = new Mock <IAdaptiveTimerService>();
            ITalkScheduleService scheduleService = new MockTalksScheduleService(TalkIdStart, NumTalks);
            var bellService        = new Mock <IBellService>();
            var commandLineService = new Mock <ICommandLineService>();
            var timingDataService  = new Mock <ILocalTimingDataStoreService>();
            var snackbarService    = new Mock <ISnackbarService>();
            var dateTimeService    = new MockDateTimeService();
            IQueryWeekendService queryWeekendService = new QueryWeekendService();

            dateTimeService.Set(new DateTime(2019, 11, 28) + TimeSpan.FromHours(19));

            var vm = new OperatorPageViewModel(
                timerService.Object,
                scheduleService,
                adaptiveTimerService.Object,
                optionsService.Object,
                commandLineService.Object,
                bellService.Object,
                timingDataService.Object,
                snackbarService.Object,
                dateTimeService,
                queryWeekendService);

            Assert.IsFalse(vm.IsRunning);
            Assert.IsFalse(vm.IsManualMode);

            for (var n = 0; n < NumTalks; ++n)
            {
                var talkId = TalkIdStart + n;
                Assert.IsTrue(vm.TalkId == talkId);

                var talk = scheduleService.GetTalkScheduleItem(talkId);
                Assert.IsNotNull(talk);
                Assert.AreEqual(vm.CurrentTimerValueString, TimeFormatter.FormatTimerDisplayString(talk.GetPlannedDurationSeconds()));

                vm.StartCommand.Execute(null);
                Assert.IsTrue(vm.IsRunning);

                Assert.IsTrue(vm.TalkId == TalkIdStart + n);

                vm.StopCommand.Execute(null);
                Assert.IsFalse(vm.IsRunning);

                Assert.IsTrue(vm.TalkId == (n == NumTalks - 1 ? 0 : TalkIdStart + n + 1));
            }
        }