Exemplo n.º 1
0
        public async Task PopulateStatsAsync_OddLoggedDays_ComputesCorrectMedian()
        {
            // arrange
            var tracker = new Tracker {
                Id = 0
            };
            var service = new MockTrackerLogService();

            service.LoggedDays.Add(new LoggedDay {
                Date = new DateTime(2002, 1, 1)
            });
            service.LoggedDays.Add(new LoggedDay {
                Date = new DateTime(2002, 1, 1)
            });
            service.LoggedDays.Add(new LoggedDay {
                Date = new DateTime(2001, 1, 1)
            });
            service.LoggedDays.Add(new LoggedDay {
                Date = new DateTime(2000, 1, 1)
            });
            service.LoggedDays.Add(new LoggedDay {
                Date = new DateTime(2000, 1, 1)
            });
            var vm = new TrackerLogViewModel(tracker, service, new MockSettingsViewModel());
            await vm.PopulateAllDayGroupsAsync();

            // act
            await vm.PopulateStatsAsync();

            // assert
            Assert.Equal(1, vm.LoggedDayStats.Median);
        }
Exemplo n.º 2
0
        public async Task PopulateAllDayGroupsAsync_ServiceFailure_DoesNotChangeState()
        {
            // arrange
            var tracker = new Tracker {
                Id = 0
            };
            var group = new LoggedDayGroup {
                Date = DateTime.Now.Date, Count = 2
            };
            var vm = new TrackerLogViewModel(tracker, new FailingTrackerLogService(), new MockSettingsViewModel());

            vm.AllDayGroups.Add(group);

            // act
            await vm.PopulateAllDayGroupsAsync();

            // assert
            Assert.Single(vm.AllDayGroups, expected: group);
        }
Exemplo n.º 3
0
        public async Task PopulateAllDayGroupsAsync_ServiceFailure_SendsMessage()
        {
            // arrange
            var tracker = new Tracker {
                Id = 0
            };
            var vm = new TrackerLogViewModel(tracker, new FailingTrackerLogService(), new MockSettingsViewModel());

            bool messageSent = false;

            MessagingCenter.Subscribe <TrackerLogViewModel>(this, TrackerLogViewModel.DatabaseErrorMessage,
                                                            sender => messageSent = true);

            // act
            await vm.PopulateAllDayGroupsAsync();

            // assert
            Assert.True(messageSent);
        }