Esempio n. 1
0
        public void ThrowsErrorWhenPersonIsInvalid()
        {
            LeaveRequest oldRequest = GenerateRequest();
            LeaveRequest newRequest = oldRequest.Copy();

            newRequest.PersonId = Guid.NewGuid();

            var ex = Assert.Throws <UnauthorizedAccessException>(() =>
                                                                 LeaveService.ThrowIfHrRequiredForUpdate(oldRequest, newRequest, new List <Holiday>()));

            ex.Message.ShouldContain("change the person");
        }
Esempio n. 2
0
        public void ThrowsIfChangingApproved()
        {
            LeaveRequest oldRequest = GenerateRequest();
            LeaveRequest newRequest = oldRequest.Copy();

            oldRequest.Approved = false;
            newRequest.Approved = true;
            var ex = Assert.Throws <UnauthorizedAccessException>(() =>
                                                                 LeaveService.ThrowIfHrRequiredForUpdate(oldRequest, newRequest, new List <Holiday>()));

            Assert.Contains("approve", ex.Message);
        }
Esempio n. 3
0
        public void ThrowsWhenChangingStartAndEndForOverridenDays()
        {
            LeaveRequest oldRequest = GenerateRequest();

            oldRequest.OverrideDays = true;
            LeaveRequest newRequest = oldRequest.Copy();

            newRequest.EndDate += TimeSpan.FromDays(4);

            var ex = Assert.Throws <UnauthorizedAccessException>(() =>
                                                                 LeaveService.ThrowIfHrRequiredForUpdate(oldRequest, newRequest, new List <Holiday>()));

            Assert.Contains("modify the start or end", ex.Message);
        }
Esempio n. 4
0
        public void ThrowsWhenChangingDaysWhenOverriden()
        {
            LeaveRequest oldRequest = GenerateRequest();

            oldRequest.OverrideDays = true;
            LeaveRequest newRequest = oldRequest.Copy();

            newRequest.Days++;

            var ex = Assert.Throws <UnauthorizedAccessException>(() =>
                                                                 LeaveService.ThrowIfHrRequiredForUpdate(oldRequest, newRequest, new List <Holiday>()));

            Assert.Contains("modify the length", ex.Message);
        }
Esempio n. 5
0
        public void AcceptMissmatchedCalculationForHalfDays()
        {
            LeaveRequest oldRequest = GenerateRequest();

            //16th is a friday
            oldRequest.StartDate = new DateTime(2018, 3, 16);
            oldRequest.EndDate   = new DateTime(2018, 3, 16);
            oldRequest.Days      = oldRequest.CalculateLength();
            LeaveRequest newRequest = oldRequest.Copy();

            newRequest.Days = 0.5m;
            //does not throw
            LeaveService.ThrowIfHrRequiredForUpdate(oldRequest, newRequest, new List <Holiday>());
        }
Esempio n. 6
0
        public void DontMissmatchedCalculationForHalfDaysOnWeekend()
        {
            LeaveRequest oldRequest = GenerateRequest();

            //17th is a saturday
            oldRequest.StartDate = new DateTime(2018, 3, 17);
            oldRequest.EndDate   = new DateTime(2018, 3, 17);
            oldRequest.Days      = oldRequest.CalculateLength();
            LeaveRequest newRequest = oldRequest.Copy();

            newRequest.Days = 0.5m;
            //does not throw
            Assert.Throws <UnauthorizedAccessException>(() =>
                                                        LeaveService.ThrowIfHrRequiredForUpdate(oldRequest, newRequest, new List <Holiday>()));
        }
Esempio n. 7
0
        public void ThrowsErrorWhenPersonIsInvalid()
        {
            var          personId   = Guid.NewGuid();
            LeaveRequest oldRequest = GenerateRequest();
            LeaveRequest newRequest = oldRequest.Copy();
            var          ex         = Assert.Throws <UnauthorizedAccessException>(() =>
                                                                                  _leaveService.ThrowIfHrRequiredForUpdate(oldRequest, newRequest, personId));

            Assert.Contains("modify this leave request", ex.Message);

            personId            = oldRequest.PersonId;
            newRequest.PersonId = Guid.NewGuid();
            ex = Assert.Throws <UnauthorizedAccessException>(() =>
                                                             _leaveService.ThrowIfHrRequiredForUpdate(oldRequest, newRequest, personId));
            Assert.Contains("modify this leave request", ex.Message);
        }
Esempio n. 8
0
        public void ThrowsWhenChangingTheDays()
        {
            LeaveRequest oldRequest = GenerateRequest();
            LeaveRequest newRequest = oldRequest.Copy();

            newRequest.Days--;

            var ex = Assert.Throws <UnauthorizedAccessException>(() =>
                                                                 LeaveService.ThrowIfHrRequiredForUpdate(oldRequest, newRequest, new List <Holiday>()));

            Assert.Contains("must match calculated", ex.Message);

            newRequest.Days     = newRequest.CalculateLength();
            newRequest.EndDate += TimeSpan.FromDays(4);
            ex = Assert.Throws <UnauthorizedAccessException>(() =>
                                                             LeaveService.ThrowIfHrRequiredForUpdate(oldRequest, newRequest, new List <Holiday>()));

            Assert.Contains("must match calculated", ex.Message);
        }