コード例 #1
0
        public async void FillMissingTimeLogs_SingleDay(
           [Frozen] Mock<IAuthenticationStorage> auth,
           [Frozen] Mock<IJobService> job,
           AuthenticationData authData,
           DaysService target)
        {
            var startOfTheMonth = new DateTime(2015, 07, 01);

            var notFilledDay1 = new Mock<IDayViewModel>();
            notFilledDay1.Setup(x => x.IsActive).Returns(true);
            notFilledDay1.Setup(x => x.IsFilled).Returns(false);
            notFilledDay1.Setup(x => x.Date).Returns(startOfTheMonth);

            var jobId = "1";

            job.Setup(x => x.GetJob(It.IsAny<DateTime>())).ReturnsAsync(jobId);
            auth.Setup(x => x.GetAuthenticationData()).Returns(authData);

            // Act
            await target.FillMissingTimeLogsAsync(notFilledDay1.Object);

            // Assert
            job.Verify(x => x.GetJob(startOfTheMonth), Times.Once);

            notFilledDay1.Verify(x => x.FillHoursAsync(authData.Id, jobId), Times.Once);
        }
コード例 #2
0
        public async void FillMissingTimeLogs_AllNotFilledAndActiveDayFilledWithDeafultJob(
            [Frozen] Mock<IAuthenticationStorage> auth,
            [Frozen] Mock<IJobService> job,
            AuthenticationData authData,
            DaysService target)
        {
            var startOfTheMonth = new DateTime(2015, 07, 01);
            
            var days = new List<IDayViewModel>();

            var dayFromOtherMonth1 = new Mock<IDayViewModel>();
            days.Add(dayFromOtherMonth1.Object);

            var filledDay1 = new Mock<IDayViewModel>();
            filledDay1.Setup(x => x.IsActive).Returns(true);
            filledDay1.Setup(x => x.IsFilled).Returns(true);
            days.Add(filledDay1.Object);

            var notFilledDay1 = new Mock<IDayViewModel>();
            notFilledDay1.Setup(x => x.IsActive).Returns(true);
            notFilledDay1.Setup(x => x.IsFilled).Returns(false);
            notFilledDay1.Setup(x => x.Date).Returns(startOfTheMonth);
            days.Add(notFilledDay1.Object);

            var notFilledDay2 = new Mock<IDayViewModel>();
            notFilledDay2.Setup(x => x.IsActive).Returns(true);
            notFilledDay2.Setup(x => x.IsFilled).Returns(false);
            notFilledDay2.Setup(x => x.Date).Returns(startOfTheMonth.AddDays(1));
            days.Add(notFilledDay2.Object);

            var notFilledHolidayDay = new Mock<IDayViewModel>();
            notFilledHolidayDay.Setup(x => x.IsActive).Returns(true);
            notFilledHolidayDay.Setup(x => x.IsFilled).Returns(false);
            notFilledHolidayDay.Setup(x => x.IsHoliday).Returns(true);
            notFilledHolidayDay.Setup(x => x.Date).Returns(startOfTheMonth.AddDays(2));
            days.Add(notFilledHolidayDay.Object);

            var filledDay2 = new Mock<IDayViewModel>();
            filledDay2.Setup(x => x.IsActive).Returns(true);
            filledDay2.Setup(x => x.IsFilled).Returns(true);
            days.Add(filledDay2.Object);

            var dayFromOtherMonth2 = new Mock<IDayViewModel>();
            days.Add(dayFromOtherMonth2.Object);

            var jobId = "1";

            job.Setup(x => x.GetJob(It.IsAny<DateTime>())).ReturnsAsync(jobId);
            auth.Setup(x => x.GetAuthenticationData()).Returns(authData);
            
            // Act
            await target.FillMissingTimeLogsAsync(days);

            // Assert
            job.Verify(x => x.GetJob(startOfTheMonth), Times.Once);

            dayFromOtherMonth1.Verify(x => x.FillHoursAsync(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
            filledDay1.Verify(x => x.FillHoursAsync(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
            notFilledDay1.Verify(x => x.FillHoursAsync(authData.Id, jobId), Times.Once);
            notFilledDay2.Verify(x => x.FillHoursAsync(authData.Id, jobId), Times.Once);
            notFilledHolidayDay.Verify(x => x.FillHoursAsync(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
            dayFromOtherMonth2.Verify(x => x.FillHoursAsync(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
            filledDay2.Verify(x => x.FillHoursAsync(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
        }