Exemple #1
0
        /// <summary>
        /// GetAvailableCalendars gets an array of .NET calendars available to the Culture
        /// </summary>
        /// <param name="culture">The Culture to get the Calendars for</param>
        /// <returns>An array of .NET calendars available to the Culture</returns>
        /// <remarks>The list is filtered to include only those .NET Calendars that can be used
        /// with custom cultures</remarks>
        private static System.Globalization.Calendar[] GetAvailableCalendars(Culture culture)
        {
            if (culture.Dates == null || culture.Dates.Calendars == null)
            {
                return(null);
            }

            List <System.Globalization.Calendar> availableCalendars = new List <System.Globalization.Calendar>();

            // the order of the calendars is important - the default calendar must be the first calendar in the list
            foreach (Types.Calendar calendar in culture.Dates.Calendars.OrderBy(c => c.Id != culture.Dates.DefaultCalendarId))
            {
                System.Globalization.Calendar dotNetCalendar = GetCalendar(calendar);

                // The CultureAndRegionInfoBuilder.AvailableCalendars property does not allow
                // certain types of calendars to be included in the array assigned to it
                if (dotNetCalendar != null &&
                    dotNetCalendar.GetType() != typeof(PersianCalendar) &&
                    dotNetCalendar.GetType() != typeof(TaiwanLunisolarCalendar) &&
                    dotNetCalendar.GetType() != typeof(KoreanLunisolarCalendar) &&
                    dotNetCalendar.GetType() != typeof(JapaneseLunisolarCalendar) &&
                    dotNetCalendar.GetType() != typeof(ChineseLunisolarCalendar) &&
                    dotNetCalendar.GetType() != typeof(JulianCalendar))
                {
                    availableCalendars.Add(dotNetCalendar);
                }
            }

            return(availableCalendars.ToArray());
        }
Exemple #2
0
 /// <summary>
 /// Tries to work out a roughly-matching calendar system for the given BCL calendar.
 /// This is needed where we're testing whether days of the week match - even if we can
 /// get day/month/year values to match without getting the calendar right, the calendar
 /// affects the day of week.
 /// </summary>
 internal static CalendarSystem CalendarSystemForCalendar(Calendar bcl)
 {
     // Yes, this is horrible... but the specific calendars aren't available to test
     // against in the PCL
     switch (bcl.GetType().Name)
     {
         case "GregorianCalendar": return CalendarSystem.Iso;
         case "HijriCalendar": return CalendarSystem.IslamicBcl;
         case "HebrewCalendar": return CalendarSystem.HebrewCivil;
         case "PersianCalendar": return bcl.IsLeapYear(1) ? CalendarSystem.PersianSimple : CalendarSystem.PersianAstronomical;
         case "UmAlQuraCalendar": return CalendarSystem.UmAlQura;
         case "JulianCalendar":
             return CalendarSystem.Julian;
         default:
             // No idea - we can't test with this calendar...
             return null;
     }
 }
Exemple #3
0
        /// <summary>
        /// GetAvailableCalendars gets an array of .NET calendars available to the Culture
        /// </summary>
        /// <param name="culture">The Culture to get the Calendars for</param>
        /// <returns>An array of .NET calendars available to the Culture</returns>
        /// <remarks>The list is filtered to include only those .NET Calendars that can be used
        /// with custom cultures</remarks>
        private static System.Globalization.Calendar[] GetAvailableCalendars(Culture culture)
        {
            if (culture.Dates == null || culture.Dates.Calendars == null)
            {
                return(null);
            }

            List <System.Globalization.Calendar> availableCalendars = new List <System.Globalization.Calendar>();

            Types.Calendar[] allCalendars = null;
            if (culture.Identity.Region != null)
            {
                string[] calendarPreferenceIds = RegionExtensions.GetCalendarPreferenceIds(culture.Identity.Region.Id);
                if (calendarPreferenceIds != null)
                {
                    allCalendars = (from cpi in calendarPreferenceIds
                                    select(from c in culture.Dates.Calendars
                                           where c.Id == cpi
                                           select c).FirstOrDefault()).ToArray();
                }
            }

            if (allCalendars == null)
            {
                allCalendars = culture.Dates.Calendars;
            }

            foreach (Types.Calendar calendar in allCalendars)
            {
                System.Globalization.Calendar dotNetCalendar = GetCalendar(calendar);

                // The CultureAndRegionInfoBuilder.AvailableCalendars property does not allow
                // certain types of calendars to be included in the array assigned to it
                if (dotNetCalendar != null &&
                    dotNetCalendar.GetType() != typeof(PersianCalendar) &&
                    dotNetCalendar.GetType() != typeof(TaiwanLunisolarCalendar) &&
                    dotNetCalendar.GetType() != typeof(KoreanLunisolarCalendar) &&
                    dotNetCalendar.GetType() != typeof(JapaneseLunisolarCalendar) &&
                    dotNetCalendar.GetType() != typeof(ChineseLunisolarCalendar) &&
                    dotNetCalendar.GetType() != typeof(JulianCalendar))
                {
                    availableCalendars.Add(dotNetCalendar);
                }
            }

            return(availableCalendars.ToArray());
        }
Exemple #4
0
	public void TestDaysInYear (Calendar calendar, int year)
	{
		var daysInYear = calendar.GetDaysInYear (year);
		var daysInMonths = 0;
		var monthInYear = calendar.GetMonthsInYear (year);
		for (var m = 1; m <= monthInYear; m++)
			daysInMonths += calendar.GetDaysInMonth (year, m);

		Assert.AreEqual (daysInYear, daysInMonths, string.Format("Calendar:{0} Year:{1}",calendar.GetType(), year));
	}
 private static string CalendarToString(Calendar calendar)
 {
     var algorithmType = calendar.AlgorithmType.ToString().Replace("Calendar", "");
     if (calendar.GetType() == typeof(GregorianCalendar))
     {
         var gregorianCalendar = (GregorianCalendar)calendar;
         return string.Format("Gregorian-{0} ({1})", gregorianCalendar.CalendarType, algorithmType);
     }
     return string.Format("{0} ({1})", calendar.ToString().Replace("System.Globalization.", "").Replace("Calendar", ""), algorithmType);
 }
        /// <summary>
        /// Returns the day of week based on calendar.
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="calendar"></param>
        /// <returns></returns>
        public static int GetDayOfWeek(DateTime dt, Calendar calendar)
        {
            var calendarType = calendar.GetType();
            if (calendarType == typeof (PersianCalendar) ||
                calendarType == typeof (System.Globalization.PersianCalendar))
            {
                return PersianDateTimeFormatInfo.GetDayIndex(dt.DayOfWeek);
            }

            return (int) dt.DayOfWeek;
        }
 public static void CloningTest(Calendar calendar, int yearHasLeapMonth, CalendarAlgorithmType algorithmType)
 {
     Calendar cloned = (Calendar) calendar.Clone();
     Assert.Equal(calendar.GetType(), cloned.GetType());
 }
Exemple #8
0
        public void Calendar_AutomationPeer()
        {
            Calendar calendar = new Calendar();
            Assert.IsNotNull(calendar);
            calendar.Height = 200;
            calendar.Width = 200;
            _isLoaded = false;
            DateTime date = new DateTime(2000, 2, 2);
            calendar.DisplayDate = date;
            calendar.SelectedDate = date;

            calendar.Loaded += new RoutedEventHandler(calendar_Loaded);
            CalendarAutomationPeer peer = ((CalendarAutomationPeer)CalendarAutomationPeer.CreatePeerForElement(calendar));
            Assert.IsNotNull(peer);

            TestPeer testPeer = new TestPeer(calendar);
            Assert.IsNotNull(testPeer);

            TestPanel.Children.Add(calendar);
            EnqueueConditional(IsLoaded);
            EnqueueCallback(delegate
            {
                Assert.AreEqual(peer.GetAutomationControlType(), AutomationControlType.Calendar, "Incorrect Control type for calendar");
                Assert.AreEqual(peer.GetClassName(), calendar.GetType().Name, "Incorrect ClassName value for Calendar");
                Assert.AreEqual(peer.GetName(), date.ToString(), "Incorrect Name value for CalendarPeer");
                Assert.IsTrue(peer.IsContentElement(), "Incorrect IsContentElement value");
                Assert.IsTrue(peer.IsControlElement(), "Incorrect IsControlElement value");

                #region CalendarAutomationPeer IGridProvider tests:

                IGridProvider calendarGridProvider = ((IGridProvider)peer.GetPattern(PatternInterface.Grid));
                Assert.IsNotNull(calendarGridProvider, "Incorrect calendarGridProvider value");
                Assert.AreEqual(calendar.MonthControl.MonthView.RowDefinitions.Count - 1, calendarGridProvider.RowCount, "Incorrect RowCount value");
                Assert.AreEqual(calendar.MonthControl.MonthView.ColumnDefinitions.Count, calendarGridProvider.ColumnCount, "Incorrect ColumnCount value");

                IRawElementProviderSimple cell = calendarGridProvider.GetItem(0, 3);
                Assert.IsNotNull(cell, "GetItem returned null for valid cell");
                AutomationPeer cellPeer = testPeer.GetPeerFromProvider(cell);
                Assert.AreEqual(typeof(CalendarDayButton).Name, cellPeer.GetClassName(), "GetItem did not return DayButton");

                calendar.DisplayMode = CalendarMode.Year;
                Assert.AreEqual(calendar.MonthControl.YearView.RowDefinitions.Count, calendarGridProvider.RowCount, "Incorrect RowCount value");
                Assert.AreEqual(calendar.MonthControl.YearView.ColumnDefinitions.Count, calendarGridProvider.ColumnCount, "Incorrect ColumnCount value");

                cell = calendarGridProvider.GetItem(2, 3);
                Assert.IsNotNull(cell, "GetItem returned null for valid cell");
                cellPeer = testPeer.GetPeerFromProvider(cell);
                Assert.AreEqual(typeof(CalendarButton).Name, cellPeer.GetClassName(), "GetItem did not return CalendarButton");

                calendar.DisplayMode = CalendarMode.Decade;
                Assert.AreEqual(calendar.MonthControl.YearView.RowDefinitions.Count, calendarGridProvider.RowCount, "Incorrect RowCount value");
                Assert.AreEqual(calendar.MonthControl.YearView.ColumnDefinitions.Count, calendarGridProvider.ColumnCount, "Incorrect ColumnCount value");

                cell = calendarGridProvider.GetItem(2, 3);
                Assert.IsNotNull(cell, "GetItem returned null for valid cell");
                cellPeer = testPeer.GetPeerFromProvider(cell);
                Assert.AreEqual(typeof(CalendarButton).Name, cellPeer.GetClassName(), "GetItem did not return CalendarButton");

                cell = calendarGridProvider.GetItem(10, 10);
                Assert.IsNull(cell, "GetItem returned object for invalid cell");

                #endregion

                #region CalendarAutomationPeer IMultipleViewProvider tests:
                calendar._hasFocus = true;
                IMultipleViewProvider calendarMultiViewProvider = ((IMultipleViewProvider)peer.GetPattern(PatternInterface.MultipleView));
                Assert.IsNotNull(calendarMultiViewProvider);
                Assert.IsTrue(calendarMultiViewProvider.CurrentView == (int)CalendarMode.Decade);
                Assert.IsTrue(CalendarMode.Decade.ToString() == calendarMultiViewProvider.GetViewName(calendarMultiViewProvider.CurrentView));
                calendarMultiViewProvider.SetCurrentView((int)CalendarMode.Year);
                Assert.IsTrue(calendar.DisplayMode == CalendarMode.Year);
                Assert.IsTrue(calendarMultiViewProvider.CurrentView == (int)CalendarMode.Year);
                Assert.IsTrue(CalendarMode.Year.ToString() == calendarMultiViewProvider.GetViewName(calendarMultiViewProvider.CurrentView));

                #endregion

                #region CalendarAutomationPeer ISelectionProvider tests:
                ISelectionProvider calendarSelectionProvider = ((ISelectionProvider)peer.GetPattern(PatternInterface.Selection));
                Assert.IsNotNull(calendarSelectionProvider);
                Assert.IsFalse(calendarSelectionProvider.IsSelectionRequired, "Incorrect IsSelectionRequired value");
                Assert.IsFalse(calendarSelectionProvider.CanSelectMultiple, "Incorrect CanSelectMultiple value");
                calendar.SelectionMode = CalendarSelectionMode.MultipleRange;
                Assert.IsNull(calendar.SelectedDate);
                Assert.IsTrue(calendarSelectionProvider.CanSelectMultiple, "Incorrect CanSelectMultiple value");
                calendar.SelectedDates.AddRange(new DateTime(2000, 2, 10), new DateTime(2000, 3, 30));

                IRawElementProviderSimple[] selection = calendarSelectionProvider.GetSelection();
                Assert.IsNotNull(selection, "GetSelection returned null for valid selection");
                Assert.AreEqual(selection.Length, 1, "GetSelection returned wrong number of selections");
                cellPeer = testPeer.GetPeerFromProvider(selection[0]);
                Assert.AreEqual(cellPeer.GetClassName(), typeof(CalendarButton).Name, "Incorrect name for CalendarButton");

                calendar.DisplayMode = CalendarMode.Month;
                selection = calendarSelectionProvider.GetSelection();
                Assert.IsNotNull(selection, "GetSelection returned null for valid selection");
                Assert.AreEqual(selection.Length, 31, "GetSelection returned wrong number of selections");
                cellPeer = testPeer.GetPeerFromProvider(selection[0]);
                Assert.AreEqual(cellPeer.GetClassName(), typeof(CalendarDayButton).Name, "Incorrect name for DayButton");
                #endregion

                #region CalendarAutomationPeer ITableProvider tests:

                ITableProvider calendarTableProvider = ((ITableProvider)peer.GetPattern(PatternInterface.Table));
                Assert.IsNotNull(calendarTableProvider);
                Assert.AreEqual(calendarTableProvider.RowOrColumnMajor, RowOrColumnMajor.RowMajor, "Incorrect RowOrColumnMajor value");

                IRawElementProviderSimple[] headers = calendarTableProvider.GetRowHeaders();
                Assert.IsNull(headers, "GetRowHeaders should return null");

                headers = calendarTableProvider.GetColumnHeaders();
                Assert.IsNotNull(headers, "GetColumnHeaders returned null");
                Assert.AreEqual(headers.Length, 7, "Incorrect number of column headers");
                #endregion

            });
            EnqueueTestComplete();
        }