Exemplo n.º 1
0
        public AttendanceListData(IDaysOffData daysOff, IList <IPerson> people, Month month, int year)
        {
            if (daysOff == null || daysOff.Year != year)
            {
                throw new ArgumentException("Days off data cannot be null and its year must be the same as passed in this constructor");
            }

            if (people == null || people.Count > _maxNumberOfFullnames)
            {
                throw new ArgumentException("People list should contain and at most 7 people");
            }

            if (month == Month.None)
            {
                throw new ArgumentException("Month cannot be 'None'");
            }

            if (year < 1900 || year > 2100)
            {
                throw new ArgumentOutOfRangeException("Year should be between 1900 and 2100");
            }

            _daysOffData = daysOff;

            People = people;
            Days   = new List <IDay>(_maxNumberOfDaysInAMonth);
            Month  = month;
            Year   = year;

            CreateListOfDays();
        }
        public void Constructor_CorrectMonth_ObjectsMonthIsEqualToGivenMonth(Month month)
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2019);

            AttendanceListData listData = new AttendanceListData(daysOff, GetListOfPeople(), month, 2019);

            Assert.That(listData.Month, Is.EqualTo(month));
        }
        public void Constructor_Year1900And2100_DoesNotThrowArgumentOutOfRangeException(int year)
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == year);

            TestDelegate constructor = () => new AttendanceListData(daysOff, GetListOfPeople(), Month.January, year);

            Assert.That(constructor, Throws.Nothing);
        }
        public void Constructor_February2020LeapYear_CreateListOf29Days()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2020);

            AttendanceListData listData = new AttendanceListData(daysOff, GetListOfPeople(), Month.February, 2020);

            Assert.That(listData.Days.Count, Is.EqualTo(29));
        }
        public void Constructor_IDaysOffDataWithAnotherYearThanPassedInConstructor_ThrowsArgumentException()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2018);

            TestDelegate constructor = () => new AttendanceListData(daysOff, GetListOfPeople(), Month.January, 2019);

            Assert.That(constructor, Throws.ArgumentException);
        }
        public void Constructor_NoneMonth_ThrowsArgumentException()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2019);

            TestDelegate constructor = () => new AttendanceListData(daysOff, GetListOfPeople(), Month.None, 2019);

            Assert.That(constructor, Throws.ArgumentException);
        }
        public void Constructor_NullPeopleList_ThrowsArgumentException()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2019);

            TestDelegate constructor = () => new AttendanceListData(daysOff, null, Month.January, 2019);

            Assert.That(constructor, Throws.ArgumentException);
        }
        public void MaxNumberOfFullnames_CorrectData_MaxNumberOfFullnamesIsEqualTo7()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2019);

            AttendanceListData listData = new AttendanceListData(daysOff, GetListOfPeople(), Month.January, 2019);

            Assert.That(listData.MaxNumberOfFullnames, Is.EqualTo(7));
        }
        public void Constructor_CorrectYear_ObjectsYearIsEqualToGivenYear(int year)
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == year);

            AttendanceListData listData = new AttendanceListData(daysOff, GetListOfPeople(), Month.January, year);

            Assert.That(listData.Year, Is.EqualTo(year));
        }
        public void Constructor_YearLessThan1900OrAbove2100_ThrowsArgumentOutOfRangeException(int year)
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == year);

            TestDelegate constructor = () => new AttendanceListData(daysOff, GetListOfPeople(), Month.January, year);

            Assert.That(constructor, Throws.InstanceOf <ArgumentOutOfRangeException>());
        }
        public void Constructor_August2024_CreatesListOf31Days()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2024);

            AttendanceListData listData = new AttendanceListData(daysOff, GetListOfPeople(), Month.August, 2024);

            Assert.That(listData.Days.Count, Is.EqualTo(31));
        }
        public void Constructor_CorrectPeopleList_ObjectsPeopleListIsEqualToGivenList()
        {
            IDaysOffData    daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2019);
            IList <IPerson> people  = GetListOfPeople();

            AttendanceListData monthData = new AttendanceListData(daysOff, people, Month.January, 2019);

            Assert.That(monthData.People, Is.EqualTo(people));
        }
        public void Constructor_June2019_FourteenthDayIsNotAHoliday()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2019);

            AttendanceListData listData = new AttendanceListData(daysOff, GetListOfPeople(), Month.January, 2019);
            IDay day = listData.Days[13];

            Assert.That(day.Holiday, Is.EqualTo(Holiday.None));
        }
        public void Constructor_August2024_LastDayIsSaturday()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2024);

            AttendanceListData listData = new AttendanceListData(daysOff, GetListOfPeople(), Month.August, 2024);
            IDay lastDay = listData.Days.LastOrDefault();

            Assert.That(lastDay.DayOfWeek, Is.Not.Null.And.EqualTo(DayOfWeek.Saturday));
        }
        public void Constructor_February2020LeapYear_FirstDayIsSaturday()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2020);

            AttendanceListData listData = new AttendanceListData(daysOff, GetListOfPeople(), Month.February, 2020);
            IDay firstDay = listData.Days.FirstOrDefault();

            Assert.That(firstDay.DayOfWeek, Is.Not.Null.And.EqualTo(DayOfWeek.Saturday));
        }
        public void Constructor_June2019_TwentythDayIsCorpusChristiDay()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2019 &&
                                                          d.GetDaysOff(Month.January) == new List <IDayOff>
            {
                Mock.Of <IDayOff>(x => x.Date == new DateTime(2019, 8, 9) && x.Holiday == Holiday.DescendOfTheHolySpirit),
                Mock.Of <IDayOff>(x => x.Date == new DateTime(2019, 8, 20) && x.Holiday == Holiday.CorpusChristi),
            });
            AttendanceListData listData = new AttendanceListData(daysOff, GetListOfPeople(), Month.January, 2019);
            IDay day = listData.Days[19];

            Assert.That(day.Holiday, Is.EqualTo(Holiday.CorpusChristi));
        }
        public void Constructor_January2019_SixthDayIsEpiphany()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2019 &&
                                                          d.GetDaysOff(Month.January) == new List <IDayOff>
            {
                Mock.Of <IDayOff>(x => x.Date == new DateTime(2019, 1, 1) && x.Holiday == Holiday.NewYearsDay),
                Mock.Of <IDayOff>(x => x.Date == new DateTime(2019, 1, 6) && x.Holiday == Holiday.Epiphany),
            });
            AttendanceListData listData = new AttendanceListData(daysOff, GetListOfPeople(), Month.January, 2019);
            IDay day = listData.Days[5];

            Assert.That(day.Holiday, Is.EqualTo(Holiday.Epiphany));
        }
        public void Constructor_ListOf8People_ThrowsArgumentException()
        {
            IDaysOffData    daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2019);
            IList <IPerson> people  = new List <IPerson>
            {
                Mock.Of <IPerson>(),
                Mock.Of <IPerson>(),
                Mock.Of <IPerson>(),
                Mock.Of <IPerson>(),
                Mock.Of <IPerson>(),
                Mock.Of <IPerson>(),
                Mock.Of <IPerson>(),
                Mock.Of <IPerson>()
            };

            TestDelegate constructor = () => new AttendanceListData(daysOff, people, Month.January, 2019);

            Assert.That(constructor, Throws.ArgumentException);
        }
        private AttendanceListData GetAttendanceListData()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2019);

            return(new AttendanceListData(daysOff, GetListOfPeople(), Month.February, 2019));
        }