コード例 #1
0
        public void TestPost()
        {
            var setup = new TrackerControllerTestSetup(new List <Tracker>());

            setup.TrackerRepoMock.Setup(tr => tr.StartTracker(setup.UserMock.Id, "unit testing")).Returns(new Tracker {
                Id = "tid"
            });

            var response = setup.Subject.Post(new StartTrackingRequest {
                TrackerName = "unit testing"
            });

            Assert.IsInstanceOf <OkObjectResult>(response);
            Assert.IsInstanceOf <Tracker>(((OkObjectResult)response).Value);


            // test that we don't allow to start tracking when there is an active session
            setup = new TrackerControllerTestSetup(new List <Tracker>());
            setup.TrackerRepoMock.Setup(tr => tr.StartTracker(setup.UserMock.Id, "unit testing")).Returns(new Tracker {
                Id = "tid2"
            });
            setup.TrackerRepoMock.Setup(tr => tr.GetActiveTrackerOfUser(setup.UserMock.Id)).Returns(new Tracker {
                Id = "tid1"
            });
            response = setup.Subject.Post(new StartTrackingRequest {
                TrackerName = "unit testing"
            });
            Assert.IsInstanceOf <BadRequestObjectResult>(response);
        }
コード例 #2
0
        public void TestPatch()
        {
            // test that we don't allow to stop an already stopped tracker
            var setup = new TrackerControllerTestSetup(new List <Tracker>());

            setup.TrackerRepoMock.Setup(tr => tr.GetTracker("tid"))
            .Returns(new Tracker {
                Id        = "tid",
                StartedAt = setup.ClockMock.Now.AddDays(-1),
                StoppedAt = setup.ClockMock.Now,
                Name      = "old",
                UserId    = setup.UserMock.Id
            });

            var response = setup.Subject.Patch("tid");

            Assert.IsInstanceOf <BadRequestObjectResult>(response);
        }
コード例 #3
0
        public void TestGetSummaryInterValCalculations()
        {
            var setup   = new TrackerControllerTestSetup(new List <Tracker>());
            var summary = setup.Subject.GetSummary("week");

            setup.TrackerRepoMock.Verify(tr =>
                                         tr.GetTrackerHistoryDuring(setup.UserMock.Id, It.Is <DateTime>(begin => begin == new DateTime(2021, 3, 1)), setup.ClockMock.Now),
                                         Times.Exactly(1)
                                         );

            summary = setup.Subject.GetSummary("month");
            setup.TrackerRepoMock.Verify(tr =>
                                         tr.GetTrackerHistoryDuring(setup.UserMock.Id, It.Is <DateTime>(begin => begin == new DateTime(2021, 3, 1)), setup.ClockMock.Now),
                                         Times.Exactly(2)
                                         );

            summary = setup.Subject.GetSummary("day");
            setup.TrackerRepoMock.Verify(tr =>
                                         tr.GetTrackerHistoryDuring(setup.UserMock.Id, It.Is <DateTime>(begin => begin == new DateTime(2021, 3, 3)), setup.ClockMock.Now),
                                         Times.Exactly(1)
                                         );
        }