Browse Source

Fix: BlackoutDates test was failing

- Revert listen to colleciton changes as the collection is already synced
- Setup the needed bindings in the test control
pull/7194/head
Tim U 5 years ago
parent
commit
f69e3e642e
  1. 47
      src/Avalonia.Controls/Calendar/CalendarDatePicker.cs
  2. 6
      tests/Avalonia.Controls.UnitTests/CalendarDatePickerTests.cs

47
src/Avalonia.Controls/Calendar/CalendarDatePicker.cs

@ -5,7 +5,6 @@
using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Globalization;
using Avalonia.Controls.Primitives;
@ -441,7 +440,6 @@ namespace Avalonia.Controls
FirstDayOfWeek = DateTimeHelper.GetCurrentDateFormat().FirstDayOfWeek;
_defaultText = string.Empty;
DisplayDate = DateTime.Today;
BlackoutDates.CollectionChanged += BlackoutDates_CollectionChanged;
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
@ -1188,50 +1186,5 @@ namespace Avalonia.Controls
return newD;
}
}
private void BlackoutDates_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (CalendarDateRange item in e.NewItems)
{
_calendar.BlackoutDates.Add(item);
}
break;
case NotifyCollectionChangedAction.Move:
// We do not need to handle this case as the result will not have an effect.
break;
case NotifyCollectionChangedAction.Remove:
foreach (CalendarDateRange item in e.OldItems)
{
_calendar.BlackoutDates.Remove(item);
}
break;
case NotifyCollectionChangedAction.Replace:
foreach (CalendarDateRange item in e.OldItems)
{
_calendar.BlackoutDates.Remove(item);
}
foreach (CalendarDateRange item in e.NewItems)
{
_calendar.BlackoutDates.Add(item);
}
break;
case NotifyCollectionChangedAction.Reset:
_calendar.BlackoutDates.Clear();
foreach (CalendarDateRange item in BlackoutDates)
{
_calendar.BlackoutDates.Add(item);
}
break;
default:
throw new ArgumentOutOfRangeException(nameof(e.Action), e.Action, "Invalid NotifyCollectionChangedAction");
}
}
}
}

6
tests/Avalonia.Controls.UnitTests/CalendarDatePickerTests.cs

@ -105,7 +105,11 @@ namespace Avalonia.Controls.UnitTests
var calendar =
new Calendar
{
Name = "PART_Calendar"
Name = "PART_Calendar",
[!Calendar.SelectedDateProperty] = control[!CalendarDatePicker.SelectedDateProperty],
[!Calendar.DisplayDateProperty] = control[!CalendarDatePicker.DisplayDateProperty],
[!Calendar.DisplayDateStartProperty] = control[!CalendarDatePicker.DisplayDateStartProperty],
[!Calendar.DisplayDateEndProperty] = control[!CalendarDatePicker.DisplayDateEndProperty]
}.RegisterInNameScope(scope);
var popup =
new Popup

Loading…
Cancel
Save