public void SelectedDateShouldTriggerChange() { TestUtils.Invoke(() => { var calendar = new Calendar(); var dateCount = 0; var rangeCount = 0; calendar.SelectedDateChanged += (sender, e) => dateCount++; calendar.SelectedRangeChanged += (sender, e) => rangeCount++; DateTime date = DateTime.Today; calendar.SelectedDate = date; Assert.AreEqual(0, dateCount, "SelectedDateChanged should not fire when set to the initial value"); Assert.AreEqual(0, rangeCount, "SelectedRangeChanged should not fire when date is set to the initial value"); Assert.AreEqual(date, calendar.SelectedDate, "SelectedDate should retain its value"); date = DateTime.Today.AddDays(10); calendar.SelectedDate = date; Assert.AreEqual(1, dateCount, "SelectedDateChanged should fire when set to a value"); Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should be fired when changing SelectedDate"); Assert.AreEqual(date, calendar.SelectedDate, "SelectedDate should retain its value"); dateCount = rangeCount = 0; calendar.SelectedDate = date; Assert.AreEqual(0, dateCount, "SelectedDateChanged should not be fired when set to the same date"); Assert.AreEqual(0, rangeCount, "SelectedRangeChanged should not be fired when set to the same date"); Assert.AreEqual(date, calendar.SelectedDate, "SelectedDate should retain its value"); dateCount = rangeCount = 0; calendar.SelectedDate = date = DateTime.Today.AddDays(20); Assert.AreEqual(1, dateCount, "SelectedDateChanged should fire when set to a specific date"); Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should be fired when changing SelectedDate"); Assert.AreEqual(date, calendar.SelectedDate, "SelectedDate should retain its value"); }); }
Control TestProperties() { var min = new DateTimePicker(); var max = new DateTimePicker(); var setValue = new DateTimePicker(); var toValue = new DateTimePicker(); var modeSelect = new EnumRadioButtonList<CalendarMode>(); var current = new Calendar(); var setButton = new Button { Text = "Set" }; var toValueSection = new StackLayout { Orientation = Orientation.Horizontal, Visible = false, Spacing = 5, Items = { " to ", toValue } }; var layout = new TableLayout { Spacing = new Size(5, 5), Padding = new Padding(10), Rows = { new TableRow("Min Value", min), new TableRow("Max Value", max), new TableRow("Mode", modeSelect), new TableRow("Set to value", new StackLayout { Orientation = Orientation.Horizontal, Spacing = 5, Items = { setValue, toValueSection, setButton } } ), new TableRow("Value", TableLayout.AutoSized(current), null), null } }; modeSelect.SelectedValueBinding.Bind(() => current.Mode, v => { toValueSection.Visible = v == CalendarMode.Range; current.Mode = v; }); min.ValueChanged += (sender, e) => current.MinDate = min.Value ?? DateTime.MinValue; max.ValueChanged += (sender, e) => current.MaxDate = max.Value ?? DateTime.MaxValue; setButton.Click += (sender, e) => { if (current.Mode == CalendarMode.Range) current.SelectedRange = (setValue.Value != null && toValue.Value != null) ? new Range<DateTime>(setValue.Value.Value, toValue.Value.Value) : current.SelectedRange; else current.SelectedDate = setValue.Value ?? current.SelectedDate; }; LogEvents(current); return layout; }
public void InitialValuesShouldBeCorrect() { TestUtils.Invoke(() => { var calendar = new Calendar(); Assert.AreEqual(CalendarMode.Single, calendar.Mode, "Calendar should default to single mode"); Assert.AreEqual(DateTime.Today, calendar.SelectedDate, "Initial SelectedDate should be Today"); Assert.AreEqual(new Range<DateTime>(DateTime.Today), calendar.SelectedRange, "Initial SelectedRange should be Today"); Assert.AreEqual(DateTime.MinValue, calendar.MinDate, "Initial MinDate should be DateTime.MinValue"); Assert.AreEqual(DateTime.MaxValue, calendar.MaxDate, "Initial MaxDate should be DateTime.MaxValue"); }); }
public void SelectedRangeShouldTriggerChange() { TestUtils.Invoke(() => { var calendar = new Calendar { Mode = CalendarMode.Range }; var dateCount = 0; var rangeCount = 0; calendar.SelectedDateChanged += (sender, e) => dateCount++; calendar.SelectedRangeChanged += (sender, e) => rangeCount++; rangeCount = dateCount = 0; var range = new Range<DateTime>(DateTime.Today); calendar.SelectedRange = range; Assert.AreEqual(0, dateCount, "SelectedDateChanged should not fire when set to initial value of null"); Assert.AreEqual(0, rangeCount, "SelectedRangeChanged should fire when set to initial value of null"); Assert.AreEqual(range, calendar.SelectedRange, "SelectedRange should retain its value"); Assert.AreEqual(range.Start, calendar.SelectedDate, "SelectedDate should be null when range is set to null"); rangeCount = dateCount = 0; range = new Range<DateTime>(DateTime.Today.AddDays(1), DateTime.Today.AddDays(10)); calendar.SelectedRange = range; Assert.AreEqual(1, dateCount, "SelectedDateChanged should fire when set to a specific date"); Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should fire when set"); Assert.AreEqual(range, calendar.SelectedRange, "SelectedDate should retain its value"); rangeCount = dateCount = 0; calendar.SelectedRange = range; Assert.AreEqual(0, dateCount, "SelectedDateChanged should not be fired when set to the same date"); Assert.AreEqual(0, rangeCount, "SelectedRangeChanged should not be fired when set to the same date"); Assert.AreEqual(range, calendar.SelectedRange, "SelectedRange should retain its value"); rangeCount = dateCount = 0; calendar.SelectedRange = range; Assert.AreEqual(0, dateCount, "SelectedDateChanged should not fire when set to the same value"); Assert.AreEqual(0, rangeCount, "SelectedRangeChanged should not fire when set to the same value"); rangeCount = dateCount = 0; calendar.SelectedRange = range = new Range<DateTime>(DateTime.Today.AddDays(1), DateTime.Today.AddDays(11)); Assert.AreEqual(0, dateCount, "SelectedDateChanged should not fire when range's start date hasn't changed"); Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should fire when set to a different date"); Assert.AreEqual(range, calendar.SelectedRange, "SelectedRange should retain its value"); rangeCount = dateCount = 0; calendar.SelectedRange = range = new Range<DateTime>(DateTime.Today.AddDays(2), DateTime.Today.AddDays(10)); Assert.AreEqual(1, dateCount, "SelectedDateChanged should fire when range's start date hasn't changed"); Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should fire when set to a different range"); Assert.AreEqual(range, calendar.SelectedRange, "SelectedRange should retain its value"); }); }
Control TestProperties() { var min = new DateTimePicker(); var max = new DateTimePicker(); var setValue = new DateTimePicker(); var toValue = new DateTimePicker(); var modeSelect = new EnumRadioButtonList<CalendarMode>(); var current = new Calendar(); var setButton = new Button { Text = "Set" }; TableLayout toValueSection; var layout = new TableLayout( new TableRow(new Label { Text = "Min Value" }, min), new TableRow(new Label { Text = "Max Value" }, max), new TableRow(new Label { Text = "Mode" }, modeSelect), new TableRow(new Label { Text = "Set to value" }, new TableLayout(new TableRow(setValue, toValueSection = new TableLayout(new TableRow(new Label { Text = " to " }, toValue)) { Visible = false, Padding = Padding.Empty }, setButton )) { Padding = Padding.Empty } ), new TableRow(new Label { Text = "Value" }, TableLayout.AutoSized(current), null), null ); modeSelect.SelectedValueBinding.Bind(() => current.Mode, v => { toValueSection.Visible = v == CalendarMode.Range; current.Mode = v; }); min.ValueChanged += (sender, e) => current.MinDate = min.Value ?? DateTime.MinValue; max.ValueChanged += (sender, e) => current.MaxDate = max.Value ?? DateTime.MaxValue; setButton.Click += (sender, e) => { if (current.Mode == CalendarMode.Range) current.SelectedRange = (setValue.Value != null && toValue.Value != null) ? new Range<DateTime>(setValue.Value.Value, toValue.Value.Value) : current.SelectedRange; else current.SelectedDate = setValue.Value ?? current.SelectedDate; }; LogEvents(current); return layout; }
public void ModeShouldUpdateDateWhenChangingFromRangeToSingle() { TestUtils.Invoke(() => { var initialRange = new Range<DateTime>(DateTime.Today, DateTime.Today.AddDays(10)); var calendar = new Calendar { Mode = CalendarMode.Range, SelectedRange = initialRange }; var dateCount = 0; var rangeCount = 0; calendar.SelectedDateChanged += (sender, e) => dateCount++; calendar.SelectedRangeChanged += (sender, e) => rangeCount++; Assert.AreEqual(initialRange, calendar.SelectedRange, "SelectedRange is not set to the initial value"); calendar.Mode = CalendarMode.Single; Assert.AreEqual(0, dateCount, "SelectedDateChanged should not be fired when changing the mode"); Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should be fired when changing the mode when the range changes"); Assert.AreEqual(initialRange.Start, calendar.SelectedDate, "SelectedDate should be the start of the original range"); Assert.AreEqual(initialRange.Start, calendar.SelectedRange.Start, "SelectedRange.End should be the same date"); Assert.AreEqual(initialRange.Start, calendar.SelectedRange.End, "SelectedRange.End should be the same date"); dateCount = rangeCount = 0; calendar.Mode = CalendarMode.Range; Assert.AreEqual(initialRange.End, calendar.SelectedRange.End, "SelectedRange.End should be the original end date when changing back to range mode"); Assert.AreEqual(0, dateCount, "SelectedDateChanged should not be fired when changing the mode"); Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should be fired when changing the mode when the range changes"); }); }
public void MaxDateShouldChangeSelectedDate() { TestUtils.Invoke(() => { var calendar = new Calendar(); var dateCount = 0; var rangeCount = 0; calendar.SelectedDateChanged += (sender, e) => dateCount++; calendar.SelectedRangeChanged += (sender, e) => rangeCount++; calendar.SelectedDate = DateTime.Today; dateCount = rangeCount = 0; var date = DateTime.Today.AddDays(-10); calendar.MaxDate = date; Assert.AreEqual(1, dateCount, "SelectedDateChanged should be fired when changing the min date"); Assert.AreEqual(1, rangeCount, "SelectedRangeChanged should be fired when changing the min date"); Assert.AreEqual(date, calendar.SelectedDate, "SelectedDate should be changed to the MaxDate"); }); }
void LogEvents(Calendar control) { control.SelectedDateChanged += (sender, e) => Log.Write(control, "SelectedDateChanged, Value: {0}", control.SelectedDate); control.SelectedRangeChanged += (sender, e) => Log.Write(control, "SelectedRangeChanged, Value: {0}", control.SelectedRange); }
/// <summary> /// Raises the selected range changed event. /// </summary> public void OnSelectedRangeChanged(Calendar widget, EventArgs e) { widget.Platform.Invoke(() => widget.OnSelectedRangeChanged(e)); }