コード例 #1
0
        public void Test_Fills_In_LatestEntry()
        {
            var entryService = GetEntryService();

            var anyEntry = new Entry() { CreatedOn = new DateTime(2010, 10, 8) };

            entryService
                .Setup(e => e.GetLatestEntry(It.IsAny<string>()))
                .Returns(anyEntry);

            var statisticsAssembler = new StatisticsAssembler(
                entryService.Object, GetDefaultTimeService().Object, GetDefaultUserSettingsService().Object);

            var statisticsViewModel = new HomeStatisticsViewModel(_baseDateTime, _baseDateTime.AddDays(3));
            var statisticsViewModelResult = statisticsAssembler.AssembleHomeStatisticsViewModel(statisticsViewModel, It.IsAny<string>());

            Assert.IsTrue(statisticsViewModelResult.HasLatestEntry);
            Assert.IsNotNull(statisticsViewModelResult.LatestEntry);
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: JefClaes/Docary
        public ActionResult Statistics(HomeStatisticsViewModel statisticsViewModel)
        {
            if (ModelState.IsValid)
            {
                var model = _statisticsAssembler.AssembleHomeStatisticsViewModel(statisticsViewModel, UserId);

                ViewData.Model = model;

                var userSession = _sessionStore.GetUserSession();
                userSession.HomeStatisticsFrom = statisticsViewModel.From;
                userSession.HomeStatisticsTo = statisticsViewModel.To;
                _sessionStore.SaveUserSession(userSession);
            }
            else
            {
                ViewData.Model = statisticsViewModel;
            }

            return View();
        }
コード例 #3
0
        public void Test_Fills_In_Null_When_FirstEntry_Is_Null()
        {
            var entryService = GetEntryService();

            entryService
                .Setup(e => e.GetFirstRealEntry(It.IsAny<string>()))
                .Returns((Entry)null);

            var statisticsAssembler = new StatisticsAssembler(
                entryService.Object, GetDefaultTimeService().Object, GetDefaultUserSettingsService().Object);

            var statisticsViewModel = new HomeStatisticsViewModel(_baseDateTime, _baseDateTime.AddDays(3));
            var statisticsViewModelResult = statisticsAssembler.AssembleHomeStatisticsViewModel(statisticsViewModel, It.IsAny<string>());

            Assert.IsFalse(statisticsViewModelResult.HasFirstEntry);
            Assert.IsNull(statisticsViewModelResult.FirstEntry);
        }
コード例 #4
0
        public void Test_Uses_TitleCased_Names_For_The_TagNames()
        {
            var statisticsAssembler = new StatisticsAssembler(
                GetEntryService().Object, GetDefaultTimeService().Object, GetDefaultUserSettingsService().Object);

            var statisticsViewModel = new HomeStatisticsViewModel(_baseDateTime, _baseDateTime.AddDays(3));
            var statisticsViewModelResult = statisticsAssembler.AssembleHomeStatisticsViewModel(statisticsViewModel, It.IsAny<string>());

            var firstPerTag = statisticsViewModelResult.PerTag.Items.First();

            Assert.AreEqual("Commuting", firstPerTag.TagName);
        }
コード例 #5
0
        public void Test_PerTag_ViewModel_Is_Calculated_Correctly()
        {
            var statisticsAssembler = new StatisticsAssembler(
                GetEntryService().Object, GetDefaultTimeService().Object, GetDefaultUserSettingsService().Object);

            var statisticsViewModel = new HomeStatisticsViewModel(_baseDateTime, _baseDateTime.AddDays(3));
            var statisticsViewModelResult = statisticsAssembler.AssembleHomeStatisticsViewModel(statisticsViewModel, It.IsAny<string>());

            var firstPerTag = statisticsViewModelResult.PerTag.Items.First();
            var secondPerTag = statisticsViewModelResult.PerTag.Items.ElementAt(1);

            Assert.AreEqual(1, firstPerTag.Time.Days);
            Assert.AreEqual(12, firstPerTag.Time.Hours);
            Assert.AreEqual(75.0, Math.Ceiling(firstPerTag.Percentage));

            Assert.AreEqual(0, secondPerTag.Time.Days);
            Assert.AreEqual(12, secondPerTag.Time.Hours);
            Assert.AreEqual(25, Math.Ceiling(secondPerTag.Percentage));
        }
コード例 #6
0
        public void Test_Orders_PerTag_Items_Descending()
        {
            var statisticsAssembler = new StatisticsAssembler(
                GetEntryService().Object, GetDefaultTimeService().Object, GetDefaultUserSettingsService().Object);

            var statisticsViewModel = new HomeStatisticsViewModel(_baseDateTime, _baseDateTime.AddDays(3));
            var statisticsViewModelResult = statisticsAssembler.AssembleHomeStatisticsViewModel(statisticsViewModel, It.IsAny<string>());

            var firstPerTag = statisticsViewModelResult.PerTag.Items.First();
            var secondPerTag = statisticsViewModelResult.PerTag.Items.ElementAt(1);

            Assert.IsTrue(firstPerTag.Percentage > secondPerTag.Percentage);
        }
コード例 #7
0
        public void Test_Fills_In_Number_Of_Entries()
        {
            var entryService = GetEntryService();

            entryService
                .Setup(e => e.GetNumberOfEntries(It.IsAny<string>()))
                .Returns(5);

            var statisticsAssembler = new StatisticsAssembler(
                entryService.Object, GetDefaultTimeService().Object, GetDefaultUserSettingsService().Object);

            var statisticsViewModel = new HomeStatisticsViewModel(_baseDateTime, _baseDateTime.AddDays(3));
            var statisticsViewModelResult = statisticsAssembler.AssembleHomeStatisticsViewModel(statisticsViewModel, It.IsAny<string>());

            Assert.AreEqual(5, statisticsViewModelResult.NumberOfEntries);
        }