Exemple #1
0
        public async Task CanPunchCardCorrectly(DateTime startMonitorTime)
        {
            var service   = new HrResourceService(new ConsoleLogger(), new VoidPunchService());
            var interFace = (IHrResourceService)service;
            var endDay    = startMonitorTime.AddDays(1);

            var totalMins = (int)(endDay - startMonitorTime).TotalMinutes;

            var totalDays = 8;

            foreach (var day in Enumerable.Range(0, totalDays))
            {
                var start = startMonitorTime.AddDays(day);

                foreach (var min in Enumerable.Range(0, totalMins))
                {
                    var now = start.AddMinutes(min);

                    bool IsWeekend() => now.DayOfWeek == DayOfWeek.Saturday || now.DayOfWeek == DayOfWeek.Sunday;


                    await service.PunchCardIfNeedAsync(now);

                    if (min % 60 == 0)
                    {
                        Console.WriteLine($@"[{now}]  {interFace.ToLogInfo()} ");
                    }
                    interFace.NextPunchedInTime.Should().NotBeNull();
                    interFace.NextPunchedOutTime.Should().NotBeNull();

                    if (IsWeekend())
                    {
                        interFace.PunchedInTime.Should().Be(null, because: $"now time: {now}");
                        interFace.PunchedOutTime.Should().Be(null, $"now time: {now}");
                        interFace.PunchedInTime.Should().Be(null, $"now time: {now}");
                        interFace.PunchedOutTime.Should().Be(null, $"now time: {now}");
                        continue;
                    }

                    if (now.Hour < 9)
                    {
                        interFace.PunchedInTime.Should().Be(null, because: $"now time: {now}");
                        interFace.PunchedOutTime.Should().Be(null, $"now time: {now}");
                    }

                    var crossDay = now.Year - startMonitorTime.Year >= 1 || now.Month - startMonitorTime.Month >= 1 || now.Day - startMonitorTime.Day >= 1  ? now.Date : startMonitorTime;

                    AssertWorkTimeShouldBeCorrect(interFace, now, crossDay);

                    AssertOffTimeShouldBeCorrect(interFace, now, crossDay);
                }
            }
        }
Exemple #2
0
        public void CanQueryDaily()
        {
            var config = Substitute.For <IAppConfiguration>();

            config.NueIpCompany.Returns("507641428");
            config.NueIpId.Returns("GJ0080");
            config.NueIpPwd.Returns("");
            var service   = new HrResourceService(new ConsoleLogger(), new NueIpService(new Logger(), config));
            var interFace = (IHrResourceService)service;

            Console.WriteLine(interFace.PunchedInTime);
        }