Esempio n. 1
0
        public void VerifyFirstStamp_NoFirstInStamp_AddBeginOfDayAsFirstInStamp()
        {
            // Arrange
            // Target day is 01.03.2016
            DateTime targetDay              = new DateTime(2016, 3, 1);
            int      targetEmployerID       = 1;
            List <EmployerTimeStamp> stamps = new List <EmployerTimeStamp>()
            {
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay
                }
            };
            int originalStampsCount           = stamps.Count;
            DailyReportsManager dailyReporter = this.СreateDailyReporter(stamps);
            EmployerTimeStamp   expectedStamp = new EmployerTimeStamp()
            {
                EmployerID = targetEmployerID, Type = StampType.In, Time = new DateTime(targetDay.Year, targetDay.Month, targetDay.Day, 0, 0, 0)
            };
            List <Notification> notifications = new List <Notification>();

            // Act
            dailyReporter.VerifyFirstStamp(stamps, targetEmployerID, targetDay, notifications);

            // Assertions
            // Check
            Assert.AreEqual(stamps.Count, originalStampsCount + 1);
            Assert.That(stamps[0], Is.EqualTo(expectedStamp).Using(new EmployerTimeStampComparer()));
        }
Esempio n. 2
0
        public void VerifyFirstStamp_EmptyCollection_NoExceptions()
        {
            // Arrange
            DateTime targetDay                     = new DateTime(2016, 3, 1);
            int      targetEmployerID              = 1;
            List <EmployerTimeStamp> stamps        = new List <EmployerTimeStamp>();
            DailyReportsManager      dailyReporter = this.СreateDailyReporter(stamps);
            List <Notification>      notifications = new List <Notification>();

            // Act and Assert
            // Check that call method with empty collection not throwing any exceptions.
            Assert.That(() => dailyReporter.VerifyFirstStamp(stamps, targetEmployerID, targetDay, notifications), Throws.Nothing);
        }
Esempio n. 3
0
        public void VerifyStampsSequence_NotificationsIsNull_ThrowArgumentNullException()
        {
            // Arrange
            DateTime targetDay                     = new DateTime(2016, 3, 1);
            int      targetEmployerID              = 1;
            List <EmployerTimeStamp> stamps        = new List <EmployerTimeStamp>();
            DailyReportsManager      dailyReporter = this.СreateDailyReporter(stamps);
            List <Notification>      notifications = null;

            // Act and Assert
            // Check that call method with null protocol throws "ArgumentNullException".
            Assert.That(() => dailyReporter.VerifyStampsSequence(stamps, targetEmployerID, targetDay, notifications), Throws.Exception.TypeOf <ArgumentNullException>());
        }
Esempio n. 4
0
        public void TimeOfWorkForDay_DataCorrect_CorrectTimeOfWork()
        {
            // Arrange
            // Target day is 01.03.2016
            DateTime targetDay              = new DateTime(2016, 3, 1);
            int      targetEmployerID       = 1;
            List <EmployerTimeStamp> stamps = new List <EmployerTimeStamp>()
            {
                // In-stamp at 9.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(9)
                },

                // Out-stamp at 11.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(10).AddMinutes(10)
                },

                // In-stamp at 12.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(12)
                },

                // Out-stamp at 14.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(18)
                },
            };
            DailyReportsManager dailyReporter = this.СreateDailyReporter(stamps);

            // Expected time of work.
            // It should 7 hours and 10 minutes.
            TimeSpan expectedTime = new TimeSpan(7, 10, 0);

            // Act
            var protocol = dailyReporter.TimeOfWorkForDay(targetEmployerID, targetDay);

            // Assertions
            // Check that computation was successful carried out.
            Assert.That(protocol.IsSucceed, Is.True);
            Assert.That(protocol.Result, Is.EqualTo(expectedTime));
        }
Esempio n. 5
0
        public void RespitesForDay_NoStampsForDay_NoRespitesFound()
        {
            // Arrange
            // Target day is 01.03.2016
            DateTime targetDay                     = new DateTime(2016, 3, 1);
            int      targetEmployerID              = 1;
            TimeSpan maxRespiteDuration            = new TimeSpan(0, 15, 0);
            List <EmployerTimeStamp> stamps        = new List <EmployerTimeStamp>();
            DailyReportsManager      dailyReporter = this.СreateDailyReporter(stamps);

            // No expected respites.
            List <Respite> expectedRespites = new List <Respite>();

            // Act
            var protocol = dailyReporter.RespitesForDay(targetEmployerID, targetDay, maxRespiteDuration);

            // Assertions
            // Check that computation was successful carried out.
            Assert.That(protocol.IsSucceed, Is.True);
            Assert.That(protocol.Result, Is.EqualTo(expectedRespites).Using(new RespitesComparer()));
        }
Esempio n. 6
0
        public void TimeOfWorkForDay_NoDataForDay_TimeOfWorkEqualsZero()
        {
            // Arrange
            // Target day is 01.03.2016
            DateTime targetDay                     = new DateTime(2016, 3, 1);
            int      targetEmployerID              = 1;
            List <EmployerTimeStamp> stamps        = new List <EmployerTimeStamp>();
            DailyReportsManager      dailyReporter = this.СreateDailyReporter(stamps);

            // Expected time of work.
            // It should 0 hours 0 minutes and 0 seconds.
            TimeSpan expectedTime = new TimeSpan(0);

            // Act
            var protocol = dailyReporter.TimeOfWorkForDay(targetEmployerID, targetDay);

            // Assertions
            // Check that computation was successful carried out.
            Assert.That(protocol.IsSucceed, Is.True);
            Assert.That(protocol.Result, Is.EqualTo(expectedTime));
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            DailyReportsManager dailyReporter = new DailyReportsManager(BuildStampsSource());

            ReportProtocol <TimeSpan>        dayWork     = dailyReporter.TimeOfWorkForDay(TargetEmployer(), TagetDay());
            ReportProtocol <List <Respite> > dayRespites = dailyReporter.RespitesForDay(TargetEmployer(), TagetDay(), MaxRespiteDuration());

            Console.WriteLine("Time for day:");
            if (dayWork.IsSucceed)
            {
                Console.WriteLine("\t{0} hrs.", dayWork.Result.TotalHours);
                Console.WriteLine("\tNotifications count: {0}", dayWork.Notifications.Count);
            }
            else
            {
                Console.WriteLine("\tError was occurred. Reporting end unsuccessfully.");
            }
            foreach (var n in dayWork.Notifications)
            {
                Console.WriteLine("\tType: {0}. Message: {1}", n.Type, n.Description);
            }


            Console.WriteLine("Respites for day:");
            if (dayRespites.IsSucceed)
            {
                Console.WriteLine("\tAmount of respites: {0}", dayRespites.Result.Count);
                Console.WriteLine("\tNotifications count: {0}", dayRespites.Notifications.Count);
            }
            else
            {
                Console.WriteLine("\tError was occurred. Reporting end unsuccessfully.");
            }
            foreach (var n in dayRespites.Notifications)
            {
                Console.WriteLine("\tType: {0}. Message: {1}", n.Type, n.Description);
            }

            Console.ReadKey();
        }
Esempio n. 8
0
        public void VerifyFirstStamp_DataIsCorrect_NoAnyChange()
        {
            // Arrange
            // Target day is 01.03.2016
            DateTime targetDay              = new DateTime(2016, 3, 1);
            int      targetEmployerID       = 1;
            List <EmployerTimeStamp> stamps = new List <EmployerTimeStamp>()
            {
                // In-stamp at 9.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(9)
                },

                // Out-stamp at 10.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(10)
                }
            };
            int originalStampsCount = stamps.Count;
            DailyReportsManager      dailyReporter  = this.СreateDailyReporter(stamps);
            List <Notification>      notifications  = new List <Notification>();
            List <EmployerTimeStamp> expectedStamps = new List <EmployerTimeStamp>()
            {
                stamps[0],
                stamps[1]
            };

            // Act
            dailyReporter.VerifyFirstStamp(stamps, targetEmployerID, targetDay, notifications);

            // Assertions
            // Check that collections contain same items in same order.
            Assert.That(stamps, Is.EqualTo(expectedStamps));
        }
Esempio n. 9
0
        public void RespitesForDay_IncorrectData_AllRespitesFound()
        {
            // Arrange
            // Target day is 01.03.2016
            DateTime targetDay        = new DateTime(2016, 3, 1);
            int      targetEmployerID = 1;

            // Maximum duration of respite.
            // It is 10 minutes.
            TimeSpan maxRespiteDuration = new TimeSpan(0, 10, 0);

            List <EmployerTimeStamp> stamps = new List <EmployerTimeStamp>()
            {
                // In-stamp at 9.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(9)
                },

                // Out-stamp at 9.10 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(9).Add(maxRespiteDuration)
                },

                // In-stamp at 9.10 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(9).Add(maxRespiteDuration)
                },

                // Out-stamp at 12.00 pm of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(12)
                },

                // In-stamp at 12:10:00.0001 pm of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(12).Add(maxRespiteDuration).AddMilliseconds(1)
                },

                // Out-stamp at 6.00 pm of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(18)
                }
            };
            DailyReportsManager dailyReporter = this.СreateDailyReporter(stamps);

            // This list looks like this because system should do the following steps to repair data:
            //      1. Source data will be sorted and 2nd record(start with 0) will be 1st.
            //      2. Now we have two In-stamps 0 and 1st so system create new Out-stamp in the middle of these ones.
            //      3. So now we have 1st Out-stamp(was added at 2nd step) and its time equals 9 hours and half of maximum respite time minutes.
            // So obvious that difference between 1st(Out-stamp) and 2nd(In-stamp) is less
            // than maximum respite duration because equals half of it.
            List <Respite> expectedRespites = new List <Respite>()
            {
                new Respite(targetDay.AddHours(9).AddMinutes(maxRespiteDuration.Minutes / 2), targetDay.AddHours(9).Add(maxRespiteDuration))
            };

            // Act
            var protocol = dailyReporter.RespitesForDay(targetEmployerID, targetDay, maxRespiteDuration);

            // Assertions
            // Check that computation was successful carried out.
            Assert.That(protocol.IsSucceed, Is.True);
            Assert.That(protocol.Result, Is.EqualTo(expectedRespites).Using(new RespitesComparer()));
        }
Esempio n. 10
0
        public void RespitesForDay_MaxRespiteDurationEqualsZero_NoRepitesFound()
        {
            // Arrange
            // Target day is 01.03.2016
            DateTime targetDay              = new DateTime(2016, 3, 1);
            int      targetEmployerID       = 1;
            List <EmployerTimeStamp> stamps = new List <EmployerTimeStamp>()
            {
                // In-stamp at 9.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(9)
                },

                // Out-stamp at 10.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(10)
                },

                // In-stamp at 10.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(10)
                },

                // Out-stamp at 12.00 pm of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(12)
                },

                // In-stamp at 12.15 pm of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(12).AddMinutes(15)
                },

                // Out-stamp at 6.00 pm of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(18)
                }
            };
            DailyReportsManager dailyReporter = this.СreateDailyReporter(stamps);

            // Maximum duration of respite.
            TimeSpan maxRespiteDuration = new TimeSpan(0, 0, 0);

            // Expected time of work.
            // No expected respites.
            List <Respite> expectedRespites = new List <Respite>();

            // Act
            var protocol = dailyReporter.RespitesForDay(targetEmployerID, targetDay, maxRespiteDuration);

            // Assertions
            // Check that computation was successful carried out.
            Assert.That(protocol.IsSucceed, Is.True);
            Assert.That(protocol.Result, Is.EqualTo(expectedRespites).Using(new RespitesComparer()));
        }
Esempio n. 11
0
        public void RespitesForDay_DataCorrect_AllRespitesFound()
        {
            // Arrange
            // Target day is 01.03.2016
            DateTime targetDay              = new DateTime(2016, 3, 1);
            int      targetEmployerID       = 1;
            TimeSpan maxRespiteDuration     = new TimeSpan(0, 15, 0);
            List <EmployerTimeStamp> stamps = new List <EmployerTimeStamp>()
            {
                // In-stamp at 9.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(9)
                },

                // Out-stamp at 10.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(10)
                },

                // In-stamp at 10.10 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(10).AddSeconds(10)
                },

                // Out-stamp at 12.00 pm of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(12)
                },

                // In-stamp at 12.15 pm of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(12).AddMinutes(15).AddSeconds(1)
                },

                // Out-stamp at 6.00 pm of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(18)
                }
            };
            DailyReportsManager dailyReporter = this.СreateDailyReporter(stamps);

            // All expected respites.
            // Between first and second stamps.
            // Between third and forth stamps.
            List <Respite> expectedRespites = new List <Respite>()
            {
                new Respite(stamps[1].Time, stamps[2].Time)
            };

            // Act
            var protocol = dailyReporter.RespitesForDay(targetEmployerID, targetDay, maxRespiteDuration);

            // Assertions
            // Check that computation was successful carried out.
            Assert.That(protocol.IsSucceed, Is.True);
            Assert.That(protocol.Result, Is.EqualTo(expectedRespites).Using(new RespitesComparer()));
        }
Esempio n. 12
0
        public void VerifyStampsSequence_NoSomeStampsInSequence_AddNonexistentStampsInMiddle()
        {
            // Arrange
            // Target day is 01.03.2016
            DateTime targetDay              = new DateTime(2016, 3, 1);
            int      targetEmployerID       = 1;
            List <EmployerTimeStamp> stamps = new List <EmployerTimeStamp>()
            {
                // In-stamp at 9.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(9)
                },

                // In-stamp at 11.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(9).AddMinutes(10)
                },

                // Out-stamp at 12.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(12)
                },

                // Out-stamp at 14.00 am of target day
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(14)
                },
            };
            int originalStampsCount = stamps.Count;
            DailyReportsManager      dailyReporter  = this.СreateDailyReporter(stamps);
            List <Notification>      notifications  = new List <Notification>();
            List <EmployerTimeStamp> expectedStamps = new List <EmployerTimeStamp>()
            {
                stamps[0],

                // Should be added! Out-stamp at 11.00 am of target day.
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.Out, Time = targetDay.AddHours(9).AddMinutes(5)
                },

                stamps[1],
                stamps[2],

                // Should be added! In-stamp at 13.00 am of target day.
                new EmployerTimeStamp()
                {
                    EmployerID = targetEmployerID, Type = StampType.In, Time = targetDay.AddHours(13)
                },

                stamps[3]
            };

            // Act
            dailyReporter.VerifyStampsSequence(stamps, targetEmployerID, targetDay, notifications);

            // Assertions
            // Check that collections contain same items in same order.
            Assert.That(stamps, Is.EqualTo(expectedStamps).Using(new EmployerTimeStampComparer()));
        }