public void ValidateWorkEvent_WhenNewWeek_ReturnTrue()
        {
            // week starts from Sunday
            var trackAction = new TrackWorkAction(string.Empty, null, 25, new DateTime(2019, 5, 19), this.address);

            Assert.True(this.trackerGuard.Validate(trackAction));
        }
        public void TrackWorkAction_MultipleTimes_AddsAllTrakedWork()
        {
            var      trackDate = DateTime.Now;
            var      track     = new TrackWorkAction(string.Empty, this.workTracker.Address, 5, trackDate, this.address);
            decimal  hours     = 0;
            DateTime date      = DateTime.MaxValue;

            this.workTracker.TrackedWork += (_, args) =>
            {
                hours += args.Hours;
                date   = args.Date;
            };

            this.permissionManager.ExecuteAction(track);

            Assert.Equal(5, hours);
            Assert.Equal(trackDate, date);

            trackDate = DateTime.Now;
            track     = new TrackWorkAction(string.Empty, this.workTracker.Address, 5, trackDate, this.address);

            this.permissionManager.ExecuteAction(track);

            Assert.Equal(10, hours);
            Assert.Equal(trackDate, date);

            trackDate = DateTime.Now;
            track     = new TrackWorkAction(string.Empty, this.workTracker.Address, 5, trackDate, this.address);

            this.permissionManager.ExecuteAction(track);

            Assert.Equal(15, hours);
            Assert.Equal(trackDate, date);
        }
        public void TrackWork_WhenGuarded_WhenFutureDate_ThrowsExeption()
        {
            this.InitializeEventLogAndGuards();
            var track = new TrackWorkAction(string.Empty, this.workTracker.Address, 25, DateTime.Today.AddDays(1),
                                            this.address);

            Assert.Throws <WorkTrackInvalidException>(() => this.permissionManager.ExecuteAction(track));
        }
        public void TrackWork_WhenGuarded_WhenHoursExeeds_ThrowsExeption()
        {
            this.InitializeEventLogAndGuards();
            var track = new TrackWorkAction(string.Empty, this.workTracker.Address, 25, new DateTime(2019, 5, 16),
                                            this.address);

            Assert.Throws <WorkTrackInvalidException>(() => this.permissionManager.ExecuteAction(track));
        }
        public void TrackWork_WhenGuarded_AddTrackedWork()
        {
            this.InitializeEventLogAndGuards();
            var track = new TrackWorkAction(string.Empty, this.workTracker.Address, 5, new DateTime(2019, 5, 16),
                                            this.address);

            this.permissionManager.ExecuteAction(track);
            Assert.Contains(new WorkEventArgs(5, new DateTime(2019, 5, 16), this.address), this.eventLog.EventsHistory);
        }
        public void RegisterEvent()
        {
            var track = new TrackWorkAction(string.Empty, this.workTracker.Address, 5, new DateTime(2019, 5, 16),
                                            this.address);

            this.permissionManager.ExecuteAction(track);
            Assert.Equal(5, this.eventLog.EventsHistory.Count);
            Assert.Contains(new WorkEventArgs(5, new DateTime(2019, 5, 16), this.address), this.eventLog.EventsHistory);
        }
        public void RegisterEvent_ShouldClearHistory()
        {
            var track = new TrackWorkAction(string.Empty, this.workTracker.Address, 5, DateTime.Today.AddDays(35),
                                            this.address);

            this.permissionManager.ExecuteAction(track);
            Assert.Single(this.eventLog.EventsHistory);
            Assert.Contains(new WorkEventArgs(5, DateTime.Today.AddDays(35), this.address),
                            this.eventLog.EventsHistory);
        }
        protected virtual bool HandleTrackWork(TrackWorkAction action)
        {
            if (this.CheckGuards(action))
            {
                var e = new WorkEventArgs(action.Hours, action.Date, action.Employee, action.TaskAddress);
                this.TrackedWork?.Invoke(this, e);
            }

            return(true);
        }
        public override bool Validate(TrackWorkAction action)
        {
            DateTime today    = action.Date;
            int      month    = today.Month;
            decimal  hoursSum = this.EventLog.EventsHistory
                                .Where(workEvent => (workEvent.Date.Month == month) &&
                                       workEvent.Employee.Equals(action.Employee))
                                .Select(args => args.Hours).Sum();

            return(hoursSum + action.Hours < this.HoursPerMonth);
        }
Beispiel #10
0
        private decimal TrackHours_ReturnsSplitterTrack(Address employee, Address task, decimal amount)
        {
            var track = new TrackWorkAction(string.Empty, this.workTracker.Address, amount, new DateTime(2019, 5, 16),
                                            employee, task);

            this.permissionManager.ExecuteAction(track);
            var hours         = this.splitterPerHours.GetTasksAddresToEmployeesHoursPerAddress();
            var employeeHours = hours.FirstOrDefault(x => x.Key.Equals(task)).Value
                                .Where(y => y.Key.Equals(employee)).First().Value;

            return(employeeHours);
        }
        protected virtual bool CheckGuards(TrackWorkAction action)
        {
            foreach (ITrackerGuard guard in this.TrackGuards)
            {
                if (!guard.Validate(action))
                {
                    throw new WorkTrackInvalidException(guard.GetType(), action);
                }
            }

            return(true);
        }
        public override bool Validate(TrackWorkAction action)
        {
            DateTime today     = action.Date;
            int      dayOfWeek = (int)today.DayOfWeek;
            decimal  hoursSum  = this.EventLog.EventsHistory
                                 .Where(workEvent =>
                                        (today.DayOfYear - workEvent.Date.DayOfYear <= dayOfWeek) &&
                                        workEvent.Employee.Equals(action.Employee))
                                 .Select(args => args.Hours).Sum();

            return(hoursSum + action.Hours < this.HoursPerWeek);
        }
        public void TrackWorkAction()
        {
            var      track = new TrackWorkAction(string.Empty, this.workTracker.Address, 5, DateTime.Today, this.address);
            decimal  hours = 0;
            DateTime date  = DateTime.MaxValue;

            this.workTracker.TrackedWork += (_, args) =>
            {
                hours = args.Hours;
                date  = args.Date;
            };

            this.permissionManager.ExecuteAction(track);

            Assert.Equal(5, hours);
            Assert.Equal(DateTime.Today, date);
        }
Beispiel #14
0
 public abstract bool Validate(TrackWorkAction action);
Beispiel #15
0
        public void ValidateWorkEvent_WhenHoursExeeds_ReturnFalse()
        {
            var trackAction = new TrackWorkAction(string.Empty, null, 25, new DateTime(2019, 5, 16), this.address);

            Assert.False(this.trackerGuard.Validate(trackAction));
        }
Beispiel #16
0
        public void ValidateWorkEvent()
        {
            var trackAction = new TrackWorkAction(string.Empty, null, 8, new DateTime(2019, 5, 16), this.address);

            Assert.True(this.trackerGuard.Validate(trackAction));
        }
 public bool Validate(TrackWorkAction action)
 {
     return(action.Date < DateTime.Now);
 }
 public WorkTrackInvalidException(Type guardType, TrackWorkAction action)
     : base($"{guardType.ToString()} failed to validate TrackWorkAction {{Date: {action.Date}, Hours: {action.Hours} }}.")
 {
 }
Beispiel #19
0
        public void ValidateWorkEvent_WhenInvalidDate_ReturnFalse()
        {
            var trackAction = new TrackWorkAction(string.Empty, null, 25, DateTime.Now.AddDays(1), this.address);

            Assert.False(this.trackerGuard.Validate(trackAction));
        }