Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DateTimePicker and Accessibility class #9253

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ public bool ShowUpDown
[AllowNull]
public override string Text
{
get => Value.ToString(CustomFormat);
get => base.Text;
set
{
// Clause to check length
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public partial class DateTimePicker : Form
public DateTimePicker()
{
InitializeComponent();
this.dateTimePicker5.CustomFormat = "yyyy-MM-dd HH:mm:ss";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ public void DateTimePickerAccessibleObject_GetPropertyValue_ReturnsExpected()
dateTimePicker.Value = dt;
AccessibleObject accessibleObject = dateTimePicker.AccessibilityObject;

Assert.Equal(dt.ToString(), accessibleObject.GetPropertyValue(UiaCore.UIA.ValueValuePropertyId));
Assert.True((bool)accessibleObject.GetPropertyValue(UiaCore.UIA.IsExpandCollapsePatternAvailablePropertyId));
Assert.False(dateTimePicker.IsHandleCreated);

dateTimePicker.CreateControl();

Assert.Equal(dt.ToLongDateString(), accessibleObject.GetPropertyValue(UiaCore.UIA.ValueValuePropertyId));
}

[WinFormsTheory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void DateTimePicker_Ctor_Default()
Assert.Equal(new Size(200, control.PreferredHeight), control.Size);
Assert.Equal(0, control.TabIndex);
Assert.True(control.TabStop);
Assert.Equal(control.TestAccessor().Dynamic._creationTime.ToString(), control.Text);
dmitrii-drobotov marked this conversation as resolved.
Show resolved Hide resolved
Assert.Equal(string.Empty, control.Text);
Assert.Equal(0, control.Top);
Assert.Null(control.TopLevelControl);
Assert.False(control.UseWaitCursor);
Expand Down Expand Up @@ -220,9 +220,36 @@ public void DateTimePicker_CustomFormat_Null_Text_ReturnsExpected()
using DateTimePicker dateTimePicker = new();
DateTime dt = new(2000, 1, 2, 3, 4, 5);
dateTimePicker.Value = dt;
dateTimePicker.CreateControl();

Assert.Null(dateTimePicker.CustomFormat);
Assert.Equal(dt.ToString(), dateTimePicker.Text);
Assert.Equal(dt.ToLongDateString(), dateTimePicker.Text);
}
dmitrii-drobotov marked this conversation as resolved.
Show resolved Hide resolved

[WinFormsFact]
public void DateTimePicker_CustomFormat_Null_Format_Short_Text_ReturnsExpected()
{
using DateTimePicker dateTimePicker = new();
DateTime dt = new(2000, 1, 2, 3, 4, 5);
dateTimePicker.Value = dt;
dateTimePicker.Format = DateTimePickerFormat.Short;
dateTimePicker.CreateControl();

Assert.Null(dateTimePicker.CustomFormat);
Assert.Equal(dt.ToShortDateString(), dateTimePicker.Text);
}

[WinFormsFact]
public void DateTimePicker_CustomFormat_Null_Format_Time_Text_ReturnsExpected()
{
using DateTimePicker dateTimePicker = new();
DateTime dt = new(2000, 1, 2, 3, 4, 5);
dateTimePicker.Value = dt;
dateTimePicker.Format = DateTimePickerFormat.Time;
dateTimePicker.CreateControl();

Assert.Null(dateTimePicker.CustomFormat);
Assert.Equal(dt.ToLongTimeString(), dateTimePicker.Text);
}

[WinFormsFact]
Expand All @@ -232,7 +259,9 @@ public void DateTimePicker_CustomFormat_LongDatePattern_Text_ReturnsExpected()
DateTime dt = new(2000, 1, 2, 3, 4, 5);
dateTimePicker.Value = dt;
Globalization.DateTimeFormatInfo dateTimeFormat = Globalization.CultureInfo.CurrentCulture.DateTimeFormat;
dateTimePicker.Format = DateTimePickerFormat.Custom;
dateTimePicker.CustomFormat = dateTimeFormat.LongDatePattern;
dateTimePicker.CreateControl();

Assert.Equal(dt.ToLongDateString(), dateTimePicker.Text);
}
Expand All @@ -244,7 +273,9 @@ public void DateTimePicker_CustomFormat_ShortDatePattern_Text_ReturnsExpected()
DateTime dt = new(2000, 1, 2, 3, 4, 5);
dateTimePicker.Value = dt;
Globalization.DateTimeFormatInfo dateTimeFormat = Globalization.CultureInfo.CurrentCulture.DateTimeFormat;
dateTimePicker.Format = DateTimePickerFormat.Custom;
dateTimePicker.CustomFormat = dateTimeFormat.ShortDatePattern;
dateTimePicker.CreateControl();

Assert.Equal(dt.ToShortDateString(), dateTimePicker.Text);
}
Expand All @@ -256,7 +287,9 @@ public void DateTimePicker_CustomFormat_LongTimePattern_Text_ReturnsExpected()
DateTime dt = new(2000, 1, 2, 3, 4, 5);
dateTimePicker.Value = dt;
Globalization.DateTimeFormatInfo dateTimeFormat = Globalization.CultureInfo.CurrentCulture.DateTimeFormat;
dateTimePicker.Format = DateTimePickerFormat.Custom;
dateTimePicker.CustomFormat = dateTimeFormat.LongTimePattern;
dateTimePicker.CreateControl();

Assert.Equal(dt.ToLongTimeString(), dateTimePicker.Text);
}
Expand All @@ -268,7 +301,9 @@ public void DateTimePicker_CustomFormat_ShortTimePattern_Text_ReturnsExpected()
DateTime dt = new(2000, 1, 2, 3, 4, 5);
dateTimePicker.Value = dt;
Globalization.DateTimeFormatInfo dateTimeFormat = Globalization.CultureInfo.CurrentCulture.DateTimeFormat;
dateTimePicker.Format = DateTimePickerFormat.Custom;
dateTimePicker.CustomFormat = dateTimeFormat.ShortTimePattern;
dateTimePicker.CreateControl();

Assert.Equal(dt.ToShortTimeString(), dateTimePicker.Text);
}
Expand Down