public void CustomHoliday_OccuredHolidaySettingChangedEventOnCustomHolidayObject_OccursHolidaySettingChangedEvent()
        {
            // arrange
            var hChecker      = (HolidayChecker_ja_JP)HolidayChecker.GetHolidayChecker("ja-JP");
            var customHoliday = new CustomHoliday();

            hChecker.CustomHoliday = customHoliday;

            bool actual = false;

            hChecker.HolidaySettingChanged += (sender, e) =>
            {
                if (e.PropertyName == nameof(CustomHoliday.Holidays))
                {
                    if (e.OriginalEventArgs is PropertyChangedEventArgs eventArgs)
                    {
                        if (sender == customHoliday && eventArgs.PropertyName == nameof(CustomHoliday.Holidays))
                        {
                            actual = true;
                        }
                    }
                }
            };

            // act
            hChecker.CustomHoliday.Holidays = new ObservableCollection <KeyValuePair <DateTime, string> >();

            // assert
            Assert.True(actual);
        }
        public void CustomHoliday_AddCustomHoliday_OccursHolidaySettingChangedEvent()
        {
            // arrange
            var hChecker = (HolidayChecker_ja_JP)HolidayChecker.GetHolidayChecker("ja-JP");

            hChecker.CustomHoliday          = new CustomHoliday();
            hChecker.CustomHoliday.Holidays = new ObservableCollection <KeyValuePair <DateTime, string> >();

            bool actual = false;

            hChecker.HolidaySettingChanged += (sender, e) =>
            {
                if (e.PropertyName == nameof(CustomHoliday.Holidays))
                {
                    if (e.OriginalEventArgs is NotifyCollectionChangedEventArgs eventArgs)
                    {
                        if (eventArgs.Action == NotifyCollectionChangedAction.Add)
                        {
                            actual = true;
                        }
                    }
                }
            };

            // act
            hChecker.CustomHoliday.Holidays.Add(new KeyValuePair <DateTime, string>(new DateTime(2020, 1, 1), "HolidayName"));

            // assert
            Assert.True(actual);
        }
        public void IsAddHolidayNameToObservedHolidayName_SetValue_OccursHolidaySettingChangedEvent()
        {
            // arrange
            var hChecker = (HolidayChecker_ja_JP)HolidayChecker.GetHolidayChecker("ja-JP");

            hChecker.IsAddHolidayNameToObservedHolidayName = false;

            bool actual = false;

            hChecker.HolidaySettingChanged += (sender, e) =>
            {
                if (e.PropertyName == nameof(HolidayChecker_ja_JP.IsAddHolidayNameToObservedHolidayName))
                {
                    if (e.OriginalEventArgs is PropertyChangedEventArgs eventArgs)
                    {
                        if (eventArgs.PropertyName == nameof(HolidayChecker_ja_JP.IsAddHolidayNameToObservedHolidayName))
                        {
                            actual = true;
                        }
                    }
                }
            };

            // act
            hChecker.IsAddHolidayNameToObservedHolidayName = true;

            // assert
            Assert.True(actual);
        }
        public void CustomHoliday_SetCustomHoliday_OccursHolidaySettingChangedEvent()
        {
            // arrange
            var hChecker = (HolidayChecker_ja_JP)HolidayChecker.GetHolidayChecker("ja-JP");

            bool actual = false;

            hChecker.HolidaySettingChanged += (sender, e) =>
            {
                if (e.PropertyName == nameof(HolidayChecker_ja_JP.CustomHoliday))
                {
                    if (e.OriginalEventArgs is PropertyChangedEventArgs eventArgs)
                    {
                        if (eventArgs.PropertyName == nameof(HolidayChecker_ja_JP.CustomHoliday))
                        {
                            actual = true;
                        }
                    }
                }
            };

            // act
            hChecker.CustomHoliday = new CustomHoliday();

            // assert
            Assert.True(actual);
        }
        public void CustomHoliday_SetNull_ThrowsNoException()
        {
            // arrange
            var hChecker = (HolidayChecker_ja_JP)HolidayChecker.GetHolidayChecker("ja-JP");

            // act
            // assert
            hChecker.CustomHoliday = null;
        }
        public void GetHolidayName_NotHolidayDateTime_ReturnsNull(DateTime date)
        {
            // arrange
            var hChecker = (HolidayChecker_ja_JP)HolidayChecker.GetHolidayChecker("ja-JP");

            // act
            var actual = hChecker.GetHolidayName(date);

            // assert
            Assert.Null(actual);
        }
        public void CustomHoliday_SetNullAfterSetOnce_ThrowsInvalidOperaionException()
        {
            // arrange
            var hChecker = (HolidayChecker_ja_JP)HolidayChecker.GetHolidayChecker("ja-JP");

            hChecker.CustomHoliday = new CustomHoliday();

            // act
            // assert
            Assert.Throws <InvalidOperationException>(() => { hChecker.CustomHoliday = null; });
        }
        public void GetHolidayName_IsAddHolidayNameToObservedHolidayName_ReturnsAddedName(DateTime date, string addedName)
        {
            // arrange
            var hChecker = (HolidayChecker_ja_JP)HolidayChecker.GetHolidayChecker("ja-JP");

            hChecker.IsAddHolidayNameToObservedHolidayName = true;

            // act
            var actual = hChecker.GetHolidayName(date);

            // assert
            Assert.Equal(addedName, actual);
        }
        public void GetHolidayName_HolidayDateTime_ReturnsCorrectlyName(DateTime date, string expectedHolidayName)
        {
            // arrange
            var hChecker = (HolidayChecker_ja_JP)HolidayChecker.GetHolidayChecker("ja-JP");

            hChecker.IsAddHolidayNameToObservedHolidayName = false;

            // act
            var actualHolidayName = hChecker.GetHolidayName(date);

            // assert
            Assert.Equal(expectedHolidayName, actualHolidayName);
        }
Exemplo n.º 10
0
        public void GetCalendar_YearAndMonthArgs_CollectCalendar(int year, int month, int[,] days, bool[,] isHoliday, bool[,] isThisMonth, int lastRow)
        {
            // arrange

            // act
            Calendar.GetCalendar(year, month, HolidayChecker.GetHolidayChecker("ja-JP"), out int[,] actualDays, out bool[,] actualIsHoliday, out bool[,] actualIsThisMonth, out int actualLastRow);

            // assert
            Assert.Equal(days, actualDays);
            Assert.Equal(isHoliday, actualIsHoliday);
            Assert.Equal(isThisMonth, actualIsThisMonth);
            Assert.Equal(lastRow, actualLastRow);
        }
Exemplo n.º 11
0
        /// <summary>
        /// MainWindow のコンストラクター。
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();


            var customHoliday = new CustomHoliday();

            customHoliday.Holidays = CustomHolidaysParser.Deserialize(Properties.Settings.Default.CustumHolidaysString);

            var dtEvtSrc = new DateTimeEventSource()
            {
                HolidayChecker = HolidayChecker.GetHolidayChecker()
            };

            dtEvtSrc.HolidayChecker.CustomHoliday = customHoliday;
            if (dtEvtSrc.HolidayChecker is HolidayChecker_ja_JP hc_ja_JP)
            {
                hc_ja_JP.IsAddHolidayNameToObservedHolidayName = true;
            }

            // カレンダー ウィンドウの生成
            var calendarWindow = new CalendarWindow();

            viewModel = new MainWindowViewModel(this.Dispatcher, calendarWindow.Dispatcher)
            {
                DateTimeEventSource          = dtEvtSrc,
                PrimaryScreenSizeEventSource = new PrimaryScreenSizeEventSource(),
                SettingsWrapper = new SettingsWrapper()
                {
                    Settings = Properties.Settings.Default
                }
            };

            viewModel.VerticalAlignment                   = (VerticalAlignment)Properties.Settings.Default.VerticalAlignment;
            viewModel.HorizontalAlignment                 = (HorizontalAlignment)Properties.Settings.Default.HorizontalAlignment;
            viewModel.VerticalMarginNumber                = Properties.Settings.Default.VerticalMarginNumber;
            viewModel.IsPercentVertical                   = Properties.Settings.Default.IsPercentVertical;
            viewModel.HorizontalMarginNumber              = Properties.Settings.Default.HorizontalMarginNumber;
            viewModel.IsPercentHorizontal                 = Properties.Settings.Default.IsPercentHorizontal;
            viewModel.ConsecutiveHolidaysMessageFormat    = (string)Application.Current.FindResource("CONSECTIVE_HOLIDAYS_MESSAGE_TOMMOROW");
            viewModel.ConsecutiveHolidaysMessageDATFormat = (string)Application.Current.FindResource("CONSECTIVE_HOLIDAYS_MESSAGE_DAT");

            this.DataContext = viewModel;

            // カレンダー ウィンドウの表示
            calendarWindow.DataContext = viewModel;
            calendarWindow.Show();
        }
        public void GetHolidayName_IfNomalDayAndCustomHoliday_RerturnsCustomHolidayName()
        {
            // arrange
            var hChecker = (HolidayChecker_ja_JP)HolidayChecker.GetHolidayChecker("ja-JP");

            hChecker.CustomHoliday          = new CustomHoliday();
            hChecker.CustomHoliday.Holidays = new ObservableCollection <KeyValuePair <DateTime, string> >();

            var targetDate  = new DateTime(2020, 1, 2);
            var defaultName = hChecker.GetHolidayName(targetDate);

            hChecker.CustomHoliday.Holidays.Add(new KeyValuePair <DateTime, string>(targetDate, "HolidayName"));


            // act
            var actual = hChecker.GetHolidayName(targetDate);

            // assert
            Assert.Null(defaultName);
            Assert.Equal("HolidayName", actual);
        }