public void ResultsMatchingTest()
        {
            var cObject = new CalculateAvailabilityCase
            {
                Src = new ObservationTime
                {
                    FullDayLeaves = new List <Interval <DateTime> >()
                    {
                        new Interval <DateTime>
                        {
                            Start = new DateTime(2018, 1, 1),
                            End   = new DateTime(2018, 1, 5)
                        }
                    },
                    ObservationInterval = new Interval <DateTime>
                    {
                        Start = new DateTime(2018, 1, 1),
                        End   = new DateTime(2018, 2, 1)
                    },
                    WeekWorkingDays = defaultWorkingDays
                },
                Result = new ExpectedResult <decimal>
                {
                    ShouldFail = false,
                    Value      = 19
                }
            };
            var wObject = new ObserveWorkingTime
            {
                WeekWorkingDays = defaultWorkingDays,
                Leaves          = new List <WorkingInterval>
                {
                    new WorkingInterval(8)
                    {
                        Start = new DateTime(2018, 1, 1),
                        End   = new DateTime(2018, 1, 5)
                    }
                },
                ObservationInterval = new WorkingInterval(8)
                {
                    Start = new DateTime(2018, 1, 1),
                    End   = new DateTime(2018, 2, 1)
                }
            };
            TimeSpan result = TimeSpan.Zero;

            Assert.DoesNotThrow(() => result = Manager.WorkAvailability(wObject));
            Assert.DoesNotThrow(() => Manager.CalculateAvailability(cObject.Src));
            Assert.AreEqual(Manager.CalculateAvailability(cObject.Src).TotalDays, Manager.TimeSpanToWorkingDays(wObject.ObservationInterval.HoursPerDay, result));
        }
        public void CalculateAvailability(CalculateAvailabilityCase tCase)
        {
            decimal result = 0;

            if (tCase.Result.ShouldFail)
            {
                Assert.Throws <Exception>(() => Manager.CalculateAvailability(tCase.Src));
            }
            else
            {
                Assert.DoesNotThrow(() => result =
                                        Convert.ToDecimal(Manager.CalculateAvailability(tCase.Src).TotalDays));
                Assert.AreEqual(result, tCase.Result.Value);
            }
        }
Example #3
0
        public IEnumerator GetEnumerator()
        {
            var obj1 = new CalculateAvailabilityCase
            {
                Src = new ObservationTime
                {
                    FullDayLeaves = new List <Interval <DateTime> >()
                    {
                        new Interval <DateTime>
                        {
                            Start = new DateTime(2018, 1, 1),
                            End   = new DateTime(2018, 1, 5)
                        }
                    },
                    ObservationInterval = new Interval <DateTime>
                    {
                        Start = new DateTime(2018, 1, 1),
                        End   = new DateTime(2018, 2, 1)
                    },
                    WeekWorkingDays = AvailabilityManagerTester.defaultWorkingDays
                },
                Result = new ExpectedResult <decimal>
                {
                    ShouldFail = false,
                    Value      = 19
                }
            };
            var obj2 = new CalculateAvailabilityCase
            {
                Src = new ObservationTime
                {
                    FullDayLeaves = new List <Interval <DateTime> >()
                    {
                        new Interval <DateTime>
                        {
                            Start = new DateTime(2018, 1, 2),
                            End   = new DateTime(2018, 1, 8)
                        }
                    },
                    ObservationInterval = new Interval <DateTime>
                    {
                        Start = new DateTime(2018, 1, 1),
                        End   = new DateTime(2018, 2, 1)
                    },
                    WeekWorkingDays = AvailabilityManagerTester.defaultWorkingDays
                },
                Result = new ExpectedResult <decimal>
                {
                    ShouldFail = false,
                    Value      = 19
                }
            };

            //var obj3 = new CalculateAvailabilityCase
            //{

            //    Src = new ObservationTime
            //    {
            //        FullDayLeaves = new List<Interval<DateTime>>() {
            //            new Interval<DateTime>
            //            {
            //                Start = new DateTime(2018, 1, 2),
            //                End = new DateTime(2018, 1, 8)
            //            }},
            //        ObservationInterval = new Interval<DateTime>
            //        {
            //            Start = new DateTime(2018, 1, 1),
            //            End = new DateTime(2018, 2, 1)
            //        },
            //        WeekWorkingDays = AvailabilityManagerTester.defaultWorkingDays
            //    },
            //    Result = new ExpectedResult<decimal>
            //    {
            //        ShouldFail = false,
            //        Value = 19
            //    }
            //};
            //var obj4 = new CalculateAvailabilityCase
            //{

            //};
            //var obj5 = new CalculateAvailabilityCase
            //{

            //};
            //var obj6 = new CalculateAvailabilityCase
            //{

            //};
            yield return
                (new TestCaseData(obj1).SetName("CalculateAvailability: " +
                                                JsonConvert.SerializeObject((object)obj1).Replace('.', ',')));

            yield return
                (new TestCaseData(obj2).SetName("CalculateAvailability: " +
                                                JsonConvert.SerializeObject((object)obj2).Replace('.', ',')));
            //yield return
            //    new TestCaseData(obj3).SetName("CalculateAvailability: " +
            //                                   JsonConvert.SerializeObject(obj3).Replace('.', ','));
            //yield return
            //    new TestCaseData(obj4).SetName("CalculateAvailability: " +
            //                                   JsonConvert.SerializeObject(obj4).Replace('.', ','));
            //yield return
            //    new TestCaseData(obj5).SetName("CalculateAvailability: " +
            //                                   JsonConvert.SerializeObject(obj3).Replace('.', ','));
            //yield return
            //    new TestCaseData(obj6).SetName("CalculateAvailability: " +
            //                                   JsonConvert.SerializeObject(obj4).Replace('.', ','));
        }