Пример #1
0
        public IPublicHolidayCalculator GetCalculator(PublicHoliday holiday)
        {
            IPublicHolidayCalculator calculator = null;

            switch (holiday.HolidayType)
            {
            case PublicHolidayType.FixedDate:
                calculator = new FixedDayCalculator();
                break;

            case PublicHolidayType.BasedOnAnotherHoliday:
                calculator = new BasedOnOtherHolidayCalculator();
                break;

            case PublicHolidayType.RepeatEveryXYear:
                calculator = new YearRepetitionCalculator();
                break;

            case PublicHolidayType.Easter:
                calculator = new EasterCalculator();
                break;

            case PublicHolidayType.SpecificDayInWeek:
                calculator = new SpecificWeekDayCalculator();
                break;

            default:
                throw new ArgumentException();
            }

            return(calculator);
        }
        public void GetPublicHolidayByYears_WhenPassedYearsAndHolidays_ThenReturnsExpectedDateList(List <int> years, PublicHoliday holiday, List <DateTime> expectedResult)
        {
            // Arrange
            var target = new BasedOnOtherHolidayCalculator();

            // Act
            var actual = target.GetPublicHolidayByYears(years, holiday);

            // Assert
            actual.Should().BeEquivalentTo(expectedResult);
        }
        public void GetPublicHolidayByYears_WhenNullNumberOfDaysFromReference_ThenThrows()
        {
            // Arrange
            var target  = new BasedOnOtherHolidayCalculator();
            var holiday = new PublicHoliday {
                Name = "Name", ReferenceHolidayName = "ReferenceName", NumberOfDaysFromReference = null
            };

            // Act
            Action actual = () => target.GetPublicHolidayByYears(null, holiday);

            // Assert
            actual.Should().Throw <ArgumentException>().WithMessage("You cannot have an empty NumberOfDaysFromReference for BasedOnOtherHoliday types.");
        }
        public void GetPublicHolidayByYears_WhenNullName_ThenThrows()
        {
            // Arrange
            var target  = new BasedOnOtherHolidayCalculator();
            var holiday = new PublicHoliday {
                Name = null
            };

            // Act
            Action actual = () => target.GetPublicHolidayByYears(null, holiday);

            // Assert
            actual.Should().Throw <ArgumentException>().WithMessage("Cannot process a custom holidays without a name.");
        }