Enable nullability in Controls.UnitTests (#20373)
This commit is contained in:
committed by
GitHub
parent
c68111294f
commit
960cb39414
@@ -159,7 +159,7 @@ namespace Avalonia.Controls
|
||||
new Manager(control).Init();
|
||||
});
|
||||
}
|
||||
public static void SetHotKey(AvaloniaObject target, KeyGesture value) => target.SetValue(HotKeyProperty, value);
|
||||
public static void SetHotKey(AvaloniaObject target, KeyGesture? value) => target.SetValue(HotKeyProperty, value);
|
||||
public static KeyGesture? GetHotKey(AvaloniaObject target) => target.GetValue(HotKeyProperty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
using (UnitTestApplication.Start(TestServices.StyledWindow))
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => { Application.Current.Run(null); });
|
||||
Assert.Throws<ArgumentNullException>(() => { Application.Current!.Run(null!); });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
// Test for #1765.
|
||||
using (UnitTestApplication.Start())
|
||||
{
|
||||
var resources = Application.Current.Resources;
|
||||
var resources = Application.Current!.Resources;
|
||||
var raised = false;
|
||||
|
||||
Application.Current.ResourcesChanged += (s, e) => raised = true;
|
||||
@@ -37,13 +37,13 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
using (UnitTestApplication.Start())
|
||||
{
|
||||
var application = Application.Current;
|
||||
var application = Application.Current!;
|
||||
|
||||
application.DataContext = "Test";
|
||||
|
||||
application.Bind(Application.NameProperty, new Binding("."));
|
||||
|
||||
Assert.Equal("Test", Application.Current.Name);
|
||||
Assert.Equal("Test", application.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,60 +21,60 @@ namespace Avalonia.Controls.UnitTests
|
||||
[Fact]
|
||||
public void Search_Filters()
|
||||
{
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.Contains)("am", "name"));
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.Contains)("AME", "name"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.Contains)("hello", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.Contains)("am", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.Contains)("AME", "name"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.Contains)("hello", "name"));
|
||||
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.ContainsCaseSensitive)("na", "name"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.ContainsCaseSensitive)("AME", "name"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.ContainsCaseSensitive)("hello", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.ContainsCaseSensitive)("na", "name"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.ContainsCaseSensitive)("AME", "name"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.ContainsCaseSensitive)("hello", "name"));
|
||||
|
||||
Assert.Null(GetFilter(AutoCompleteFilterMode.Custom));
|
||||
Assert.Null(GetFilter(AutoCompleteFilterMode.None));
|
||||
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.Equals)("na", "na"));
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.Equals)("na", "NA"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.Equals)("hello", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.Equals)("na", "na"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.Equals)("na", "NA"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.Equals)("hello", "name"));
|
||||
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.EqualsCaseSensitive)("na", "na"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.EqualsCaseSensitive)("na", "NA"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.EqualsCaseSensitive)("hello", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.EqualsCaseSensitive)("na", "na"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.EqualsCaseSensitive)("na", "NA"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.EqualsCaseSensitive)("hello", "name"));
|
||||
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.StartsWith)("na", "name"));
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.StartsWith)("NAM", "name"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.StartsWith)("hello", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.StartsWith)("na", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.StartsWith)("NAM", "name"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.StartsWith)("hello", "name"));
|
||||
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.StartsWithCaseSensitive)("na", "name"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.StartsWithCaseSensitive)("NAM", "name"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.StartsWithCaseSensitive)("hello", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.StartsWithCaseSensitive)("na", "name"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.StartsWithCaseSensitive)("NAM", "name"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.StartsWithCaseSensitive)("hello", "name"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ordinal_Search_Filters()
|
||||
{
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.ContainsOrdinal)("am", "name"));
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.ContainsOrdinal)("AME", "name"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.ContainsOrdinal)("hello", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.ContainsOrdinal)("am", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.ContainsOrdinal)("AME", "name"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.ContainsOrdinal)("hello", "name"));
|
||||
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.ContainsOrdinalCaseSensitive)("na", "name"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.ContainsOrdinalCaseSensitive)("AME", "name"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.ContainsOrdinalCaseSensitive)("hello", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.ContainsOrdinalCaseSensitive)("na", "name"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.ContainsOrdinalCaseSensitive)("AME", "name"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.ContainsOrdinalCaseSensitive)("hello", "name"));
|
||||
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.EqualsOrdinal)("na", "na"));
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.EqualsOrdinal)("na", "NA"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.EqualsOrdinal)("hello", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.EqualsOrdinal)("na", "na"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.EqualsOrdinal)("na", "NA"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.EqualsOrdinal)("hello", "name"));
|
||||
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.EqualsOrdinalCaseSensitive)("na", "na"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.EqualsOrdinalCaseSensitive)("na", "NA"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.EqualsOrdinalCaseSensitive)("hello", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.EqualsOrdinalCaseSensitive)("na", "na"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.EqualsOrdinalCaseSensitive)("na", "NA"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.EqualsOrdinalCaseSensitive)("hello", "name"));
|
||||
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.StartsWithOrdinal)("na", "name"));
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.StartsWithOrdinal)("NAM", "name"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.StartsWithOrdinal)("hello", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.StartsWithOrdinal)("na", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.StartsWithOrdinal)("NAM", "name"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.StartsWithOrdinal)("hello", "name"));
|
||||
|
||||
Assert.True(GetFilter(AutoCompleteFilterMode.StartsWithOrdinalCaseSensitive)("na", "name"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.StartsWithOrdinalCaseSensitive)("NAM", "name"));
|
||||
Assert.False(GetFilter(AutoCompleteFilterMode.StartsWithOrdinalCaseSensitive)("hello", "name"));
|
||||
Assert.True(GetNotNullFilter(AutoCompleteFilterMode.StartsWithOrdinalCaseSensitive)("na", "name"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.StartsWithOrdinalCaseSensitive)("NAM", "name"));
|
||||
Assert.False(GetNotNullFilter(AutoCompleteFilterMode.StartsWithOrdinalCaseSensitive)("hello", "name"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -261,7 +261,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
control.Populated += (s, e) =>
|
||||
{
|
||||
populated = true;
|
||||
ReadOnlyCollection<object> collection = e.Data as ReadOnlyCollection<object>;
|
||||
var collection = e.Data as ReadOnlyCollection<object>;
|
||||
populatedOk = collection != null && collection.Count == 1;
|
||||
};
|
||||
|
||||
@@ -328,14 +328,10 @@ namespace Avalonia.Controls.UnitTests
|
||||
RunTest((control, textbox) =>
|
||||
{
|
||||
control.FilterMode = AutoCompleteFilterMode.Custom;
|
||||
control.ItemFilter = (search, item) =>
|
||||
{
|
||||
string s = item as string;
|
||||
return s == null ? false : true;
|
||||
};
|
||||
control.ItemFilter = (_, item) => item is string;
|
||||
|
||||
// Just set to null briefly to exercise that code path
|
||||
AutoCompleteFilterPredicate<object> filter = control.ItemFilter;
|
||||
var filter = control.ItemFilter;
|
||||
Assert.NotNull(filter);
|
||||
control.ItemFilter = null;
|
||||
Assert.Null(control.ItemFilter);
|
||||
@@ -377,6 +373,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
RunTest((control, textbox) =>
|
||||
{
|
||||
Assert.NotNull(control.ItemsSource);
|
||||
|
||||
object selectedItem = control.ItemsSource.Cast<object>().First();
|
||||
string input = "42";
|
||||
|
||||
@@ -394,6 +392,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
RunTest((control, textbox) =>
|
||||
{
|
||||
Assert.NotNull(control.ItemsSource);
|
||||
|
||||
object selectedItem = control.ItemsSource.Cast<object>().First();
|
||||
string input = "42";
|
||||
|
||||
@@ -416,8 +416,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
control.Bind(AutoCompleteBox.TextProperty, textObservable);
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
|
||||
Assert.Equal(DataValidationErrors.GetHasErrors(control), true);
|
||||
Assert.Equal(DataValidationErrors.GetErrors(control).SequenceEqual(new[] { exception }), true);
|
||||
Assert.True(DataValidationErrors.GetHasErrors(control));
|
||||
Assert.Equal([exception], DataValidationErrors.GetErrors(control));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -453,8 +453,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
control.Bind(AutoCompleteBox.SelectedItemProperty, itemObservable);
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
|
||||
Assert.Equal(DataValidationErrors.GetHasErrors(control), true);
|
||||
Assert.Equal(DataValidationErrors.GetErrors(control).SequenceEqual(new[] { exception }), true);
|
||||
Assert.True(DataValidationErrors.GetHasErrors(control));
|
||||
Assert.Equal([exception], DataValidationErrors.GetErrors(control));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -587,12 +587,19 @@ namespace Avalonia.Controls.UnitTests
|
||||
/// </summary>
|
||||
/// <param name="mode">The FilterMode of interest.</param>
|
||||
/// <returns>Returns the predicate instance.</returns>
|
||||
private static AutoCompleteFilterPredicate<string> GetFilter(AutoCompleteFilterMode mode)
|
||||
private static AutoCompleteFilterPredicate<string?>? GetFilter(AutoCompleteFilterMode mode)
|
||||
{
|
||||
return new AutoCompleteBox { FilterMode = mode }
|
||||
.TextFilter;
|
||||
}
|
||||
|
||||
private static AutoCompleteFilterPredicate<string?> GetNotNullFilter(AutoCompleteFilterMode mode)
|
||||
{
|
||||
var filter = GetFilter(mode);
|
||||
Assert.NotNull(filter);
|
||||
return filter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a large list of strings for AutoCompleteBox testing.
|
||||
/// </summary>
|
||||
@@ -1200,7 +1207,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var window = new Window {Content = control};
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
window.Presenter.ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
test.Invoke(control, textBox);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<Import Project="..\..\build\Base.props" />
|
||||
<Import Project="..\..\build\SharedVersion.props" />
|
||||
<Import Project="..\..\build\HarfBuzzSharp.props" />
|
||||
<Import Project="..\..\build\NullableEnable.props" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup.Xaml.Loader\Avalonia.Markup.Xaml.Loader.csproj" />
|
||||
<ProjectReference Include="..\..\src\Markup\Avalonia.Markup.Xaml\Avalonia.Markup.Xaml.csproj" />
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var pt = new Point(150, 50);
|
||||
renderer.Setup(r => r.HitTest(It.IsAny<Point>(), It.IsAny<Visual>(), It.IsAny<Func<Visual, bool>>()))
|
||||
.Returns<Point, Visual, Func<Visual, bool>>((p, r, f) =>
|
||||
r.Bounds.Contains(p.Transform(r.RenderTransform.Value.Invert())) ?
|
||||
r.Bounds.Contains(p.Transform(r.RenderTransform!.Value.Invert())) ?
|
||||
new Visual[] { r } : new Visual[0]);
|
||||
|
||||
using var _ = UnitTestApplication.Start(TestServices.StyledWindow);
|
||||
@@ -336,9 +336,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
};
|
||||
|
||||
root.ApplyTemplate();
|
||||
root.Presenter.UpdateChild();
|
||||
root.Presenter!.UpdateChild();
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.UpdateChild();
|
||||
target.Presenter!.UpdateChild();
|
||||
kd.SetFocusedElement(target, NavigationMethod.Unspecified, KeyModifiers.None);
|
||||
|
||||
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
|
||||
@@ -535,7 +535,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
public void Button_CommandParameter_Does_Not_Change_While_Execution()
|
||||
{
|
||||
var target = new Button();
|
||||
object lastParamenter = "A";
|
||||
object? lastParamenter = "A";
|
||||
var generator = new Random();
|
||||
var onlyOnce = false;
|
||||
var command = new TestCommand(parameter =>
|
||||
@@ -582,12 +582,12 @@ namespace Avalonia.Controls.UnitTests
|
||||
}
|
||||
}
|
||||
|
||||
private KeyEventArgs CreateKeyDownEvent(Key key, Interactive source = null)
|
||||
private KeyEventArgs CreateKeyDownEvent(Key key, Interactive? source = null)
|
||||
{
|
||||
return new KeyEventArgs { RoutedEvent = InputElement.KeyDownEvent, Key = key, Source = source };
|
||||
}
|
||||
|
||||
private KeyEventArgs CreateKeyUpEvent(Key key, Interactive source = null)
|
||||
private KeyEventArgs CreateKeyUpEvent(Key key, Interactive? source = null)
|
||||
{
|
||||
return new KeyEventArgs { RoutedEvent = InputElement.KeyUpEvent, Key = key, Source = source };
|
||||
}
|
||||
@@ -682,6 +682,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
button.ApplyTemplate();
|
||||
var presenter = button.Presenter;
|
||||
Assert.NotNull(presenter);
|
||||
|
||||
button.LetterSpacing = 5.0;
|
||||
|
||||
@@ -758,7 +759,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
private readonly ILayoutManager _layoutManager;
|
||||
public bool IsClosed { get; private set; }
|
||||
|
||||
public TestTopLevel(ITopLevelImpl impl, ILayoutManager layoutManager = null)
|
||||
public TestTopLevel(ITopLevelImpl impl, ILayoutManager? layoutManager = null)
|
||||
: base(impl)
|
||||
{
|
||||
_layoutManager = layoutManager ?? new LayoutManager(this);
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
using (UnitTestApplication.Start(Services))
|
||||
{
|
||||
CalendarDatePicker datePicker = CreateControl();
|
||||
Assert.NotNull(datePicker.BlackoutDates);
|
||||
datePicker.BlackoutDates.AddDatesInPast();
|
||||
|
||||
DateTime goodValue = DateTime.Today.AddDays(1);
|
||||
@@ -65,7 +66,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
datePicker.SelectedDate = DateTime.Today.AddDays(5);
|
||||
|
||||
Assert.ThrowsAny<ArgumentOutOfRangeException>(
|
||||
() => datePicker.BlackoutDates.Add(new CalendarDateRange(DateTime.Today, DateTime.Today.AddDays(10))));
|
||||
() => datePicker.BlackoutDates!.Add(new CalendarDateRange(DateTime.Today, DateTime.Today.AddDays(10))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
RaiseKeyEvent(tb, Key.Enter, KeyModifiers.None);
|
||||
|
||||
Assert.Equal("17.10.2024", datePicker.Text);
|
||||
Assert.True(CompareDates(datePicker.SelectedDate.Value, new DateTime(2024, 10, 17)));
|
||||
Assert.True(CompareDates(datePicker.SelectedDate!.Value, new DateTime(2024, 10, 17)));
|
||||
|
||||
tb.Clear();
|
||||
RaiseTextEvent(tb, "12.10.2024");
|
||||
|
||||
@@ -143,12 +143,12 @@ namespace Avalonia.Controls.UnitTests
|
||||
/// <summary>
|
||||
/// The days added to the SelectedDates collection.
|
||||
/// </summary>
|
||||
private IList<object> _selectedDatesChangedAddedDays;
|
||||
private IList<object>? _selectedDatesChangedAddedDays;
|
||||
|
||||
/// <summary>
|
||||
/// The days removed from the SelectedDates collection.
|
||||
/// </summary>
|
||||
private IList<object> _selectedDateChangedRemovedDays;
|
||||
private IList<object>? _selectedDatesChangedRemovedDays;
|
||||
|
||||
/// <summary>
|
||||
/// The number of times the SelectedDatesChanged event has been fired.
|
||||
@@ -160,13 +160,13 @@ namespace Avalonia.Controls.UnitTests
|
||||
/// </summary>
|
||||
/// <param name="sender">The calendar.</param>
|
||||
/// <param name="e">Event arguments.</param>
|
||||
private void OnSelectedDatesChanged(object sender, SelectionChangedEventArgs e)
|
||||
private void OnSelectedDatesChanged(object? sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
_selectedDatesChangedAddedDays =
|
||||
e.AddedItems
|
||||
.Cast<object>()
|
||||
.ToList();
|
||||
_selectedDateChangedRemovedDays =
|
||||
_selectedDatesChangedRemovedDays =
|
||||
e.RemovedItems
|
||||
.Cast<object>()
|
||||
.ToList();
|
||||
@@ -183,9 +183,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
_selectedDatesChangedAddedDays.Clear();
|
||||
}
|
||||
|
||||
if (_selectedDateChangedRemovedDays != null)
|
||||
if (_selectedDatesChangedRemovedDays != null)
|
||||
{
|
||||
_selectedDateChangedRemovedDays.Clear();
|
||||
_selectedDatesChangedRemovedDays.Clear();
|
||||
}
|
||||
|
||||
_selectedDatesChangedCount = 0;
|
||||
@@ -203,8 +203,10 @@ namespace Avalonia.Controls.UnitTests
|
||||
Assert.True(calendar.SelectedDates.Count == 1);
|
||||
Assert.True(CompareDates(calendar.SelectedDates[0], DateTime.Today));
|
||||
Assert.True(_selectedDatesChangedCount == 1);
|
||||
Assert.NotNull(_selectedDatesChangedAddedDays);
|
||||
Assert.True(_selectedDatesChangedAddedDays.Count == 1);
|
||||
Assert.True(_selectedDateChangedRemovedDays.Count == 0);
|
||||
Assert.NotNull(_selectedDatesChangedRemovedDays);
|
||||
Assert.True(_selectedDatesChangedRemovedDays.Count == 0);
|
||||
ResetSelectedDatesChanged();
|
||||
|
||||
calendar.SelectedDate = DateTime.Today;
|
||||
@@ -241,8 +243,10 @@ namespace Avalonia.Controls.UnitTests
|
||||
Assert.True(calendar.SelectedDates.Count == 1);
|
||||
Assert.True(CompareDates(calendar.SelectedDates[0], DateTime.Today));
|
||||
Assert.True(_selectedDatesChangedCount == 1);
|
||||
Assert.NotNull(_selectedDatesChangedAddedDays);
|
||||
Assert.True(_selectedDatesChangedAddedDays.Count == 1);
|
||||
Assert.True(_selectedDateChangedRemovedDays.Count == 0);
|
||||
Assert.NotNull(_selectedDatesChangedRemovedDays);
|
||||
Assert.True(_selectedDatesChangedRemovedDays.Count == 0);
|
||||
ResetSelectedDatesChanged();
|
||||
|
||||
calendar.SelectedDates.Clear();
|
||||
@@ -264,7 +268,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Assert.True(calendar.SelectedDates.Count == 21);
|
||||
Assert.True(_selectedDatesChangedCount == 1);
|
||||
Assert.True(_selectedDatesChangedAddedDays.Count == 21);
|
||||
Assert.True(_selectedDateChangedRemovedDays.Count == 11);
|
||||
Assert.True(_selectedDatesChangedRemovedDays.Count == 11);
|
||||
ResetSelectedDatesChanged();
|
||||
|
||||
calendar.SelectedDates.Add(DateTime.Today.AddDays(100));
|
||||
|
||||
@@ -257,7 +257,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.Bind(ComboBox.SelectedItemProperty, textObservable);
|
||||
|
||||
Assert.True(DataValidationErrors.GetHasErrors(target));
|
||||
Assert.True(DataValidationErrors.GetErrors(target).SequenceEqual(new[] { exception }));
|
||||
Assert.Equal([exception], DataValidationErrors.GetErrors(target));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
private static void Layout(Carousel target)
|
||||
{
|
||||
((ILayoutRoot)target.GetVisualRoot()).LayoutManager.ExecuteLayoutPass();
|
||||
((ILayoutRoot)target.GetVisualRoot()!).LayoutManager.ExecuteLayoutPass();
|
||||
}
|
||||
|
||||
private static IControlTemplate CarouselTemplate()
|
||||
@@ -371,7 +371,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
});
|
||||
}
|
||||
|
||||
private static TextBlock GetContainerTextBlock(object control)
|
||||
private static TextBlock GetContainerTextBlock(object? control)
|
||||
{
|
||||
var contentPresenter = Assert.IsType<ContentPresenter>(control);
|
||||
return Assert.IsType<TextBlock>(contentPresenter.Child);
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
};
|
||||
var root = new TestRoot(target);
|
||||
target.ApplyTemplate();
|
||||
((Control)target.Presenter).ApplyTemplate();
|
||||
target.Presenter!.ApplyTemplate();
|
||||
target.Focus();
|
||||
Assert.Equal(target.SelectedIndex, -1);
|
||||
Assert.True(target.IsFocused);
|
||||
@@ -117,7 +117,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
};
|
||||
var root = new TestRoot(target);
|
||||
target.ApplyTemplate();
|
||||
((Control)target.Presenter).ApplyTemplate();
|
||||
target.Presenter!.ApplyTemplate();
|
||||
target.Focus();
|
||||
Assert.Equal(target.SelectedIndex, -1);
|
||||
Assert.True(target.IsFocused);
|
||||
@@ -166,9 +166,10 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var root = new TestRoot { Child = target };
|
||||
target.ApplyTemplate();
|
||||
((Control)target.Presenter).ApplyTemplate();
|
||||
target.Presenter!.ApplyTemplate();
|
||||
|
||||
var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle;
|
||||
Assert.NotNull(rectangle);
|
||||
Assert.True(((ILogical)target).IsAttachedToLogicalTree);
|
||||
Assert.True(((ILogical)rectangle).IsAttachedToLogicalTree);
|
||||
|
||||
@@ -202,7 +203,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Content = new ItemsPresenter
|
||||
{
|
||||
Name = "PART_ItemsPresenter",
|
||||
ItemsPanel = new FuncTemplate<Panel>(() => new VirtualizingStackPanel()),
|
||||
ItemsPanel = new FuncTemplate<Panel?>(() => new VirtualizingStackPanel()),
|
||||
}.RegisterInNameScope(scope)
|
||||
}.RegisterInNameScope(scope)
|
||||
}.RegisterInNameScope(scope),
|
||||
@@ -234,7 +235,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var root = new TestRoot { Child = panel = new StackPanel { Children = { target, other } } };
|
||||
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.ApplyTemplate();
|
||||
target.Presenter!.ApplyTemplate();
|
||||
|
||||
other.Focus();
|
||||
|
||||
@@ -379,14 +380,14 @@ namespace Avalonia.Controls.UnitTests
|
||||
};
|
||||
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.ApplyTemplate();
|
||||
target.Presenter!.ApplyTemplate();
|
||||
|
||||
var exception = new System.InvalidCastException("failed validation");
|
||||
var textObservable = new BehaviorSubject<BindingNotification>(new BindingNotification(exception, BindingErrorType.DataValidationError));
|
||||
target.Bind(ComboBox.SelectedItemProperty, textObservable);
|
||||
|
||||
Assert.True(DataValidationErrors.GetHasErrors(target));
|
||||
Assert.True(DataValidationErrors.GetErrors(target).SequenceEqual(new[] { exception }));
|
||||
Assert.Equal([exception], DataValidationErrors.GetErrors(target));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -473,7 +474,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.SelectedIndex = 0;
|
||||
|
||||
var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle;
|
||||
|
||||
Assert.NotNull(rectangle);
|
||||
Assert.Equal(FlowDirection.LeftToRight, rectangle.FlowDirection);
|
||||
}
|
||||
|
||||
@@ -503,6 +504,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.SelectedIndex = 0;
|
||||
|
||||
var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle;
|
||||
Assert.NotNull(rectangle);
|
||||
Assert.Equal(FlowDirection.LeftToRight, rectangle.FlowDirection);
|
||||
|
||||
parentContent.FlowDirection = FlowDirection.RightToLeft;
|
||||
@@ -539,6 +541,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.SelectedIndex = 0;
|
||||
|
||||
var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle;
|
||||
Assert.NotNull(rectangle);
|
||||
Assert.Equal(FlowDirection.LeftToRight, rectangle.FlowDirection);
|
||||
|
||||
parentContent.FlowDirection = FlowDirection.RightToLeft;
|
||||
@@ -807,7 +810,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
keyboardNavHandler.SetOwner(root);
|
||||
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.ApplyTemplate();
|
||||
target.Presenter!.ApplyTemplate();
|
||||
|
||||
var containerPanel = target.GetTemplateChildren().OfType<Panel>().FirstOrDefault(x => x.Name == "container");
|
||||
var editableTextBox = containerPanel?.GetVisualDescendants().OfType<TextBox>().FirstOrDefault(x => x.Name == "PART_EditableTextBox");
|
||||
@@ -815,6 +818,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
var popupScrollViewer = popup?.Child as ScrollViewer;
|
||||
var scrollViewerItemsPresenter = popupScrollViewer?.Content as ItemsPresenter;
|
||||
var popupVirtualizingStackPanel = scrollViewerItemsPresenter?.GetVisualDescendants().OfType<VirtualizingStackPanel>().FirstOrDefault();
|
||||
|
||||
Assert.NotNull(editableTextBox);
|
||||
Assert.NotNull(scrollViewerItemsPresenter);
|
||||
Assert.NotNull(popupVirtualizingStackPanel);
|
||||
|
||||
//force the popup to render the ComboBoxItem(s) as they are what get set as "focused" if this test fails
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.Content = "Foo";
|
||||
target.Template = GetTemplate();
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.UpdateChild();
|
||||
target.Presenter!.UpdateChild();
|
||||
|
||||
var child = target.VisualChildren.Single();
|
||||
Assert.IsType<Border>(child);
|
||||
@@ -55,7 +55,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
root.Child = target;
|
||||
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.ApplyTemplate();
|
||||
target.Presenter!.ApplyTemplate();
|
||||
|
||||
foreach (Control child in target.GetTemplateChildren())
|
||||
Assert.Equal("foo", child.Tag);
|
||||
@@ -70,9 +70,10 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.Template = GetTemplate();
|
||||
target.Content = child;
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.UpdateChild();
|
||||
target.Presenter!.UpdateChild();
|
||||
|
||||
var contentPresenter = child.GetVisualParent<ContentPresenter>();
|
||||
Assert.NotNull(contentPresenter);
|
||||
Assert.Equal(target, contentPresenter.TemplatedParent);
|
||||
}
|
||||
|
||||
@@ -85,7 +86,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.Template = GetTemplate();
|
||||
target.Content = child;
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.UpdateChild();
|
||||
target.Presenter!.UpdateChild();
|
||||
|
||||
Assert.Null(child.TemplatedParent);
|
||||
}
|
||||
@@ -117,7 +118,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var child = new Control();
|
||||
target.Content = child;
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.UpdateChild();
|
||||
target.Presenter!.UpdateChild();
|
||||
|
||||
Assert.Equal(child.Parent, target);
|
||||
Assert.Equal(child.GetLogicalParent(), target);
|
||||
@@ -135,7 +136,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
target.Content = "Foo";
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.UpdateChild();
|
||||
target.Presenter!.UpdateChild();
|
||||
|
||||
var child = target.Presenter.Child;
|
||||
|
||||
@@ -152,7 +153,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
target.Content = "Foo";
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.UpdateChild();
|
||||
target.Presenter!.UpdateChild();
|
||||
|
||||
var child = target.Presenter.Child;
|
||||
|
||||
@@ -192,7 +193,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.Template = GetTemplate();
|
||||
target.Content = child;
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.UpdateChild();
|
||||
target.Presenter!.UpdateChild();
|
||||
|
||||
Assert.True(called);
|
||||
}
|
||||
@@ -207,7 +208,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.Template = GetTemplate();
|
||||
target.Content = child;
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.UpdateChild();
|
||||
target.Presenter!.UpdateChild();
|
||||
|
||||
((ILogical)target).LogicalChildren.CollectionChanged += (s, e) => called = true;
|
||||
|
||||
@@ -228,7 +229,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.Template = GetTemplate();
|
||||
target.Content = child1;
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.UpdateChild();
|
||||
target.Presenter!.UpdateChild();
|
||||
|
||||
((ILogical)target).LogicalChildren.CollectionChanged += (s, e) => called = true;
|
||||
|
||||
@@ -245,14 +246,14 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
target.Template = GetTemplate();
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.UpdateChild();
|
||||
target.Presenter!.UpdateChild();
|
||||
|
||||
target.Content = "Foo";
|
||||
target.Presenter.UpdateChild();
|
||||
Assert.Equal("Foo", ((TextBlock)target.Presenter.Child).Text);
|
||||
Assert.Equal("Foo", ((TextBlock)target.Presenter.Child!).Text);
|
||||
target.Content = "Bar";
|
||||
target.Presenter.UpdateChild();
|
||||
Assert.Equal("Bar", ((TextBlock)target.Presenter.Child).Text);
|
||||
Assert.Equal("Bar", ((TextBlock)target.Presenter.Child!).Text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -263,9 +264,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.Template = GetTemplate();
|
||||
target.Content = "Foo";
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.UpdateChild();
|
||||
target.Presenter!.UpdateChild();
|
||||
|
||||
Assert.Equal("Foo", target.Presenter.Child.DataContext);
|
||||
Assert.Equal("Foo", target.Presenter.Child!.DataContext);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -276,16 +277,16 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.Template = GetTemplate();
|
||||
target.Content = new TextBlock();
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.UpdateChild();
|
||||
target.Presenter!.UpdateChild();
|
||||
|
||||
Assert.Null(target.Presenter.Child.DataContext);
|
||||
Assert.Null(target.Presenter.Child!.DataContext);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Binding_ContentTemplate_After_Content_Does_Not_Leave_Orpaned_TextBlock()
|
||||
{
|
||||
// Test for #1271.
|
||||
var children = new List<Control>();
|
||||
var children = new List<Control?>();
|
||||
var presenter = new ContentPresenter();
|
||||
|
||||
// The content and then the content template property need to be bound with delayed bindings
|
||||
@@ -328,7 +329,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
x => Assert.IsType<TextBlock>(x),
|
||||
x => Assert.IsType<Canvas>(x));
|
||||
|
||||
var textBlock = (TextBlock)children[1];
|
||||
var textBlock = (TextBlock)children[1]!;
|
||||
|
||||
// The leak in #1271 was caused by the TextBlock's logical parent not being cleared when
|
||||
// it is replaced by the Canvas.
|
||||
@@ -356,9 +357,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
target.Content = "Foo";
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.ApplyTemplate();
|
||||
target.Presenter!.ApplyTemplate();
|
||||
|
||||
Assert.Equal(target, target.Presenter.Child.GetLogicalParent());
|
||||
Assert.Equal(target, target.Presenter!.Child!.GetLogicalParent());
|
||||
Assert.Equal(new[] { target.Presenter.Child }, target.LogicalChildren);
|
||||
|
||||
root.Child = null;
|
||||
@@ -370,7 +371,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
root.Child = target;
|
||||
target.Content = "Bar";
|
||||
|
||||
Assert.Equal(target, target.Presenter.Child.GetLogicalParent());
|
||||
Assert.Equal(target, target.Presenter.Child!.GetLogicalParent());
|
||||
Assert.Equal(new[] { target.Presenter.Child }, target.LogicalChildren);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
using System;
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Platform;
|
||||
using Avalonia.Rendering;
|
||||
using Avalonia.Rendering.Composition;
|
||||
using Avalonia.UnitTests;
|
||||
|
||||
using Moq;
|
||||
@@ -15,7 +13,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
public class ContextMenuTests : ScopedTestBase
|
||||
{
|
||||
private Mock<IPopupImpl> popupImpl;
|
||||
private Mock<IPopupImpl>? _popupImpl;
|
||||
private MouseTestHelper _mouse = new MouseTestHelper();
|
||||
|
||||
[Fact]
|
||||
@@ -32,7 +30,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var window = new Window { Content = target };
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
((Control)window.Presenter).ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
|
||||
int openedCount = 0;
|
||||
|
||||
@@ -65,7 +63,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var window = new Window { Content = target };
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
((Control)window.Presenter).ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
|
||||
target.RaiseEvent(new ContextRequestedEventArgs());
|
||||
|
||||
@@ -135,7 +133,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var window = new Window { Content = target };
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
((Control)window.Presenter).ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
|
||||
int openedCount = 0;
|
||||
|
||||
@@ -164,7 +162,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var window = new Window { Content = target };
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
((Control)window.Presenter).ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
|
||||
bool opened = false;
|
||||
|
||||
@@ -193,7 +191,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var window = new Window { Content = target };
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
((Control)window.Presenter).ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
|
||||
target.ContextMenu = null;
|
||||
|
||||
@@ -215,7 +213,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var window = new Window { Content = target };
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
((Control)window.Presenter).ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
|
||||
sut.Open(target);
|
||||
|
||||
@@ -237,8 +235,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
using (Application())
|
||||
{
|
||||
popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
popupImpl.Setup(x => x.Hide()).Verifiable();
|
||||
_popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
_popupImpl.Setup(x => x.Hide()).Verifiable();
|
||||
|
||||
var window = PreparedWindow();
|
||||
window.Width = 100;
|
||||
@@ -268,14 +266,15 @@ namespace Avalonia.Controls.UnitTests
|
||||
c.Open(button);
|
||||
|
||||
var overlay = LightDismissOverlayLayer.GetLightDismissOverlayLayer(window);
|
||||
Assert.NotNull(overlay);
|
||||
_mouse.Down(overlay, MouseButton.Left, new Point(90, 90));
|
||||
_mouse.Up(button, MouseButton.Left, new Point(90, 90));
|
||||
|
||||
Assert.Equal(1, tracker);
|
||||
Assert.True(c.IsOpen);
|
||||
|
||||
popupImpl.Verify(x => x.Hide(), Times.Never);
|
||||
popupImpl.Verify(x => x.Show(true, false), Times.Exactly(1));
|
||||
_popupImpl.Verify(x => x.Hide(), Times.Never);
|
||||
_popupImpl.Verify(x => x.Show(true, false), Times.Exactly(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,8 +283,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
using (Application())
|
||||
{
|
||||
popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
popupImpl.Setup(x => x.Hide()).Verifiable();
|
||||
_popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
_popupImpl.Setup(x => x.Hide()).Verifiable();
|
||||
|
||||
var window = PreparedWindow();
|
||||
window.Width = 100;
|
||||
@@ -308,12 +307,13 @@ namespace Avalonia.Controls.UnitTests
|
||||
c.Open(button);
|
||||
|
||||
var overlay = LightDismissOverlayLayer.GetLightDismissOverlayLayer(window);
|
||||
Assert.NotNull(overlay);
|
||||
_mouse.Down(overlay, MouseButton.Left, new Point(90, 90));
|
||||
_mouse.Up(button, MouseButton.Left, new Point(90, 90));
|
||||
|
||||
Assert.False(c.IsOpen);
|
||||
popupImpl.Verify(x => x.Hide(), Times.Exactly(1));
|
||||
popupImpl.Verify(x => x.Show(true, false), Times.Exactly(1));
|
||||
_popupImpl.Verify(x => x.Hide(), Times.Exactly(1));
|
||||
_popupImpl.Verify(x => x.Show(true, false), Times.Exactly(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,8 +322,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
using (Application())
|
||||
{
|
||||
popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
popupImpl.Setup(x => x.Hide()).Verifiable();
|
||||
_popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
_popupImpl.Setup(x => x.Hide()).Verifiable();
|
||||
|
||||
var sut = new ContextMenu();
|
||||
var target = new Panel
|
||||
@@ -334,6 +334,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var window = PreparedWindow(target);
|
||||
window.Show();
|
||||
var overlay = LightDismissOverlayLayer.GetLightDismissOverlayLayer(window);
|
||||
Assert.NotNull(overlay);
|
||||
|
||||
_mouse.Click(target, MouseButton.Right);
|
||||
|
||||
@@ -343,8 +344,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
_mouse.Up(target);
|
||||
|
||||
Assert.False(sut.IsOpen);
|
||||
popupImpl.Verify(x => x.Show(true, false), Times.Once);
|
||||
popupImpl.Verify(x => x.Hide(), Times.Once);
|
||||
_popupImpl.Verify(x => x.Show(true, false), Times.Once);
|
||||
_popupImpl.Verify(x => x.Hide(), Times.Once);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,8 +354,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
using (Application())
|
||||
{
|
||||
popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
popupImpl.Setup(x => x.Hide()).Verifiable();
|
||||
_popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
_popupImpl.Setup(x => x.Hide()).Verifiable();
|
||||
|
||||
var sut = new ContextMenu();
|
||||
var target = new Panel
|
||||
@@ -366,6 +367,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
window.Show();
|
||||
|
||||
var overlay = LightDismissOverlayLayer.GetLightDismissOverlayLayer(window);
|
||||
Assert.NotNull(overlay);
|
||||
|
||||
_mouse.Click(target, MouseButton.Right);
|
||||
Assert.True(sut.IsOpen);
|
||||
@@ -374,8 +376,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
_mouse.Up(target, MouseButton.Right);
|
||||
|
||||
Assert.True(sut.IsOpen);
|
||||
popupImpl.Verify(x => x.Hide(), Times.Once);
|
||||
popupImpl.Verify(x => x.Show(true, false), Times.Exactly(2));
|
||||
_popupImpl.Verify(x => x.Hide(), Times.Once);
|
||||
_popupImpl.Verify(x => x.Show(true, false), Times.Exactly(2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,7 +402,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
((Control)window.Presenter).ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
|
||||
_mouse.Click(target1, MouseButton.Right);
|
||||
|
||||
@@ -421,7 +423,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
using (Application())
|
||||
{
|
||||
popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
_popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
|
||||
bool eventCalled = false;
|
||||
var sut = new ContextMenu();
|
||||
@@ -437,7 +439,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Assert.True(eventCalled);
|
||||
Assert.False(sut.IsOpen);
|
||||
popupImpl.Verify(x => x.Show(true, false), Times.Never);
|
||||
_popupImpl.Verify(x => x.Show(true, false), Times.Never);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,8 +498,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
</Window>";
|
||||
|
||||
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
|
||||
var target1 = window.Find<TextBlock>("target1");
|
||||
var target2 = window.Find<TextBlock>("target2");
|
||||
var target1 = window.Get<TextBlock>("target1");
|
||||
var target2 = window.Get<TextBlock>("target2");
|
||||
var mouse = new MouseTestHelper();
|
||||
|
||||
Assert.NotNull(target1.ContextMenu);
|
||||
@@ -539,8 +541,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
</Window>";
|
||||
|
||||
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
|
||||
var target1 = window.Find<TextBlock>("target1");
|
||||
var target2 = window.Find<TextBlock>("target2");
|
||||
var target1 = window.Get<TextBlock>("target1");
|
||||
var target2 = window.Get<TextBlock>("target2");
|
||||
var mouse = new MouseTestHelper();
|
||||
|
||||
Assert.NotNull(target1.ContextMenu);
|
||||
@@ -562,8 +564,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
using (Application())
|
||||
{
|
||||
popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
popupImpl.Setup(x => x.Hide()).Verifiable();
|
||||
_popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
_popupImpl.Setup(x => x.Hide()).Verifiable();
|
||||
|
||||
bool eventCalled = false;
|
||||
var sut = new ContextMenu();
|
||||
@@ -574,6 +576,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var window = PreparedWindow(target);
|
||||
var overlay = LightDismissOverlayLayer.GetLightDismissOverlayLayer(window);
|
||||
Assert.NotNull(overlay);
|
||||
|
||||
sut.Closing += (c, e) => { eventCalled = true; e.Cancel = true; };
|
||||
|
||||
@@ -589,8 +592,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
Assert.True(eventCalled);
|
||||
Assert.True(sut.IsOpen);
|
||||
|
||||
popupImpl.Verify(x => x.Show(true, false), Times.Once());
|
||||
popupImpl.Verify(x => x.Hide(), Times.Never);
|
||||
_popupImpl.Verify(x => x.Show(true, false), Times.Once());
|
||||
_popupImpl.Verify(x => x.Hide(), Times.Never);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,8 +602,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
using (Application())
|
||||
{
|
||||
popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
popupImpl.Setup(x => x.Hide()).Verifiable();
|
||||
_popupImpl.Setup(x => x.Show(true, false)).Verifiable();
|
||||
_popupImpl.Setup(x => x.Hide()).Verifiable();
|
||||
|
||||
var item = new MenuItem();
|
||||
var sut = new ContextMenu
|
||||
@@ -643,7 +646,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
}
|
||||
}
|
||||
|
||||
private static Window PreparedWindow(object content = null)
|
||||
private static Window PreparedWindow(object? content = null)
|
||||
{
|
||||
|
||||
var platform = AvaloniaLocator.Current.GetRequiredService<IWindowingPlatform>();
|
||||
@@ -653,10 +656,11 @@ namespace Avalonia.Controls.UnitTests
|
||||
var w = new Window(windowImpl.Object) { Content = content };
|
||||
w.ApplyStyling();
|
||||
w.ApplyTemplate();
|
||||
((Control)w.Presenter).ApplyTemplate();
|
||||
w.Presenter!.ApplyTemplate();
|
||||
return w;
|
||||
}
|
||||
|
||||
[MemberNotNull(nameof(_popupImpl))]
|
||||
private IDisposable Application()
|
||||
{
|
||||
var screen = new PixelRect(new PixelPoint(), new PixelSize(100, 100));
|
||||
@@ -665,9 +669,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
screenImpl.Setup(X => X.AllScreens).Returns( new[] { new Screen(1, screen, screen, true) });
|
||||
|
||||
var windowImpl = MockWindowingPlatform.CreateWindowMock();
|
||||
popupImpl = MockWindowingPlatform.CreatePopupMock(windowImpl.Object);
|
||||
popupImpl.SetupGet(x => x.RenderScaling).Returns(1);
|
||||
windowImpl.Setup(x => x.CreatePopup()).Returns(popupImpl.Object);
|
||||
_popupImpl = MockWindowingPlatform.CreatePopupMock(windowImpl.Object);
|
||||
_popupImpl.SetupGet(x => x.RenderScaling).Returns(1);
|
||||
windowImpl.Setup(x => x.CreatePopup()).Returns(_popupImpl.Object);
|
||||
|
||||
windowImpl.Setup(x => x.TryGetFeature(It.Is<Type>(t => t == typeof(IScreenImpl)))).Returns(screenImpl.Object);
|
||||
|
||||
@@ -675,7 +679,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
keyboardDevice: () => new KeyboardDevice(),
|
||||
inputManager: new InputManager(),
|
||||
windowImpl: windowImpl.Object,
|
||||
windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object, x => popupImpl.Object));
|
||||
windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object, x => _popupImpl.Object));
|
||||
|
||||
return UnitTestApplication.Start(services);
|
||||
}
|
||||
|
||||
@@ -50,13 +50,10 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var desc = datePicker.GetVisualDescendants();
|
||||
Assert.True(desc.Count() > 1);//Should be layoutroot grid & button
|
||||
TextBlock dayText = null;
|
||||
Grid container = null;
|
||||
TextBlock? dayText = null;
|
||||
|
||||
Assert.True(desc.ElementAt(1) is Button);
|
||||
|
||||
container = (desc.ElementAt(1) as Button).Content as Grid;
|
||||
Assert.True(container != null);
|
||||
var button = Assert.IsAssignableFrom<Button>(desc.ElementAt(1));
|
||||
var container = Assert.IsAssignableFrom<Grid>(button.Content);
|
||||
|
||||
for(int i = 0; i < container.Children.Count; i++)
|
||||
{
|
||||
@@ -67,9 +64,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(dayText != null);
|
||||
Assert.True(!dayText.IsVisible);
|
||||
Assert.True(container.ColumnDefinitions.Count == 3);
|
||||
Assert.NotNull(dayText);
|
||||
Assert.False(dayText.IsVisible);
|
||||
Assert.Equal(3, container.ColumnDefinitions.Count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,13 +85,10 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var desc = datePicker.GetVisualDescendants();
|
||||
Assert.True(desc.Count() > 1);//Should be layoutroot grid & button
|
||||
TextBlock monthText = null;
|
||||
Grid container = null;
|
||||
TextBlock? monthText = null;
|
||||
|
||||
Assert.True(desc.ElementAt(1) is Button);
|
||||
|
||||
container = (desc.ElementAt(1) as Button).Content as Grid;
|
||||
Assert.True(container != null);
|
||||
var button = Assert.IsAssignableFrom<Button>(desc.ElementAt(1));
|
||||
var container = Assert.IsAssignableFrom<Grid>(button.Content);
|
||||
|
||||
for (int i = 0; i < container.Children.Count; i++)
|
||||
{
|
||||
@@ -105,9 +99,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(monthText != null);
|
||||
Assert.True(!monthText.IsVisible);
|
||||
Assert.True(container.ColumnDefinitions.Count == 3);
|
||||
Assert.NotNull(monthText);
|
||||
Assert.False(monthText.IsVisible);
|
||||
Assert.Equal(3, container.ColumnDefinitions.Count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,13 +120,10 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var desc = datePicker.GetVisualDescendants();
|
||||
Assert.True(desc.Count() > 1);//Should be layoutroot grid & button
|
||||
TextBlock yearText = null;
|
||||
Grid container = null;
|
||||
TextBlock? yearText = null;
|
||||
|
||||
Assert.True(desc.ElementAt(1) is Button);
|
||||
|
||||
container = (desc.ElementAt(1) as Button).Content as Grid;
|
||||
Assert.True(container != null);
|
||||
var button = Assert.IsAssignableFrom<Button>(desc.ElementAt(1));
|
||||
var container = Assert.IsAssignableFrom<Grid>(button.Content);
|
||||
|
||||
for (int i = 0; i < container.Children.Count; i++)
|
||||
{
|
||||
@@ -143,9 +134,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(yearText != null);
|
||||
Assert.True(!yearText.IsVisible);
|
||||
Assert.True(container.ColumnDefinitions.Count == 3);
|
||||
Assert.NotNull(yearText);
|
||||
Assert.False(yearText.IsVisible);
|
||||
Assert.Equal(3, container.ColumnDefinitions.Count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,15 +155,12 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var desc = datePicker.GetVisualDescendants();
|
||||
Assert.True(desc.Count() > 1);//Should be layoutroot grid & button
|
||||
TextBlock yearText = null;
|
||||
TextBlock monthText = null;
|
||||
TextBlock dayText = null;
|
||||
Grid container = null;
|
||||
TextBlock? yearText = null;
|
||||
TextBlock? monthText = null;
|
||||
TextBlock? dayText = null;
|
||||
|
||||
Assert.True(desc.ElementAt(1) is Button);
|
||||
|
||||
container = (desc.ElementAt(1) as Button).Content as Grid;
|
||||
Assert.True(container != null);
|
||||
var button = Assert.IsAssignableFrom<Button>(desc.ElementAt(1));
|
||||
var container = Assert.IsAssignableFrom<Grid>(button.Content);
|
||||
|
||||
for (int i = 0; i < container.Children.Count; i++)
|
||||
{
|
||||
@@ -190,6 +178,10 @@ namespace Avalonia.Controls.UnitTests
|
||||
}
|
||||
}
|
||||
|
||||
Assert.NotNull(dayText);
|
||||
Assert.NotNull(monthText);
|
||||
Assert.NotNull(yearText);
|
||||
|
||||
DateTimeOffset value = new DateTimeOffset(2000, 10, 10, 0, 0, 0, TimeSpan.Zero);
|
||||
datePicker.SelectedDate = value;
|
||||
|
||||
|
||||
@@ -317,7 +317,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
window.Show();
|
||||
Assert.Equal(1, lifetime.Windows.Count);
|
||||
windowImpl.Object.Closed();
|
||||
windowImpl.Object.Closed!();
|
||||
|
||||
Assert.Empty(lifetime.Windows);
|
||||
}
|
||||
@@ -443,7 +443,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
lifetime.Exit += (_, _) => Assert.Fail("lifetime.Exit was called.");
|
||||
Dispatcher.UIThread.ShutdownStarted += UiThreadOnShutdownStarted;
|
||||
|
||||
static void UiThreadOnShutdownStarted(object sender, EventArgs e)
|
||||
static void UiThreadOnShutdownStarted(object? sender, EventArgs e)
|
||||
{
|
||||
Assert.Fail("Dispatcher.UIThread.ShutdownStarted was called.");
|
||||
}
|
||||
|
||||
@@ -185,6 +185,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var e = CreatePointerPressedEventArgs(window, new Point(90, 90));
|
||||
var overlay = LightDismissOverlayLayer.GetLightDismissOverlayLayer(window);
|
||||
Assert.NotNull(overlay);
|
||||
overlay.RaiseEvent(e);
|
||||
|
||||
Assert.Equal(1, tracker);
|
||||
@@ -218,6 +219,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var e = CreatePointerPressedEventArgs(window, new Point(90, 90));
|
||||
var overlay = LightDismissOverlayLayer.GetLightDismissOverlayLayer(window);
|
||||
Assert.NotNull(overlay);
|
||||
overlay.RaiseEvent(e);
|
||||
|
||||
Assert.False(f.IsOpen);
|
||||
@@ -259,6 +261,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var e = CreatePointerPressedEventArgs(window, new Point(90, 90));
|
||||
var overlay = LightDismissOverlayLayer.GetLightDismissOverlayLayer(window);
|
||||
Assert.NotNull(overlay);
|
||||
overlay.RaiseEvent(e);
|
||||
|
||||
Assert.False(f.IsOpen);
|
||||
@@ -301,6 +304,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var e = CreatePointerPressedEventArgs(window, new Point(90, 90));
|
||||
var overlay = LightDismissOverlayLayer.GetLightDismissOverlayLayer(window);
|
||||
Assert.NotNull(overlay);
|
||||
overlay.RaiseEvent(e);
|
||||
|
||||
Assert.False(f.IsOpen);
|
||||
@@ -410,9 +414,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
window.Show();
|
||||
|
||||
button.Focus();
|
||||
Assert.True(window.FocusManager.GetFocusedElement() == button);
|
||||
Assert.Same(button, window.FocusManager?.GetFocusedElement());
|
||||
button.Flyout.ShowAt(button);
|
||||
Assert.True(window.FocusManager.GetFocusedElement() == button);
|
||||
Assert.Same(button, window.FocusManager?.GetFocusedElement());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,8 +590,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
</Window>";
|
||||
|
||||
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
|
||||
var target1 = window.Find<TextBlock>("target1");
|
||||
var target2 = window.Find<TextBlock>("target2");
|
||||
var target1 = window.Get<TextBlock>("target1");
|
||||
var target2 = window.Get<TextBlock>("target2");
|
||||
var mouse = new MouseTestHelper();
|
||||
|
||||
Assert.NotNull(target1.ContextFlyout);
|
||||
@@ -632,13 +636,13 @@ namespace Avalonia.Controls.UnitTests
|
||||
window.Content = button;
|
||||
window.Show();
|
||||
|
||||
(button.Flyout as Flyout).FlyoutPresenterClasses.Add("TestClass");
|
||||
((Flyout)button.Flyout).FlyoutPresenterClasses.Add("TestClass");
|
||||
|
||||
button.Flyout.ShowAt(button);
|
||||
|
||||
var presenter = flyoutPanel.GetVisualAncestors().OfType<FlyoutPresenter>().FirstOrDefault();
|
||||
Assert.NotNull(presenter);
|
||||
Assert.True((presenter.Background as ISolidColorBrush).Color == Colors.Red);
|
||||
Assert.Equal(Colors.Red, (presenter.Background as ISolidColorBrush)?.Color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -650,7 +654,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
keyboardDevice: () => new KeyboardDevice()));
|
||||
}
|
||||
|
||||
private static Window PreparedWindow(object content = null)
|
||||
private static Window PreparedWindow(object? content = null)
|
||||
{
|
||||
var platform = AvaloniaLocator.Current.GetRequiredService<IWindowingPlatform>();
|
||||
var windowImpl = Mock.Get(platform.CreateWindow());
|
||||
|
||||
@@ -16,19 +16,19 @@ namespace Avalonia.Controls.UnitTests
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
private static Grid CreateGrid(params (string name, GridLength width)[] columns)
|
||||
private static Grid CreateGrid(params (string? name, GridLength width)[] columns)
|
||||
{
|
||||
return CreateGrid(columns.Select(c =>
|
||||
(c.name, c.width, ColumnDefinition.MinWidthProperty.GetDefaultValue(typeof(ColumnDefinition)))).ToArray());
|
||||
}
|
||||
|
||||
private static Grid CreateGrid(params (string name, GridLength width, double minWidth)[] columns)
|
||||
private static Grid CreateGrid(params (string? name, GridLength width, double minWidth)[] columns)
|
||||
{
|
||||
return CreateGrid(columns.Select(c =>
|
||||
(c.name, c.width, c.minWidth, ColumnDefinition.MaxWidthProperty.GetDefaultValue(typeof(ColumnDefinition)))).ToArray());
|
||||
}
|
||||
|
||||
private static Grid CreateGrid(params (string name, GridLength width, double minWidth, double maxWidth)[] columns)
|
||||
private static Grid CreateGrid(params (string? name, GridLength width, double minWidth, double maxWidth)[] columns)
|
||||
{
|
||||
var grid = new Grid();
|
||||
foreach (var k in columns.Select(c => new ColumnDefinition
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
target.Header = "Foo";
|
||||
target.ApplyTemplate();
|
||||
target.HeaderPresenter.UpdateChild();
|
||||
target.HeaderPresenter!.UpdateChild();
|
||||
|
||||
var child = target.HeaderPresenter.Child;
|
||||
|
||||
|
||||
@@ -16,17 +16,17 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
private readonly Action _action;
|
||||
public DelegateCommand(Action action) => _action = action;
|
||||
public event EventHandler CanExecuteChanged { add { } remove { } }
|
||||
public bool CanExecute(object parameter) => true;
|
||||
public void Execute(object parameter) => _action();
|
||||
public event EventHandler? CanExecuteChanged { add { } remove { } }
|
||||
public bool CanExecute(object? parameter) => true;
|
||||
public void Execute(object? parameter) => _action();
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<KeyGesture> HotKeyProperty =
|
||||
public static readonly StyledProperty<KeyGesture?> HotKeyProperty =
|
||||
HotKeyManager.HotKeyProperty.AddOwner<HotKeyedTextBox>();
|
||||
|
||||
private KeyGesture _hotkey;
|
||||
private KeyGesture? _hotkey;
|
||||
|
||||
public KeyGesture HotKey
|
||||
public KeyGesture? HotKey
|
||||
{
|
||||
get => GetValue(HotKeyProperty);
|
||||
set => SetValue(HotKeyProperty, value);
|
||||
@@ -61,7 +61,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
public ICommand Command => _command;
|
||||
|
||||
public object CommandParameter => null;
|
||||
public object? CommandParameter => null;
|
||||
|
||||
private readonly DelegateCommand _command;
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
public class HotKeyedControlsTests : ScopedTestBase
|
||||
{
|
||||
private static Window PreparedWindow(object content = null)
|
||||
private static Window PreparedWindow(object? content = null)
|
||||
{
|
||||
var platform = AvaloniaLocator.Current.GetRequiredService<IWindowingPlatform>();
|
||||
var windowImpl = Mock.Get(platform.CreateWindow());
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
bold.BuildTextRun(textRuns, default);
|
||||
|
||||
var runProperties = textRuns[0].Properties;
|
||||
Assert.NotNull(runProperties);
|
||||
Assert.Equal(FontWeight.Bold, runProperties.Typeface.Weight);
|
||||
}
|
||||
|
||||
@@ -38,6 +39,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
italic.BuildTextRun(textRuns, default);
|
||||
|
||||
var runProperties = textRuns[0].Properties;
|
||||
Assert.NotNull(runProperties);
|
||||
Assert.Equal(FontStyle.Italic, runProperties.Typeface.Style);
|
||||
}
|
||||
|
||||
@@ -55,6 +57,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
span.BuildTextRun(textRuns, default);
|
||||
|
||||
var runProperties = textRuns[0].Properties;
|
||||
Assert.NotNull(runProperties);
|
||||
Assert.Equal(FontStretch.Condensed, runProperties.Typeface.Stretch);
|
||||
}
|
||||
|
||||
@@ -74,6 +77,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
span.BuildTextRun(textRuns, default);
|
||||
|
||||
var runProperties = textRuns[0].Properties;
|
||||
Assert.NotNull(runProperties);
|
||||
Assert.Equal(backgroundBrush, runProperties.BackgroundBrush);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,12 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Assert.Null(debug.GetCollectionChangedSubscribers());
|
||||
|
||||
void Handler(object sender, NotifyCollectionChangedEventArgs e) { }
|
||||
void Handler(object? sender, NotifyCollectionChangedEventArgs e) { }
|
||||
target.CollectionChanged += Handler;
|
||||
|
||||
Assert.NotNull(debug.GetCollectionChangedSubscribers());
|
||||
Assert.Equal(1, debug.GetCollectionChangedSubscribers().Length);
|
||||
var subscribers = debug.GetCollectionChangedSubscribers();
|
||||
Assert.NotNull(subscribers);
|
||||
Assert.Equal(1, subscribers.Length);
|
||||
|
||||
target.CollectionChanged -= Handler;
|
||||
|
||||
@@ -48,7 +49,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
target.CollectionChanged += (s, e) => { };
|
||||
|
||||
Assert.Equal(1, debug.GetCollectionChangedSubscribers().Length);
|
||||
var subscribers = debug.GetCollectionChangedSubscribers();
|
||||
Assert.NotNull(subscribers);
|
||||
Assert.Equal(1, subscribers.Length);
|
||||
|
||||
target.SetSource(new string[0]);
|
||||
|
||||
@@ -65,12 +68,14 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.CollectionChanged += (s, e) => { };
|
||||
target.SetSource(source);
|
||||
|
||||
Assert.Equal(1, debug.GetCollectionChangedSubscribers().Length);
|
||||
var subscribers = debug.GetCollectionChangedSubscribers();
|
||||
Assert.NotNull(subscribers);
|
||||
Assert.Equal(1, subscribers.Length);
|
||||
}
|
||||
|
||||
private class InvalidCollection : INotifyCollectionChanged, IEnumerable<string>
|
||||
{
|
||||
public event NotifyCollectionChangedEventHandler CollectionChanged { add { } remove { } }
|
||||
public event NotifyCollectionChangedEventHandler? CollectionChanged { add { } remove { } }
|
||||
|
||||
public IEnumerator<string> GetEnumerator()
|
||||
{
|
||||
|
||||
@@ -198,6 +198,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
25,
|
||||
new RotateTransform() { Angle = 90 });
|
||||
|
||||
Assert.NotNull(lt.TransformRoot);
|
||||
Assert.NotNull(lt.TransformRoot.RenderTransform);
|
||||
|
||||
Matrix m = lt.TransformRoot.RenderTransform.Value;
|
||||
@@ -222,6 +223,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
25,
|
||||
new RotateTransform() { Angle = -90 });
|
||||
|
||||
Assert.NotNull(lt.TransformRoot);
|
||||
Assert.NotNull(lt.TransformRoot.RenderTransform);
|
||||
|
||||
var m = lt.TransformRoot.RenderTransform.Value;
|
||||
@@ -246,6 +248,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
50,
|
||||
new ScaleTransform() { ScaleX = 2, ScaleY = 2 });
|
||||
|
||||
Assert.NotNull(lt.TransformRoot);
|
||||
Assert.NotNull(lt.TransformRoot.RenderTransform);
|
||||
|
||||
Matrix m = lt.TransformRoot.RenderTransform.Value;
|
||||
@@ -269,6 +272,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
100,
|
||||
new SkewTransform() { AngleX = 45, AngleY = 45 });
|
||||
|
||||
Assert.NotNull(lt.TransformRoot);
|
||||
Assert.NotNull(lt.TransformRoot.RenderTransform);
|
||||
|
||||
Matrix m = lt.TransformRoot.RenderTransform.Value;
|
||||
@@ -293,6 +297,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
100,
|
||||
new SkewTransform() { AngleX = -45, AngleY = -45 });
|
||||
|
||||
Assert.NotNull(lt.TransformRoot);
|
||||
Assert.NotNull(lt.TransformRoot.RenderTransform);
|
||||
|
||||
Matrix m = lt.TransformRoot.RenderTransform.Value;
|
||||
@@ -325,6 +330,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
var window = new Window { Content = lt };
|
||||
window.Show();
|
||||
|
||||
Assert.NotNull(lt.TransformRoot);
|
||||
Assert.NotNull(lt.TransformRoot.RenderTransform);
|
||||
Matrix actual = lt.TransformRoot.RenderTransform.Value;
|
||||
Matrix expected = Matrix.CreateSkew(Matrix.ToRadians(45), Matrix.ToRadians(45));
|
||||
Assert.Equal(expected.M11, actual.M11, 3);
|
||||
@@ -357,6 +364,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
LayoutTransformControl lt = CreateWithChildAndMeasureAndTransform(size.Width, size.Height, transform);
|
||||
|
||||
Assert.NotNull(lt.TransformRoot);
|
||||
Rect outBounds = lt.TransformRoot.Bounds;
|
||||
|
||||
Assert.Equal(outBounds.X, expectedBounds.X);
|
||||
|
||||
@@ -37,8 +37,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Prepare(target);
|
||||
|
||||
var container = (ListBoxItem)target.Presenter.Panel.Children[0];
|
||||
Assert.IsType<Canvas>(container.Presenter.Child);
|
||||
var container = (ListBoxItem)target.Presenter!.Panel!.Children[0];
|
||||
Assert.IsType<Canvas>(container.Presenter!.Child);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,7 +62,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Template = ListBoxTemplate(),
|
||||
};
|
||||
|
||||
ScrollViewer viewer = null;
|
||||
ScrollViewer? viewer = null;
|
||||
|
||||
target.TemplateApplied += (sender, e) =>
|
||||
{
|
||||
@@ -88,9 +88,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Prepare(target);
|
||||
|
||||
var text = target.Presenter.Panel.Children
|
||||
var text = target.Presenter!.Panel!.Children
|
||||
.OfType<ListBoxItem>()
|
||||
.Select(x => x.Presenter.Child)
|
||||
.Select(x => x.Presenter!.Child)
|
||||
.OfType<TextBlock>()
|
||||
.Select(x => x.Text)
|
||||
.ToList();
|
||||
@@ -115,7 +115,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Prepare(target);
|
||||
|
||||
var container = (ListBoxItem)target.Presenter.Panel.Children[0];
|
||||
var container = (ListBoxItem)target.Presenter!.Panel!.Children[0];
|
||||
|
||||
Assert.Same(container.Theme, theme);
|
||||
}
|
||||
@@ -136,7 +136,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Prepare(target);
|
||||
|
||||
var container = (ListBoxItem)target.Presenter.Panel.Children[0];
|
||||
var container = (ListBoxItem)target.Presenter!.Panel!.Children[0];
|
||||
|
||||
Assert.Same(container.Theme, theme);
|
||||
}
|
||||
@@ -187,7 +187,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Prepare(target);
|
||||
|
||||
var dataContexts = target.Presenter.Panel.Children
|
||||
var dataContexts = target.Presenter!.Panel!.Children
|
||||
.Cast<Control>()
|
||||
.Select(x => x.DataContext)
|
||||
.ToList();
|
||||
@@ -214,14 +214,14 @@ namespace Avalonia.Controls.UnitTests
|
||||
Prepare(target);
|
||||
|
||||
// Make sure we're virtualized and first item is selected.
|
||||
Assert.Equal(10, target.Presenter.Panel.Children.Count);
|
||||
Assert.Equal(10, target.Presenter!.Panel!.Children.Count);
|
||||
Assert.True(((ListBoxItem)target.Presenter.Panel.Children[0]).IsSelected);
|
||||
|
||||
// The selected item must not be the anchor, otherwise it won't get recycled.
|
||||
target.Selection.AnchorIndex = -1;
|
||||
|
||||
// Scroll down a page.
|
||||
target.Scroll.Offset = new Vector(0, 10);
|
||||
target.Scroll!.Offset = new Vector(0, 10);
|
||||
Layout(target);
|
||||
|
||||
// Make sure recycled item isn't now selected.
|
||||
@@ -244,7 +244,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Prepare(target);
|
||||
|
||||
Assert.Equal(new Size(100, 200), target.Scroll.Extent);
|
||||
Assert.Equal(new Size(100, 200), target.Scroll!.Extent);
|
||||
Assert.Equal(new Size(100, 100), target.Scroll.Viewport);
|
||||
}
|
||||
}
|
||||
@@ -273,7 +273,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
items.Remove("Item 2");
|
||||
Layout(target);
|
||||
|
||||
var actual = target.GetRealizedContainers().Cast<ListBoxItem>().Select(x => (string)x.Content).ToList();
|
||||
var actual = target.GetRealizedContainers().Cast<ListBoxItem>().Select(x => (string?)x.Content).ToList();
|
||||
Assert.Equal(items.OrderBy(x => x), actual.OrderBy(x => x));
|
||||
}
|
||||
}
|
||||
@@ -324,7 +324,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
};
|
||||
|
||||
Prepare(target);
|
||||
target.Scroll.Offset = new Vector(0, 1);
|
||||
target.Scroll!.Offset = new Vector(0, 1);
|
||||
|
||||
items.RemoveRange(0, 11);
|
||||
}
|
||||
@@ -393,10 +393,12 @@ namespace Avalonia.Controls.UnitTests
|
||||
lm.ExecuteLayoutPass();
|
||||
|
||||
var flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic;
|
||||
var toMeasure = lm.GetType().GetField("_toMeasure", flags).GetValue(lm) as System.Collections.Generic.IEnumerable<Layout.Layoutable>;
|
||||
var toArrange = lm.GetType().GetField("_toArrange", flags).GetValue(lm) as System.Collections.Generic.IEnumerable<Layout.Layoutable>;
|
||||
var toMeasure = lm.GetType().GetField("_toMeasure", flags)!.GetValue(lm) as IEnumerable<Layoutable>;
|
||||
var toArrange = lm.GetType().GetField("_toArrange", flags)!.GetValue(lm) as IEnumerable<Layoutable>;
|
||||
|
||||
Assert.NotNull(toMeasure);
|
||||
Assert.Equal(0, toMeasure.Count());
|
||||
Assert.NotNull(toArrange);
|
||||
Assert.Equal(0, toArrange.Count());
|
||||
}
|
||||
}
|
||||
@@ -435,11 +437,11 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Threading.Dispatcher.UIThread.RunJobs();
|
||||
|
||||
Assert.Equal("30", target.ContainerFromIndex(items.Count - 1).DataContext);
|
||||
Assert.Equal("29", target.ContainerFromIndex(items.Count - 2).DataContext);
|
||||
Assert.Equal("28", target.ContainerFromIndex(items.Count - 3).DataContext);
|
||||
Assert.Equal("27", target.ContainerFromIndex(items.Count - 4).DataContext);
|
||||
Assert.Equal("26", target.ContainerFromIndex(items.Count - 5).DataContext);
|
||||
Assert.Equal("30", target.ContainerFromIndex(items.Count - 1)!.DataContext);
|
||||
Assert.Equal("29", target.ContainerFromIndex(items.Count - 2)!.DataContext);
|
||||
Assert.Equal("28", target.ContainerFromIndex(items.Count - 3)!.DataContext);
|
||||
Assert.Equal("27", target.ContainerFromIndex(items.Count - 4)!.DataContext);
|
||||
Assert.Equal("26", target.ContainerFromIndex(items.Count - 5)!.DataContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,7 +465,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Threading.Dispatcher.UIThread.RunJobs();
|
||||
|
||||
// First an item that is not index 0 must be selected.
|
||||
_mouse.Click(target.Presenter.Panel.Children[1]);
|
||||
_mouse.Click(target.Presenter!.Panel!.Children[1]);
|
||||
|
||||
Threading.Dispatcher.UIThread.RunJobs();
|
||||
|
||||
@@ -516,7 +518,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
lm.ExecuteInitialLayoutPass();
|
||||
|
||||
var panel = target.Presenter.Panel;
|
||||
var panel = target.Presenter!.Panel!;
|
||||
|
||||
items.Add("Item 1");
|
||||
target.Selection.Select(0);
|
||||
@@ -640,7 +642,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
private static void Layout(Control c)
|
||||
{
|
||||
((ILayoutRoot)c.GetVisualRoot()).LayoutManager.ExecuteLayoutPass();
|
||||
((ILayoutRoot)c.GetVisualRoot()!).LayoutManager.ExecuteLayoutPass();
|
||||
}
|
||||
|
||||
private class Item
|
||||
@@ -671,7 +673,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.Bind(ComboBox.SelectedItemProperty, textObservable);
|
||||
|
||||
Assert.True(DataValidationErrors.GetHasErrors(target));
|
||||
Assert.True(DataValidationErrors.GetErrors(target).SequenceEqual(new[] { exception }));
|
||||
Assert.Equal([exception], DataValidationErrors.GetErrors(target));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -689,7 +691,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var realized = target.GetRealizedContainers()
|
||||
.Cast<ListBoxItem>()
|
||||
.Select(x => (string)x.DataContext)
|
||||
.Select(x => (string?)x.DataContext)
|
||||
.ToList();
|
||||
|
||||
Assert.Equal(Enumerable.Range(0, 10).Select(x => $"Item{x}"), realized);
|
||||
@@ -699,7 +701,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
realized = target.GetRealizedContainers()
|
||||
.Cast<ListBoxItem>()
|
||||
.Select(x => (string)x.DataContext)
|
||||
.Select(x => (string?)x.DataContext)
|
||||
.ToList();
|
||||
|
||||
Assert.Equal(Enumerable.Range(0, 10).Select(x => $"Item{99 - x}"), realized);
|
||||
@@ -722,7 +724,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var realized = target.GetRealizedContainers()
|
||||
.Cast<ListBoxItem>()
|
||||
.Select(x => (string)x.DataContext)
|
||||
.Select(x => (string?)x.DataContext)
|
||||
.ToList();
|
||||
|
||||
Assert.Equal(Enumerable.Range(0, 10).Select(x => $"Item{x}"), realized);
|
||||
@@ -734,7 +736,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
realized = target.GetRealizedContainers()
|
||||
.Cast<ListBoxItem>()
|
||||
.Select(x => (string)x.DataContext)
|
||||
.Select(x => (string?)x.DataContext)
|
||||
.ToList();
|
||||
|
||||
// "Item1" should remain selected, and now be at the bottom of the viewport.
|
||||
@@ -775,7 +777,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
Template = ListBoxTemplate(),
|
||||
ItemsSource = items,
|
||||
ItemsPanel = new FuncTemplate<Panel>(() => new VirtualizingStackPanel
|
||||
ItemsPanel = new FuncTemplate<Panel?>(() => new VirtualizingStackPanel
|
||||
{
|
||||
Orientation = Orientation.Horizontal
|
||||
}),
|
||||
@@ -811,13 +813,13 @@ namespace Avalonia.Controls.UnitTests
|
||||
Prepare(target);
|
||||
|
||||
RaiseKeyEvent(target, Key.Down);
|
||||
Assert.True(target.ContainerFromIndex(1).IsFocused);
|
||||
Assert.True(target.ContainerFromIndex(1)!.IsFocused);
|
||||
|
||||
RaiseKeyEvent(target, Key.Down);
|
||||
Assert.True(target.ContainerFromIndex(2).IsFocused);
|
||||
Assert.True(target.ContainerFromIndex(2)!.IsFocused);
|
||||
|
||||
RaiseKeyEvent(target, Key.Up);
|
||||
Assert.True(target.ContainerFromIndex(1).IsFocused);
|
||||
Assert.True(target.ContainerFromIndex(1)!.IsFocused);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -878,7 +880,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
RaiseKeyEvent(target, Key.Down, KeyModifiers.Control);
|
||||
|
||||
Assert.Equal(0, target.SelectedIndex);
|
||||
Assert.True(target.ContainerFromIndex(1).IsFocused);
|
||||
Assert.True(target.ContainerFromIndex(1)!.IsFocused);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -899,16 +901,16 @@ namespace Avalonia.Controls.UnitTests
|
||||
Prepare(target);
|
||||
|
||||
target.ContainerFromIndex(0)!.Focus();
|
||||
target.Scroll.Offset = new Vector(0, 100);
|
||||
target.Scroll!.Offset = new Vector(0, 100);
|
||||
Layout(target);
|
||||
|
||||
var panel = (VirtualizingStackPanel)target.ItemsPanelRoot;
|
||||
var panel = (VirtualizingStackPanel)target.ItemsPanelRoot!;
|
||||
Assert.Equal(10, panel.FirstRealizedIndex);
|
||||
|
||||
RaiseKeyEvent(target, Key.Down);
|
||||
|
||||
Assert.Equal(1, target.SelectedIndex);
|
||||
Assert.True(target.ContainerFromIndex(1).IsFocused);
|
||||
Assert.True(target.ContainerFromIndex(1)!.IsFocused);
|
||||
Assert.Equal(new Vector(0, 10), target.Scroll.Offset);
|
||||
}
|
||||
|
||||
@@ -1184,6 +1186,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
RaiseKeyEvent(button, Key.Tab);
|
||||
|
||||
var item = target.ContainerFromIndex(1);
|
||||
Assert.NotNull(item);
|
||||
Assert.Same(item, root.FocusManager.GetFocusedElement());
|
||||
|
||||
RaiseKeyEvent(item, Key.Tab);
|
||||
@@ -1340,33 +1343,33 @@ namespace Avalonia.Controls.UnitTests
|
||||
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
|
||||
public event NotifyCollectionChangedEventHandler CollectionChanged;
|
||||
public event NotifyCollectionChangedEventHandler? CollectionChanged;
|
||||
}
|
||||
|
||||
private class DataVirtualizingList : IList
|
||||
{
|
||||
private readonly List<string> _inner = new(Enumerable.Repeat<string>(null, 100));
|
||||
private readonly List<string?> _inner = new(Enumerable.Repeat<string?>(null, 100));
|
||||
|
||||
public object this[int index]
|
||||
public object? this[int index]
|
||||
{
|
||||
get => _inner[index] = $"Item{index}";
|
||||
set => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetRealizedItems() => _inner.Where(x => x is not null);
|
||||
public IEnumerable<string> GetRealizedItems() => _inner.Where(x => x is not null)!;
|
||||
public bool IsFixedSize => true;
|
||||
public bool IsReadOnly => true;
|
||||
public int Count => _inner.Count;
|
||||
public bool IsSynchronized => false;
|
||||
public object SyncRoot => this;
|
||||
public int Add(object value) => throw new NotSupportedException();
|
||||
public int Add(object? value) => throw new NotSupportedException();
|
||||
public void Clear() => throw new NotSupportedException();
|
||||
public bool Contains(object value) => throw new NotImplementedException();
|
||||
public bool Contains(object? value) => throw new NotImplementedException();
|
||||
public void CopyTo(Array array, int index) => throw new NotImplementedException();
|
||||
public IEnumerator GetEnumerator() => _inner.GetEnumerator();
|
||||
public int IndexOf(object value) => throw new NotImplementedException();
|
||||
public void Insert(int index, object value) => throw new NotSupportedException();
|
||||
public void Remove(object value) => throw new NotSupportedException();
|
||||
public int IndexOf(object? value) => throw new NotImplementedException();
|
||||
public void Insert(int index, object? value) => throw new NotSupportedException();
|
||||
public void Remove(object? value) => throw new NotSupportedException();
|
||||
public void RemoveAt(int index) => throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
root.LayoutManager.ExecuteInitialLayoutPass();
|
||||
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
_helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Shift);
|
||||
_helper.Click(target.Presenter!.Panel!.Children[2], modifiers: KeyModifiers.Shift);
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar", "Baz" }, target.SelectedItems);
|
||||
Assert.Equal(new[] { 0, 1, 2 }, SelectedContainers(target));
|
||||
@@ -63,7 +63,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
|
||||
SelectionChangedEventArgs receivedArgs = null;
|
||||
SelectionChangedEventArgs? receivedArgs = null;
|
||||
|
||||
target.SelectionChanged += (_, args) => receivedArgs = args;
|
||||
|
||||
@@ -81,22 +81,23 @@ namespace Avalonia.Controls.UnitTests
|
||||
Assert.Empty(receivedArgs.AddedItems);
|
||||
}
|
||||
|
||||
_helper.Click(target.Presenter.Panel.Children[1]);
|
||||
var panel = target.Presenter!.Panel!;
|
||||
_helper.Click(panel.Children[1]);
|
||||
|
||||
VerifyAdded("Bar");
|
||||
|
||||
receivedArgs = null;
|
||||
_helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control);
|
||||
_helper.Click(panel.Children[2], modifiers: KeyModifiers.Control);
|
||||
|
||||
VerifyAdded("Baz");
|
||||
|
||||
receivedArgs = null;
|
||||
_helper.Click(target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Control);
|
||||
_helper.Click(panel.Children[3], modifiers: KeyModifiers.Control);
|
||||
|
||||
VerifyAdded("Qux");
|
||||
|
||||
receivedArgs = null;
|
||||
_helper.Click(target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Control);
|
||||
_helper.Click(panel.Children[1], modifiers: KeyModifiers.Control);
|
||||
|
||||
VerifyRemoved("Bar");
|
||||
}
|
||||
@@ -120,15 +121,16 @@ namespace Avalonia.Controls.UnitTests
|
||||
root.LayoutManager.ExecuteInitialLayoutPass();
|
||||
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
_helper.Click(target.Presenter.Panel.Children[1]);
|
||||
_helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control);
|
||||
_helper.Click(target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Control);
|
||||
var panel = target.Presenter!.Panel!;
|
||||
_helper.Click(panel.Children[1]);
|
||||
_helper.Click(panel.Children[2], modifiers: KeyModifiers.Control);
|
||||
_helper.Click(panel.Children[3], modifiers: KeyModifiers.Control);
|
||||
|
||||
Assert.Equal(1, target.SelectedIndex);
|
||||
Assert.Equal("Bar", target.SelectedItem);
|
||||
Assert.Equal(new[] { "Bar", "Baz", "Qux" }, target.SelectedItems);
|
||||
|
||||
_helper.Click(target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Control);
|
||||
_helper.Click(panel.Children[1], modifiers: KeyModifiers.Control);
|
||||
|
||||
Assert.Equal(2, target.SelectedIndex);
|
||||
Assert.Equal("Baz", target.SelectedItem);
|
||||
@@ -154,13 +156,14 @@ namespace Avalonia.Controls.UnitTests
|
||||
root.LayoutManager.ExecuteInitialLayoutPass();
|
||||
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
_helper.Click(target.Presenter.Panel.Children[1]);
|
||||
_helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control);
|
||||
var panel = target.Presenter!.Panel!;
|
||||
_helper.Click(panel.Children[1]);
|
||||
_helper.Click(panel.Children[2], modifiers: KeyModifiers.Control);
|
||||
|
||||
Assert.Equal(1, target.SelectedIndex);
|
||||
Assert.Equal("Bar", target.SelectedItem);
|
||||
|
||||
_helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Control);
|
||||
_helper.Click(panel.Children[2], modifiers: KeyModifiers.Control);
|
||||
|
||||
Assert.Equal(1, target.SelectedIndex);
|
||||
Assert.Equal("Bar", target.SelectedItem);
|
||||
@@ -185,13 +188,14 @@ namespace Avalonia.Controls.UnitTests
|
||||
root.LayoutManager.ExecuteInitialLayoutPass();
|
||||
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
var panel = target.Presenter!.Panel!;
|
||||
// Select first range
|
||||
_helper.Click(target.Presenter.Panel.Children[0]);
|
||||
_helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Shift);
|
||||
_helper.Click(panel.Children[0]);
|
||||
_helper.Click(panel.Children[2], modifiers: KeyModifiers.Shift);
|
||||
|
||||
// Select second range
|
||||
_helper.Click(target.Presenter.Panel.Children[4], modifiers: KeyModifiers.Control);
|
||||
_helper.Click(target.Presenter.Panel.Children[6], modifiers: KeyModifiers.Control | KeyModifiers.Shift);
|
||||
_helper.Click(panel.Children[4], modifiers: KeyModifiers.Control);
|
||||
_helper.Click(panel.Children[6], modifiers: KeyModifiers.Control | KeyModifiers.Shift);
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar", "Baz", "Boo", "Far", "Faz" }, target.SelectedItems);
|
||||
}
|
||||
@@ -215,10 +219,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
root.LayoutManager.ExecuteInitialLayoutPass();
|
||||
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
_helper.Click(target.Presenter.Panel.Children[3]);
|
||||
_helper.Click(target.Presenter.Panel.Children[4], modifiers: KeyModifiers.Control);
|
||||
|
||||
var panel = target.Presenter.Panel;
|
||||
var panel = target.Presenter!.Panel!;
|
||||
_helper.Click(panel.Children[3]);
|
||||
_helper.Click(panel.Children[4], modifiers: KeyModifiers.Control);
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar" }, target.SelectedItems);
|
||||
Assert.Equal(new[] { 3, 4 }, SelectedContainers(target));
|
||||
@@ -243,10 +246,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
root.LayoutManager.ExecuteInitialLayoutPass();
|
||||
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
_helper.Click(target.Presenter.Panel.Children[3]);
|
||||
_helper.Click(target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift);
|
||||
|
||||
var panel = target.Presenter.Panel;
|
||||
var panel = target.Presenter!.Panel!;
|
||||
_helper.Click(panel.Children[3]);
|
||||
_helper.Click(panel.Children[5], modifiers: KeyModifiers.Shift);
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar", "Baz" }, target.SelectedItems);
|
||||
Assert.Equal(new[] { 3, 4, 5 }, SelectedContainers(target));
|
||||
@@ -271,10 +273,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
root.LayoutManager.ExecuteInitialLayoutPass();
|
||||
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
_helper.Click(target.Presenter.Panel.Children[0]);
|
||||
_helper.Click(target.Presenter.Panel.Children[5], modifiers: KeyModifiers.Shift);
|
||||
|
||||
var panel = target.Presenter.Panel;
|
||||
var panel = target.Presenter!.Panel!;
|
||||
_helper.Click(panel.Children[0]);
|
||||
_helper.Click(panel.Children[5], modifiers: KeyModifiers.Shift);
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, target.SelectedItems);
|
||||
Assert.Equal(new[] { 0, 1, 2, 3, 4, 5 }, SelectedContainers(target));
|
||||
@@ -299,7 +300,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
|
||||
SelectionChangedEventArgs receivedArgs = null;
|
||||
SelectionChangedEventArgs? receivedArgs = null;
|
||||
|
||||
target.SelectionChanged += (_, args) => receivedArgs = args;
|
||||
|
||||
@@ -317,17 +318,18 @@ namespace Avalonia.Controls.UnitTests
|
||||
Assert.Empty(receivedArgs.AddedItems);
|
||||
}
|
||||
|
||||
_helper.Click(target.Presenter.Panel.Children[1]);
|
||||
var panel = target.Presenter!.Panel!;
|
||||
_helper.Click(panel.Children[1]);
|
||||
|
||||
VerifyAdded("Bar");
|
||||
|
||||
receivedArgs = null;
|
||||
_helper.Click(target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Shift);
|
||||
_helper.Click(panel.Children[3], modifiers: KeyModifiers.Shift);
|
||||
|
||||
VerifyAdded("Baz", "Qux");
|
||||
|
||||
receivedArgs = null;
|
||||
_helper.Click(target.Presenter.Panel.Children[2], modifiers: KeyModifiers.Shift);
|
||||
_helper.Click(panel.Children[2], modifiers: KeyModifiers.Shift);
|
||||
|
||||
VerifyRemoved("Qux");
|
||||
}
|
||||
@@ -351,19 +353,20 @@ namespace Avalonia.Controls.UnitTests
|
||||
root.LayoutManager.ExecuteInitialLayoutPass();
|
||||
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
_helper.Click(target.Presenter.Panel.Children[0]);
|
||||
var panel = target.Presenter!.Panel!;
|
||||
_helper.Click(panel.Children[0]);
|
||||
|
||||
Assert.Equal(new[] { "Foo" }, target.SelectedItems);
|
||||
|
||||
_helper.Click(target.Presenter.Panel.Children[4], modifiers: KeyModifiers.Control);
|
||||
_helper.Click(panel.Children[4], modifiers: KeyModifiers.Control);
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar" }, target.SelectedItems);
|
||||
|
||||
_helper.Click(target.Presenter.Panel.Children[3], modifiers: KeyModifiers.Control);
|
||||
_helper.Click(panel.Children[3], modifiers: KeyModifiers.Control);
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar", "Foo" }, target.SelectedItems);
|
||||
|
||||
_helper.Click(target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Control);
|
||||
_helper.Click(panel.Children[1], modifiers: KeyModifiers.Control);
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar", "Foo", "Bar" }, target.SelectedItems);
|
||||
}
|
||||
@@ -389,9 +392,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
target.SelectAll();
|
||||
|
||||
Assert.Equal(3, target.SelectedItems.Count);
|
||||
Assert.Equal(3, target.SelectedItems!.Count);
|
||||
|
||||
_helper.Click(target.Presenter.Panel.Children[0]);
|
||||
_helper.Click(target.Presenter!.Panel!.Children[0]);
|
||||
|
||||
Assert.Equal(1, target.SelectedItems.Count);
|
||||
Assert.Equal(new[] { "Foo", }, target.SelectedItems);
|
||||
@@ -419,9 +422,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
target.SelectAll();
|
||||
|
||||
Assert.Equal(3, target.SelectedItems.Count);
|
||||
Assert.Equal(3, target.SelectedItems!.Count);
|
||||
|
||||
_helper.Click(target.Presenter.Panel.Children[0], MouseButton.Right);
|
||||
_helper.Click(target.Presenter!.Panel!.Children[0], MouseButton.Right);
|
||||
|
||||
Assert.Equal(3, target.SelectedItems.Count);
|
||||
}
|
||||
@@ -446,13 +449,16 @@ namespace Avalonia.Controls.UnitTests
|
||||
root.LayoutManager.ExecuteInitialLayoutPass();
|
||||
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
_helper.Click(target.Presenter.Panel.Children[0]);
|
||||
_helper.Click(target.Presenter.Panel.Children[1], modifiers: KeyModifiers.Shift);
|
||||
var panel = target.Presenter!.Panel!;
|
||||
_helper.Click(panel.Children[0]);
|
||||
_helper.Click(panel.Children[1], modifiers: KeyModifiers.Shift);
|
||||
|
||||
Assert.NotNull(target.SelectedItems);
|
||||
Assert.Equal(2, target.SelectedItems.Count);
|
||||
|
||||
_helper.Click(target.Presenter.Panel.Children[2], MouseButton.Right);
|
||||
_helper.Click(panel.Children[2], MouseButton.Right);
|
||||
|
||||
Assert.NotNull(target.SelectedItems);
|
||||
Assert.Equal(1, target.SelectedItems.Count);
|
||||
}
|
||||
}
|
||||
@@ -477,9 +483,11 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
|
||||
_helper.Click(target.Presenter.Panel.Children[0]);
|
||||
_helper.Click(target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Shift);
|
||||
var panel = target.Presenter!.Panel!;
|
||||
_helper.Click(panel.Children[0]);
|
||||
_helper.Click(panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Shift);
|
||||
|
||||
Assert.NotNull(target.SelectedItems);
|
||||
Assert.Equal(1, target.SelectedItems.Count);
|
||||
}
|
||||
}
|
||||
@@ -504,9 +512,11 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
|
||||
_helper.Click(target.Presenter.Panel.Children[0]);
|
||||
_helper.Click(target.Presenter.Panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Control);
|
||||
var panel = target.Presenter!.Panel!;
|
||||
_helper.Click(panel.Children[0]);
|
||||
_helper.Click(panel.Children[2], MouseButton.Right, modifiers: KeyModifiers.Control);
|
||||
|
||||
Assert.NotNull(target.SelectedItems);
|
||||
Assert.Equal(1, target.SelectedItems.Count);
|
||||
}
|
||||
}
|
||||
@@ -532,19 +542,19 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar", }, target.SelectedItems);
|
||||
Assert.Equal(new[] { 0, 1 }, SelectedContainers(target));
|
||||
Assert.True(target.ContainerFromIndex(1).IsFocused);
|
||||
Assert.True(target.ContainerFromIndex(1)!.IsFocused);
|
||||
|
||||
RaiseKeyEvent(target, Key.Down, KeyModifiers.Shift);
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar", "Baz", }, target.SelectedItems);
|
||||
Assert.Equal(new[] { 0, 1, 2 }, SelectedContainers(target));
|
||||
Assert.True(target.ContainerFromIndex(2).IsFocused);
|
||||
Assert.True(target.ContainerFromIndex(2)!.IsFocused);
|
||||
|
||||
RaiseKeyEvent(target, Key.Up, KeyModifiers.Shift);
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar", }, target.SelectedItems);
|
||||
Assert.Equal(new[] { 0, 1 }, SelectedContainers(target));
|
||||
Assert.True(target.ContainerFromIndex(1).IsFocused);
|
||||
Assert.True(target.ContainerFromIndex(1)!.IsFocused);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -569,7 +579,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar", "Baz" }, target.SelectedItems);
|
||||
Assert.Equal(new[] { 0, 1, 2 }, SelectedContainers(target));
|
||||
Assert.True(target.ContainerFromIndex(2).IsFocused);
|
||||
Assert.True(target.ContainerFromIndex(2)!.IsFocused);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -593,19 +603,19 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar" }, target.SelectedItems);
|
||||
Assert.Equal(new[] { 0, 1 }, SelectedContainers(target));
|
||||
Assert.True(target.ContainerFromIndex(1).IsFocused);
|
||||
Assert.True(target.ContainerFromIndex(1)!.IsFocused);
|
||||
|
||||
RaiseKeyEvent(target, Key.Down, KeyModifiers.Control);
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar" }, target.SelectedItems);
|
||||
Assert.Equal(new[] { 0, 1 }, SelectedContainers(target));
|
||||
Assert.True(target.ContainerFromIndex(2).IsFocused);
|
||||
Assert.True(target.ContainerFromIndex(2)!.IsFocused);
|
||||
|
||||
RaiseKeyEvent(target, Key.Down, KeyModifiers.Shift);
|
||||
|
||||
Assert.Equal(new[] { "Foo", "Bar", "Baz", "Qux" }, target.SelectedItems);
|
||||
Assert.Equal(new[] { 0, 1, 2, 3 }, SelectedContainers(target));
|
||||
Assert.True(target.ContainerFromIndex(3).IsFocused);
|
||||
Assert.True(target.ContainerFromIndex(3)!.IsFocused);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -700,7 +710,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
private static IEnumerable<int> SelectedContainers(SelectingItemsControl target)
|
||||
{
|
||||
return target.Presenter.Panel.Children
|
||||
return target.Presenter!.Panel!.Children
|
||||
.Select(x => x.Classes.Contains(":selected") ? target.IndexFromContainer(x) : -1)
|
||||
.Where(x => x != -1);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Prepare(target);
|
||||
|
||||
target.Presenter.Panel.Children[0].RaiseEvent(new GotFocusEventArgs
|
||||
target.Presenter!.Panel!.Children[0].RaiseEvent(new GotFocusEventArgs
|
||||
{
|
||||
NavigationMethod = NavigationMethod.Tab,
|
||||
});
|
||||
@@ -57,7 +57,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
Prepare(target);
|
||||
|
||||
target.Presenter.Panel.Children[0].RaiseEvent(new GotFocusEventArgs
|
||||
target.Presenter!.Panel!.Children[0].RaiseEvent(new GotFocusEventArgs
|
||||
{
|
||||
NavigationMethod = NavigationMethod.Directional,
|
||||
KeyModifiers = KeyModifiers.Control
|
||||
@@ -86,7 +86,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
};
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
Prepare(target);
|
||||
_mouse.Click(target.Presenter.Panel.Children[0]);
|
||||
_mouse.Click(target.Presenter!.Panel!.Children[0]);
|
||||
|
||||
Assert.Equal(0, target.SelectedIndex);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
ItemsSource = new[] { "Foo", "Bar", "Baz " }
|
||||
};
|
||||
Prepare(target);
|
||||
_pen.Down(target.Presenter.Panel.Children[0], MouseButton.Right);
|
||||
_pen.Down(target.Presenter!.Panel!.Children[0], MouseButton.Right);
|
||||
|
||||
Assert.Equal(0, target.SelectedIndex);
|
||||
}
|
||||
@@ -122,7 +122,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
ItemsSource = new[] { "Foo", "Bar", "Baz " }
|
||||
};
|
||||
Prepare(target);
|
||||
_pen.Down(target.Presenter.Panel.Children[0]);
|
||||
_pen.Down(target.Presenter!.Panel!.Children[0]);
|
||||
|
||||
Assert.Equal(-1, target.SelectedIndex);
|
||||
}
|
||||
@@ -156,7 +156,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
});
|
||||
|
||||
var pointer = type == PointerType.Mouse ? _mouse : _pen;
|
||||
pointer.Click(target.Presenter.Panel.Children[0], MouseButton.Right, position: new Point(5, 5));
|
||||
pointer.Click(target.Presenter!.Panel!.Children[0], MouseButton.Right, position: new Point(5, 5));
|
||||
|
||||
Assert.True(contextRaised);
|
||||
Assert.Equal(0, target.SelectedIndex);
|
||||
@@ -177,7 +177,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Prepare(target);
|
||||
target.SelectedIndex = 0;
|
||||
|
||||
_mouse.Click(target.Presenter.Panel.Children[0]);
|
||||
_mouse.Click(target.Presenter!.Panel!.Children[0]);
|
||||
|
||||
Assert.Equal(0, target.SelectedIndex);
|
||||
}
|
||||
@@ -197,7 +197,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
Prepare(target);
|
||||
|
||||
_mouse.Click(target.Presenter.Panel.Children[0]);
|
||||
_mouse.Click(target.Presenter!.Panel!.Children[0]);
|
||||
|
||||
Assert.Equal(0, target.SelectedIndex);
|
||||
}
|
||||
@@ -219,7 +219,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Prepare(target);
|
||||
target.SelectedIndex = 0;
|
||||
|
||||
_mouse.Click(target.Presenter.Panel.Children[0]);
|
||||
_mouse.Click(target.Presenter!.Panel!.Children[0]);
|
||||
|
||||
Assert.Equal(-1, target.SelectedIndex);
|
||||
}
|
||||
@@ -240,7 +240,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Prepare(target);
|
||||
target.SelectedIndex = 0;
|
||||
|
||||
_mouse.Click(target.Presenter.Panel.Children[0]);
|
||||
_mouse.Click(target.Presenter!.Panel!.Children[0]);
|
||||
|
||||
Assert.Equal(0, target.SelectedIndex);
|
||||
}
|
||||
@@ -261,7 +261,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Prepare(target);
|
||||
target.SelectedIndex = 1;
|
||||
|
||||
_mouse.Click(target.Presenter.Panel.Children[0]);
|
||||
_mouse.Click(target.Presenter!.Panel!.Children[0]);
|
||||
|
||||
Assert.Equal(0, target.SelectedIndex);
|
||||
}
|
||||
@@ -292,7 +292,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
|
||||
{
|
||||
var viewModel = new TestStackOverflowViewModel() { Items = new List<string> { "foo", "bar", "baz" } };
|
||||
var viewModel = new TestStackOverflowViewModel() { Items = ["foo", "bar", "baz"] };
|
||||
|
||||
var target = new ListBox
|
||||
{
|
||||
@@ -316,17 +316,17 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
private class TestStackOverflowViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public List<string> Items { get; set; }
|
||||
public List<string?> Items { get; set; } = [];
|
||||
|
||||
public int SetterInvokedCount { get; private set; }
|
||||
|
||||
public const int MaxInvokedCount = 1000;
|
||||
|
||||
private string _selectedItem;
|
||||
private string? _selectedItem;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public string SelectedItem
|
||||
public string? SelectedItem
|
||||
{
|
||||
get { return _selectedItem; }
|
||||
set
|
||||
|
||||
@@ -977,7 +977,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
});
|
||||
}
|
||||
|
||||
private static IDisposable Start(TestServices services = null)
|
||||
private static IDisposable Start(TestServices? services = null)
|
||||
{
|
||||
CultureInfo.CurrentCulture = CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
|
||||
return UnitTestApplication.Start((services ?? Services).With(assetLoader: new StandardAssetLoader()));
|
||||
@@ -986,7 +986,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
private class Class1 : NotifyingBase
|
||||
{
|
||||
private int _foo;
|
||||
private string _bar;
|
||||
private string? _bar;
|
||||
|
||||
public int Foo
|
||||
{
|
||||
@@ -994,7 +994,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
set { _foo = value; RaisePropertyChanged(); }
|
||||
}
|
||||
|
||||
public string Bar
|
||||
public string? Bar
|
||||
{
|
||||
get { return _bar; }
|
||||
set { _bar = value; RaisePropertyChanged(); }
|
||||
@@ -1005,7 +1005,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
private readonly ILayoutManager _layoutManager;
|
||||
|
||||
public TestTopLevel(ITopLevelImpl impl, ILayoutManager layoutManager = null)
|
||||
public TestTopLevel(ITopLevelImpl impl, ILayoutManager? layoutManager = null)
|
||||
: base(impl)
|
||||
{
|
||||
_layoutManager = layoutManager ?? new LayoutManager(this);
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
public class MenuItemTests : ScopedTestBase
|
||||
{
|
||||
private Mock<IPopupImpl> popupImpl;
|
||||
private Mock<IPopupImpl>? _popupImpl;
|
||||
|
||||
[Fact]
|
||||
public void Header_Of_Minus_Should_Apply_Separator_Pseudoclass()
|
||||
@@ -238,7 +238,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var window = new Window { Content = new Panel { ContextMenu = contextMenu } };
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
window.Presenter.ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
|
||||
|
||||
Assert.True(target.IsEffectivelyEnabled);
|
||||
@@ -280,7 +280,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var window = new Window { Content = button };
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
window.Presenter.ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
|
||||
Assert.True(target.IsEffectivelyEnabled);
|
||||
target.Command = command;
|
||||
@@ -321,7 +321,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var window = new Window { Content = new Panel { ContextMenu = contextMenu } };
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
window.Presenter.ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
contextMenu.Open();
|
||||
|
||||
Dispatcher.UIThread.RunJobs(DispatcherPriority.Loaded);
|
||||
@@ -421,7 +421,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
window.Show();
|
||||
window.LayoutManager.ExecuteInitialLayoutPass();
|
||||
|
||||
var panel = Assert.IsType<StackPanel>(menu.Presenter.Panel);
|
||||
var panel = Assert.IsType<StackPanel>(menu.Presenter!.Panel);
|
||||
Assert.Equal(2, panel.Children.Count);
|
||||
|
||||
for (var i = 0; i < panel.Children.Count; i++)
|
||||
@@ -819,7 +819,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
public void MenuItem_CommandParameter_Does_Not_Change_While_Execution()
|
||||
{
|
||||
var target = new MenuItem();
|
||||
object lastParamenter = "A";
|
||||
object? lastParamenter = "A";
|
||||
var generator = new Random();
|
||||
var onlyOnce = false;
|
||||
var command = new TestCommand(parameter =>
|
||||
@@ -851,16 +851,16 @@ namespace Avalonia.Controls.UnitTests
|
||||
screenImpl.Setup(X => X.AllScreens).Returns(new[] { new Screen(1, screen, screen, true) });
|
||||
|
||||
var windowImpl = MockWindowingPlatform.CreateWindowMock();
|
||||
popupImpl = MockWindowingPlatform.CreatePopupMock(windowImpl.Object);
|
||||
popupImpl.SetupGet(x => x.RenderScaling).Returns(1);
|
||||
windowImpl.Setup(x => x.CreatePopup()).Returns(popupImpl.Object);
|
||||
_popupImpl = MockWindowingPlatform.CreatePopupMock(windowImpl.Object);
|
||||
_popupImpl.SetupGet(x => x.RenderScaling).Returns(1);
|
||||
windowImpl.Setup(x => x.CreatePopup()).Returns(_popupImpl.Object);
|
||||
|
||||
windowImpl.Setup(x => x.TryGetFeature(It.Is<Type>(t => t == typeof(IScreenImpl)))).Returns(screenImpl.Object);
|
||||
|
||||
var services = TestServices.StyledWindow.With(
|
||||
inputManager: new InputManager(),
|
||||
windowImpl: windowImpl.Object,
|
||||
windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object, x => popupImpl.Object));
|
||||
windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object, x => _popupImpl.Object));
|
||||
|
||||
return UnitTestApplication.Start(services);
|
||||
}
|
||||
@@ -868,7 +868,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
private record MenuViewModel(string Header)
|
||||
{
|
||||
public IList<MenuViewModel> Children { get; set; }
|
||||
public IList<MenuViewModel> Children { get; set; } = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
that the object graph is completely ready to use after it's built
|
||||
rather than have pending continuations queued by SynchronizationContext.
|
||||
*/
|
||||
object _found = null;
|
||||
private object? _found;
|
||||
|
||||
async void FindAsync(INameScope scope, string name)
|
||||
{
|
||||
_found = await scope.FindAsync(name);
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Threading;
|
||||
using Avalonia.UnitTests;
|
||||
using Xunit;
|
||||
@@ -27,7 +26,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
|
||||
Assert.True(DataValidationErrors.GetHasErrors(control));
|
||||
Assert.True(DataValidationErrors.GetErrors(control).SequenceEqual(new[] { exception }));
|
||||
Assert.Equal([exception], DataValidationErrors.GetErrors(control));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,7 +41,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
|
||||
Assert.True(DataValidationErrors.GetHasErrors(control));
|
||||
Assert.True(DataValidationErrors.GetErrors(control).SequenceEqual(new[] { exception }));
|
||||
Assert.Equal([exception], DataValidationErrors.GetErrors(control));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -101,19 +100,19 @@ namespace Avalonia.Controls.UnitTests
|
||||
});
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Increment_Decrement_TestData()
|
||||
public static IEnumerable<object?[]> Increment_Decrement_TestData()
|
||||
{
|
||||
// if min and max are not defined and value was null, 0 should be ne new value after spin
|
||||
yield return new object[] { decimal.MinValue, decimal.MaxValue, null, SpinDirection.Decrease, 0m };
|
||||
yield return new object[] { decimal.MinValue, decimal.MaxValue, null, SpinDirection.Increase, 0m };
|
||||
yield return [decimal.MinValue, decimal.MaxValue, null, SpinDirection.Decrease, 0m];
|
||||
yield return [decimal.MinValue, decimal.MaxValue, null, SpinDirection.Increase, 0m];
|
||||
|
||||
// if no value was defined, but Min or Max are defined, use these as the new value
|
||||
yield return new object[] { -400m, -200m, null, SpinDirection.Decrease, -200m };
|
||||
yield return new object[] { 200m, 400m, null, SpinDirection.Increase, 200m };
|
||||
yield return [-400m, -200m, null, SpinDirection.Decrease, -200m];
|
||||
yield return [200m, 400m, null, SpinDirection.Increase, 200m];
|
||||
|
||||
// Value should be clamped to Min / Max after spinning
|
||||
yield return new object[] { 200m, 400m, 5m, SpinDirection.Increase, 200m };
|
||||
yield return new object[] { 200m, 400m, 200m, SpinDirection.Decrease, 200m };
|
||||
yield return [200m, 400m, 5m, SpinDirection.Increase, 200m];
|
||||
yield return [200m, 400m, 200m, SpinDirection.Decrease, 200m];
|
||||
}
|
||||
|
||||
private void RunTest(Action<NumericUpDown, TextBox> test)
|
||||
@@ -125,7 +124,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var window = new Window { Content = control };
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
window.Presenter.ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
test.Invoke(control, textBox);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
using Avalonia.Controls.Platform;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Input.GestureRecognizers;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.UnitTests;
|
||||
using Avalonia.VisualTree;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
@@ -575,7 +573,7 @@ namespace Avalonia.Controls.UnitTests.Platform
|
||||
bool isTopLevel = false,
|
||||
bool hasSubMenu = false,
|
||||
bool isSubMenuOpen = false,
|
||||
IMenuElement parent = null)
|
||||
IMenuElement? parent = null)
|
||||
{
|
||||
var mock = new Mock<Control>();
|
||||
var item = mock.As<IMenuItem>();
|
||||
@@ -589,17 +587,18 @@ namespace Avalonia.Controls.UnitTests.Platform
|
||||
|
||||
private class TestTimer
|
||||
{
|
||||
private Action _action;
|
||||
private Action? _action;
|
||||
|
||||
public bool ActionIsQueued => _action != null;
|
||||
|
||||
public void Pulse()
|
||||
{
|
||||
Assert.NotNull(_action);
|
||||
_action();
|
||||
_action = null;
|
||||
}
|
||||
|
||||
public void RunOnce(Action action, TimeSpan timeSpan)
|
||||
public void RunOnce(Action? action, TimeSpan timeSpan)
|
||||
{
|
||||
if (_action != null)
|
||||
{
|
||||
@@ -614,14 +613,14 @@ namespace Avalonia.Controls.UnitTests.Platform
|
||||
{
|
||||
public int Id { get; } = Pointer.GetNextFreeId();
|
||||
|
||||
public void Capture(IInputElement control)
|
||||
public void Capture(IInputElement? control)
|
||||
{
|
||||
Captured = control;
|
||||
}
|
||||
|
||||
public IInputElement Captured { get; set; }
|
||||
public PointerType Type { get; }
|
||||
public bool IsPrimary { get; } = true;
|
||||
public IInputElement? Captured { get; set; }
|
||||
public PointerType Type => PointerType.Mouse;
|
||||
public bool IsPrimary => true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
|
||||
target.Content = "Foo";
|
||||
|
||||
var child = target.Child;
|
||||
Assert.NotNull(child);
|
||||
Assert.Equal(parent, child.GetLogicalParent());
|
||||
Assert.Equal(new[] { child }, parent.GetLogicalChildren());
|
||||
}
|
||||
@@ -97,6 +98,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
|
||||
target.Content = "Foo";
|
||||
|
||||
var child = target.Child;
|
||||
Assert.NotNull(child);
|
||||
Assert.Equal(target, child.GetVisualParent());
|
||||
Assert.Equal(new[] { child }, target.GetVisualChildren());
|
||||
}
|
||||
@@ -289,7 +291,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
|
||||
var canvas = new Canvas();
|
||||
var (target, host) = CreateTarget();
|
||||
var viewModel = new TestViewModel { Content = "foo" };
|
||||
var dataContexts = new List<object>();
|
||||
var dataContexts = new List<object?>();
|
||||
|
||||
target.Bind(ContentPresenter.ContentProperty, (IBinding)new TemplateBinding(ContentControl.ContentProperty));
|
||||
canvas.GetObservable(ContentPresenter.DataContextProperty).Subscribe(x => dataContexts.Add(x));
|
||||
@@ -302,7 +304,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
|
||||
|
||||
viewModel.Content = 42;
|
||||
|
||||
Assert.Equal(new object[]
|
||||
Assert.Equal(new object?[]
|
||||
{
|
||||
null,
|
||||
"foo",
|
||||
@@ -391,19 +393,19 @@ namespace Avalonia.Controls.UnitTests.Presenters
|
||||
|
||||
templatedParent.ApplyTemplate();
|
||||
|
||||
return (templatedParent.Presenter, templatedParent);
|
||||
return (templatedParent.Presenter!, templatedParent);
|
||||
}
|
||||
|
||||
private class TestContentControl : ContentControl, IContentPresenterHost
|
||||
{
|
||||
public Control Child { get; set; }
|
||||
public Control? Child { get; set; }
|
||||
}
|
||||
|
||||
private class TestViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private object _content;
|
||||
private object? _content;
|
||||
|
||||
public object Content
|
||||
public object? Content
|
||||
{
|
||||
get => _content;
|
||||
set
|
||||
@@ -416,7 +418,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,8 @@ namespace Avalonia.Controls.UnitTests.Presenters
|
||||
(contentControl as ISetLogicalParent).SetParent(parentMock.Object);
|
||||
|
||||
contentControl.ApplyTemplate();
|
||||
var target = contentControl.Presenter as ContentPresenter;
|
||||
var target = contentControl.Presenter;
|
||||
Assert.NotNull(target);
|
||||
|
||||
contentControl.Content = "foo";
|
||||
|
||||
@@ -199,8 +200,8 @@ namespace Avalonia.Controls.UnitTests.Presenters
|
||||
|
||||
logicalChildren = target.GetLogicalChildren();
|
||||
|
||||
Assert.Single(logicalChildren);
|
||||
Assert.NotEqual(foo, logicalChildren.First());
|
||||
var logicalChild = Assert.Single(logicalChildren);
|
||||
Assert.NotEqual(foo, logicalChild);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -446,7 +446,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
|
||||
target.Arrange(new Rect(0, 0, 100, 100));
|
||||
|
||||
// Border20 is at position 0,600 with bottom at Y=620
|
||||
var border20 = target.FindControl<Border>("Border20");
|
||||
var border20 = target.GetControl<Border>("Border20");
|
||||
target.BringDescendantIntoView(border20, new Rect(border20.Bounds.Size));
|
||||
|
||||
// With viewport Height of 100, border becomes fully visible when alligned from the bottom at Offset Y=520, i.e. 620-100
|
||||
@@ -458,7 +458,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
|
||||
target.Arrange(new Rect(0, 0, 100, 100));
|
||||
|
||||
// Border20 is at position 0,800 with bottom at Y=820
|
||||
var border40 = target.FindControl<Border>("Border40");
|
||||
var border40 = target.GetControl<Border>("Border40");
|
||||
target.BringDescendantIntoView(border40, new Rect(border40.Bounds.Size));
|
||||
|
||||
// With viewport Height of 100, border becomes fully visible when alligned from the bottom at Offset Y=720, i.e. 820-100
|
||||
@@ -502,7 +502,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
|
||||
target.UpdateChild();
|
||||
target.Measure(Size.Infinity);
|
||||
target.Arrange(new Rect(0, 0, 100, 100));
|
||||
var border3 = target.FindControl<Border>("Border3");
|
||||
var border3 = target.GetControl<Border>("Border3");
|
||||
target.BringDescendantIntoView(border3, new Rect(border3.Bounds.Size));
|
||||
|
||||
// Border3 is still in view, offset hasn't changed
|
||||
|
||||
+3
-3
@@ -323,7 +323,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
private Size _extent;
|
||||
private Vector _offset;
|
||||
private Size _viewport;
|
||||
private EventHandler _scrollInvalidated;
|
||||
private EventHandler? _scrollInvalidated;
|
||||
|
||||
public bool CanHorizontallyScroll { get; set; }
|
||||
public bool CanVerticallyScroll { get; set; }
|
||||
@@ -332,7 +332,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
public bool HasScrollInvalidatedSubscriber => _scrollInvalidated != null;
|
||||
|
||||
public event EventHandler ScrollInvalidated
|
||||
public event EventHandler? ScrollInvalidated
|
||||
{
|
||||
add => _scrollInvalidated += value;
|
||||
remove => _scrollInvalidated -= value;
|
||||
@@ -400,7 +400,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
return new Size(150, 150);
|
||||
}
|
||||
|
||||
public Control GetControlInDirection(NavigationDirection direction, Control from)
|
||||
public Control GetControlInDirection(NavigationDirection direction, Control? from)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
|
||||
Assert.Equal(1, presenter.TextLayout.TextLines.Count);
|
||||
Assert.Equal(1, presenter.TextLayout.TextLines[0].TextRuns.Count);
|
||||
Assert.NotNull(presenter.TextLayout.TextLines[0].TextRuns[0].Properties);
|
||||
Assert.Equal(fontStretch, presenter.TextLayout.TextLines[0].TextRuns[0].Properties.Typeface.Stretch);
|
||||
Assert.Equal(fontStretch, presenter.TextLayout.TextLines[0].TextRuns[0].Properties!.Typeface.Stretch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
{
|
||||
var target = CreateTarget(new Window());
|
||||
|
||||
Assert.True(((ILogical)target.Presenter).IsAttachedToLogicalTree);
|
||||
Assert.True(((ILogical)target.Presenter!).IsAttachedToLogicalTree);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,11 +53,11 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
window.Presenter.ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
target.ApplyTemplate();
|
||||
target.Popup.Open();
|
||||
target.Popup!.Open();
|
||||
|
||||
Assert.Equal(target.Popup, ((IStyleHost)target.Popup.Host).StylingParent);
|
||||
Assert.Equal(target.Popup, ((IStyleHost)target.Popup.Host!).StylingParent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +74,11 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
window.ApplyTemplate();
|
||||
target.Open();
|
||||
|
||||
|
||||
Assert.Single(((Visual)target.Host).GetVisualChildren());
|
||||
|
||||
var templatedChild = ((Visual)target.Host).GetVisualChildren().Single();
|
||||
var host = Assert.IsAssignableFrom<Visual>(target.Host);
|
||||
Assert.Single(host.GetVisualChildren());
|
||||
|
||||
var templatedChild = host.GetVisualChildren().Single();
|
||||
|
||||
Assert.IsType<LayoutTransformControl>(templatedChild);
|
||||
|
||||
@@ -93,8 +94,8 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
Assert.IsType<ContentPresenter>(contentPresenter);
|
||||
|
||||
|
||||
Assert.Equal((PopupRoot)target.Host, ((Control)templatedChild).TemplatedParent);
|
||||
Assert.Equal((PopupRoot)target.Host, ((Control)contentPresenter).TemplatedParent);
|
||||
Assert.Equal((PopupRoot)host, ((Control)templatedChild).TemplatedParent);
|
||||
Assert.Equal((PopupRoot)host, ((Control)contentPresenter).TemplatedParent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
target.Open();
|
||||
|
||||
Assert.Null(((Visual)target.Host).GetVisualParent());
|
||||
Assert.Null(((Visual)target.Host!).GetVisualParent());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,9 +181,9 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
window.Presenter.ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
target.ApplyTemplate();
|
||||
target.Popup.Open();
|
||||
target.Popup!.Open();
|
||||
target.PopupContent = null;
|
||||
}
|
||||
}
|
||||
@@ -194,7 +195,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
{
|
||||
var child = new ChildControl();
|
||||
var window = new Window();
|
||||
var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl);
|
||||
var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl!);
|
||||
popupImpl.Setup(x => x.MaxAutoSizeHint).Returns(new Size(1200, 1000));
|
||||
var target = CreateTarget(window, popupImpl.Object);
|
||||
|
||||
@@ -251,7 +252,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
using (UnitTestApplication.Start(TestServices.StyledWindow))
|
||||
{
|
||||
var window = new Window();
|
||||
var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl);
|
||||
var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl!);
|
||||
|
||||
var child = new Canvas
|
||||
{
|
||||
@@ -280,7 +281,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
using (UnitTestApplication.Start(TestServices.StyledWindow))
|
||||
{
|
||||
var window = new Window();
|
||||
var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl);
|
||||
var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl!);
|
||||
|
||||
var target = CreateTarget(window, popupImpl.Object);
|
||||
target.MinWidth = 400;
|
||||
@@ -296,7 +297,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
Assert.Equal(new Rect(0, 0, 400, 800), target.Bounds);
|
||||
Assert.Equal(new Size(400, 800), target.ClientSize);
|
||||
Assert.Equal(new Size(400, 800), target.PlatformImpl.ClientSize);
|
||||
Assert.Equal(new Size(400, 800), target.PlatformImpl!.ClientSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,7 +308,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
using (UnitTestApplication.Start(TestServices.StyledWindow))
|
||||
{
|
||||
var window = new Window();
|
||||
var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl);
|
||||
var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl!);
|
||||
var positioner = new Mock<IPopupPositioner>();
|
||||
popupImpl.Setup(x => x.PopupPositioner).Returns(positioner.Object);
|
||||
|
||||
@@ -330,9 +331,9 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
}
|
||||
}
|
||||
|
||||
private static PopupRoot CreateTarget(TopLevel popupParent, IPopupImpl impl = null)
|
||||
private static PopupRoot CreateTarget(TopLevel popupParent, IPopupImpl? impl = null)
|
||||
{
|
||||
impl ??= popupParent.PlatformImpl.CreatePopup();
|
||||
impl ??= popupParent.PlatformImpl!.CreatePopup()!;
|
||||
|
||||
var result = new PopupRoot(popupParent, impl)
|
||||
{
|
||||
@@ -351,8 +352,8 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
private class TemplatedControlWithPopup : Avalonia.Controls.Primitives.TemplatedControl
|
||||
{
|
||||
public static readonly StyledProperty<Control> PopupContentProperty =
|
||||
AvaloniaProperty.Register<TemplatedControlWithPopup, Control>(nameof(PopupContent));
|
||||
public static readonly StyledProperty<Control?> PopupContentProperty =
|
||||
AvaloniaProperty.Register<TemplatedControlWithPopup, Control?>(nameof(PopupContent));
|
||||
|
||||
public TemplatedControlWithPopup()
|
||||
{
|
||||
@@ -364,9 +365,9 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
});
|
||||
}
|
||||
|
||||
public Popup Popup { get; private set; }
|
||||
public Popup? Popup { get; private set; }
|
||||
|
||||
public Control PopupContent
|
||||
public Control? PopupContent
|
||||
{
|
||||
get => GetValue(PopupContentProperty);
|
||||
set => SetValue(PopupContentProperty, value);
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
{
|
||||
var target = new Popup();
|
||||
|
||||
Assert.Null(((Visual)target.Host));
|
||||
Assert.Null((Visual)target.Host!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
target.Open();
|
||||
|
||||
Assert.Equal(target, ((Visual)target.Host).Parent);
|
||||
Assert.Equal(target, ((Visual)target.Host!).Parent);
|
||||
Assert.Equal(target, ((Visual)target.Host).GetLogicalParent());
|
||||
}
|
||||
}
|
||||
@@ -213,7 +213,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
target.Open();
|
||||
|
||||
var popupRoot = (ILogical)((Visual)target.Host);
|
||||
var popupRoot = (ILogical)(Visual)target.Host!;
|
||||
|
||||
Assert.True(popupRoot.IsAttachedToLogicalTree);
|
||||
root.Content = null;
|
||||
@@ -332,7 +332,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
var popup = (Popup)target.GetTemplateChildren().First(x => x.Name == "popup");
|
||||
popup.Open();
|
||||
|
||||
var popupRoot = (Control)popup.Host;
|
||||
var popupRoot = (Control)popup.Host!;
|
||||
popupRoot.Measure(Size.Infinity);
|
||||
popupRoot.Arrange(new Rect(popupRoot.DesiredSize));
|
||||
|
||||
@@ -375,7 +375,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
if (UsePopupHost)
|
||||
{
|
||||
Assert.Equal(
|
||||
new object[]
|
||||
new object?[]
|
||||
{
|
||||
popupRoot,
|
||||
popupRoot,
|
||||
@@ -388,7 +388,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
else
|
||||
{
|
||||
Assert.Equal(
|
||||
new object[]
|
||||
new object?[]
|
||||
{
|
||||
popupRoot,
|
||||
popupRoot,
|
||||
@@ -423,7 +423,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
var popup = (Popup)target.GetTemplateChildren().First(x => x.Name == "popup");
|
||||
popup.Open();
|
||||
|
||||
var popupRoot = (Control)popup.Host;
|
||||
var popupRoot = (Control)popup.Host!;
|
||||
popupRoot.Measure(Size.Infinity);
|
||||
popupRoot.Arrange(new Rect(popupRoot.DesiredSize));
|
||||
|
||||
@@ -468,7 +468,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
if (UsePopupHost)
|
||||
{
|
||||
Assert.Equal(
|
||||
new object[]
|
||||
new object?[]
|
||||
{
|
||||
popupRoot,
|
||||
popupRoot,
|
||||
@@ -482,7 +482,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
else
|
||||
{
|
||||
Assert.Equal(
|
||||
new object[]
|
||||
new object?[]
|
||||
{
|
||||
popupRoot,
|
||||
popupRoot,
|
||||
@@ -518,7 +518,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
var popup = (Popup)target.GetTemplateChildren().First(x => x.Name == "popup");
|
||||
popup.Open();
|
||||
|
||||
var popupRoot = (Control)popup.Host;
|
||||
var popupRoot = (Control)popup.Host!;
|
||||
popupRoot.Measure(Size.Infinity);
|
||||
popupRoot.Arrange(new Rect(popupRoot.DesiredSize));
|
||||
|
||||
@@ -621,6 +621,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
var e = CreatePointerPressedEventArgs(window, new Point(10, 15));
|
||||
var overlay = LightDismissOverlayLayer.GetLightDismissOverlayLayer(window);
|
||||
Assert.NotNull(overlay);
|
||||
overlay.RaiseEvent(e);
|
||||
|
||||
Assert.Equal(1, raised);
|
||||
@@ -747,6 +748,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
p.Close();
|
||||
|
||||
var focusManager = window.FocusManager;
|
||||
Assert.NotNull(focusManager);
|
||||
var focus = focusManager.GetFocusedElement();
|
||||
Assert.Same(window, focus);
|
||||
}
|
||||
@@ -787,6 +789,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
windowTB.Focus();
|
||||
|
||||
var focusManager = window.FocusManager;
|
||||
Assert.NotNull(focusManager);
|
||||
var focus = focusManager.GetFocusedElement();
|
||||
|
||||
Assert.True(focus == windowTB);
|
||||
@@ -1167,7 +1170,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
var ev = new PointerPressedEventArgs(
|
||||
popupContent,
|
||||
pointer,
|
||||
popupContent.VisualRoot as PopupRoot,
|
||||
(PopupRoot)popupContent.VisualRoot!,
|
||||
new Point(50 , 50),
|
||||
0,
|
||||
new PointerPointProperties(RawInputModifiers.None, PointerUpdateKind.LeftButtonPressed),
|
||||
@@ -1231,6 +1234,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
var root = PreparedWindow(windowContent);
|
||||
|
||||
var adornerLayer = AdornerLayer.GetAdornerLayer(adorned);
|
||||
Assert.NotNull(adornerLayer);
|
||||
adornerLayer.Children.Add(adorner);
|
||||
AdornerLayer.SetAdornedElement(adorner, adorned);
|
||||
|
||||
@@ -1286,9 +1290,9 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
}
|
||||
}
|
||||
|
||||
private static PopupRoot CreateRoot(TopLevel popupParent, IPopupImpl impl = null)
|
||||
private static PopupRoot CreateRoot(TopLevel popupParent, IPopupImpl? impl = null)
|
||||
{
|
||||
impl ??= popupParent.PlatformImpl.CreatePopup();
|
||||
impl ??= popupParent.PlatformImpl!.CreatePopup()!;
|
||||
|
||||
var result = new PopupRoot(popupParent, impl)
|
||||
{
|
||||
@@ -1382,7 +1386,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
}, null);
|
||||
}
|
||||
|
||||
private static Window PreparedWindow(object content = null)
|
||||
private static Window PreparedWindow(object? content = null)
|
||||
{
|
||||
var w = new Window { Content = content };
|
||||
w.Show();
|
||||
@@ -1424,9 +1428,9 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
private class TestControl : Decorator
|
||||
{
|
||||
public event EventHandler DataContextBeginUpdate;
|
||||
public event EventHandler? DataContextBeginUpdate;
|
||||
|
||||
public new AvaloniaObject InheritanceParent => base.InheritanceParent;
|
||||
public new AvaloniaObject? InheritanceParent => base.InheritanceParent;
|
||||
|
||||
protected override void OnDataContextBeginUpdate()
|
||||
{
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
Value = 50
|
||||
};
|
||||
|
||||
Track track = null;
|
||||
Track? track = null;
|
||||
|
||||
var target = new TestRange()
|
||||
{
|
||||
@@ -157,7 +157,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
target.Bind(TestRange.ValueProperty, new Binding("Value") { Mode = BindingMode.TwoWay });
|
||||
|
||||
target.ApplyTemplate();
|
||||
track.Measure(new Size(100, 0));
|
||||
track!.Measure(new Size(100, 0));
|
||||
track.Arrange(new Rect(0, 0, 100, 0));
|
||||
|
||||
Assert.Equal(1, viewModel.SetterInvokedCount);
|
||||
@@ -218,7 +218,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
private double _value;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public double Value
|
||||
{
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
Vector = new Vector(0, 0)
|
||||
};
|
||||
|
||||
track.Thumb.RaiseEvent(ev);
|
||||
track.Thumb!.RaiseEvent(ev);
|
||||
});
|
||||
|
||||
Assert.Equal(ScrollEventType.ThumbTrack, raisedEvent.Arguments.ScrollEventType);
|
||||
@@ -110,7 +110,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
Vector = new Vector(0, 0)
|
||||
};
|
||||
|
||||
track.Thumb.RaiseEvent(ev);
|
||||
track.Thumb!.RaiseEvent(ev);
|
||||
});
|
||||
|
||||
Assert.Equal(ScrollEventType.EndScroll, raisedEvent.Arguments.ScrollEventType);
|
||||
|
||||
@@ -266,7 +266,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
foreach (var v in selected)
|
||||
{
|
||||
listBox.SelectedItems.Add(v);
|
||||
listBox.SelectedItems!.Add(v);
|
||||
}
|
||||
|
||||
listBox.BeginInit();
|
||||
@@ -289,7 +289,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
foreach (var v in new[] { "bar", "baz" })
|
||||
{
|
||||
listBox.SelectedItems.Add(v);
|
||||
listBox.SelectedItems!.Add(v);
|
||||
}
|
||||
|
||||
listBox.BeginInit();
|
||||
@@ -629,7 +629,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
Assert.Equal(items[1], target.SelectedItem);
|
||||
Assert.Equal(1, target.SelectedIndex);
|
||||
|
||||
SelectionChangedEventArgs receivedArgs = null;
|
||||
SelectionChangedEventArgs? receivedArgs = null;
|
||||
|
||||
target.SelectionChanged += (_, args) => receivedArgs = args;
|
||||
|
||||
@@ -669,7 +669,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
Assert.Equal(items[1], target.SelectedItem);
|
||||
Assert.Equal(1, target.SelectedIndex);
|
||||
|
||||
SelectionChangedEventArgs receivedArgs = null;
|
||||
SelectionChangedEventArgs? receivedArgs = null;
|
||||
|
||||
target.SelectionChanged += (_, args) => receivedArgs = args;
|
||||
|
||||
@@ -704,7 +704,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
Assert.Equal(items[0], target.SelectedItem);
|
||||
Assert.Equal(0, target.SelectedIndex);
|
||||
|
||||
SelectionChangedEventArgs receivedArgs = null;
|
||||
SelectionChangedEventArgs? receivedArgs = null;
|
||||
|
||||
target.SelectionChanged += (_, args) => receivedArgs = args;
|
||||
|
||||
@@ -741,7 +741,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
Assert.Equal(items[1], target.SelectedItem);
|
||||
Assert.Equal(1, target.SelectedIndex);
|
||||
|
||||
SelectionChangedEventArgs receivedArgs = null;
|
||||
SelectionChangedEventArgs? receivedArgs = null;
|
||||
|
||||
target.SelectionChanged += (_, args) => receivedArgs = args;
|
||||
|
||||
@@ -773,7 +773,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
Assert.Equal(items[1], target.SelectedItem);
|
||||
Assert.Equal(1, target.SelectedIndex);
|
||||
|
||||
SelectionChangedEventArgs receivedArgs = null;
|
||||
SelectionChangedEventArgs? receivedArgs = null;
|
||||
|
||||
target.SelectionChanged += (_, args) => receivedArgs = args;
|
||||
|
||||
@@ -1295,9 +1295,9 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
};
|
||||
|
||||
root.ApplyTemplate();
|
||||
root.Presenter.ApplyTemplate();
|
||||
root.Presenter!.ApplyTemplate();
|
||||
nested.ApplyTemplate();
|
||||
nested.Presenter.ApplyTemplate();
|
||||
nested.Presenter!.ApplyTemplate();
|
||||
|
||||
Assert.Equal(0, root.SelectedIndex);
|
||||
Assert.Equal(1, nested.SelectedIndex);
|
||||
@@ -1342,7 +1342,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
var container = target.ContainerFromIndex(1)!;
|
||||
_helper.Down(container);
|
||||
|
||||
var panel = target.Presenter.Panel;
|
||||
var panel = target.Presenter!.Panel;
|
||||
|
||||
Assert.Same(container, KeyboardNavigation.GetTabOnceActiveElement(target));
|
||||
}
|
||||
@@ -1363,12 +1363,11 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
Prepare(target);
|
||||
|
||||
_helper.Down(target.Presenter.Panel.Children[1]);
|
||||
var panel = target.Presenter!.Panel!;
|
||||
_helper.Down(panel.Children[1]);
|
||||
|
||||
items.RemoveAt(1);
|
||||
|
||||
var panel = target.Presenter.Panel;
|
||||
|
||||
Assert.Null(KeyboardNavigation.GetTabOnceActiveElement((InputElement)panel));
|
||||
}
|
||||
}
|
||||
@@ -1459,7 +1458,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
};
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
Prepare(target);
|
||||
_helper.Down((Interactive)target.Presenter.Panel.Children[3]);
|
||||
_helper.Down((Interactive)target.Presenter!.Panel!.Children[3]);
|
||||
|
||||
Assert.Equal(3, target.SelectedIndex);
|
||||
}
|
||||
@@ -1477,7 +1476,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
};
|
||||
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration());
|
||||
Prepare(target);
|
||||
_helper.Down((Interactive)target.Presenter.Panel.Children[3]);
|
||||
_helper.Down((Interactive)target.Presenter!.Panel!.Children[3]);
|
||||
|
||||
Assert.Equal(new[] { ":pressed", ":selected" }, target.Presenter.Panel.Children[3].Classes);
|
||||
}
|
||||
@@ -1592,7 +1591,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
Prepare(target);
|
||||
other.ApplyTemplate();
|
||||
other.Presenter.ApplyTemplate();
|
||||
other.Presenter!.ApplyTemplate();
|
||||
|
||||
items.Add("Foo");
|
||||
|
||||
@@ -1706,8 +1705,9 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
root.Measure(new Size(100, 100));
|
||||
root.Arrange(new Rect(0, 0, 100, 100));
|
||||
|
||||
Assert.True(target.Presenter.Panel.Children.Count > 0);
|
||||
Assert.True(target.Presenter.Panel.Children.Count < 100);
|
||||
var panel = target.Presenter!.Panel!;
|
||||
Assert.True(panel.Children.Count > 0);
|
||||
Assert.True(panel.Children.Count < 100);
|
||||
|
||||
target.SelectedItem = "Item99";
|
||||
|
||||
@@ -1716,7 +1716,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
Layout(target);
|
||||
|
||||
Assert.Equal(0, target.SelectedIndex);
|
||||
Assert.Equal(1, target.Presenter.Panel.Children.Where(x => x.IsVisible).Count());
|
||||
Assert.Equal(1, panel.Children.Count(x => x.IsVisible));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1743,7 +1743,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
Prepare(target);
|
||||
|
||||
var root = (TestRoot)target.Parent;
|
||||
var root = (TestRoot)target.Parent!;
|
||||
|
||||
target.AddHandler(Control.RequestBringIntoViewEvent, (s, e) => raised = true);
|
||||
|
||||
@@ -1777,7 +1777,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
Prepare(target);
|
||||
|
||||
var root = (TestRoot)target.Parent;
|
||||
var root = (TestRoot)target.Parent!;
|
||||
|
||||
target.AddHandler(Control.RequestBringIntoViewEvent, (s, e) => raised = true);
|
||||
|
||||
@@ -2555,7 +2555,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
private static void Layout(Control c)
|
||||
{
|
||||
((ILayoutRoot)c.GetVisualRoot()).LayoutManager.ExecuteLayoutPass();
|
||||
((ILayoutRoot)c.GetVisualRoot()!).LayoutManager.ExecuteLayoutPass();
|
||||
}
|
||||
|
||||
private static FuncControlTemplate Template()
|
||||
@@ -2573,7 +2573,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
private class Item : Control, ISelectable
|
||||
{
|
||||
public string Value { get; set; }
|
||||
public string? Value { get; set; }
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
@@ -2584,9 +2584,9 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
private class MasterViewModel : NotifyingBase
|
||||
{
|
||||
private ChildViewModel _child;
|
||||
private ChildViewModel? _child;
|
||||
|
||||
public ChildViewModel Child
|
||||
public ChildViewModel? Child
|
||||
{
|
||||
get { return _child; }
|
||||
set
|
||||
@@ -2599,15 +2599,15 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
private class ChildViewModel : NotifyingBase
|
||||
{
|
||||
public IList<Item> Items { get; set; }
|
||||
public Item SelectedItem { get; set; }
|
||||
public IList<Item> Items { get; set; } = [];
|
||||
public Item? SelectedItem { get; set; }
|
||||
public int SelectedIndex { get; set; }
|
||||
}
|
||||
|
||||
private class SelectionViewModel : NotifyingBase
|
||||
{
|
||||
private int _selectedIndex = -1;
|
||||
private object _selectedItem;
|
||||
private object? _selectedItem;
|
||||
|
||||
public SelectionViewModel()
|
||||
{
|
||||
@@ -2625,7 +2625,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
}
|
||||
}
|
||||
|
||||
public object SelectedItem
|
||||
public object? SelectedItem
|
||||
{
|
||||
get => _selectedItem;
|
||||
set
|
||||
@@ -2647,7 +2647,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
private class TestSelector : SelectingItemsControl
|
||||
{
|
||||
public new static readonly DirectProperty<SelectingItemsControl, IList> SelectedItemsProperty =
|
||||
public new static readonly DirectProperty<SelectingItemsControl, IList?> SelectedItemsProperty =
|
||||
SelectingItemsControl.SelectedItemsProperty;
|
||||
|
||||
public TestSelector()
|
||||
@@ -2666,7 +2666,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
set => base.Selection = value;
|
||||
}
|
||||
|
||||
public new IList SelectedItems
|
||||
public new IList? SelectedItems
|
||||
{
|
||||
get => base.SelectedItems;
|
||||
set => base.SelectedItems = value;
|
||||
@@ -2700,11 +2700,9 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
|
||||
public event NotifyCollectionChangedEventHandler CollectionChanged;
|
||||
public event NotifyCollectionChangedEventHandler? CollectionChanged;
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
|
||||
private sealed class FullSelectionViewModel : NotifyingBase
|
||||
{
|
||||
private ItemModel? _selectedItem;
|
||||
|
||||
+2
-2
@@ -111,7 +111,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
};
|
||||
|
||||
target.ApplyTemplate();
|
||||
target.Presenter.ApplyTemplate();
|
||||
target.Presenter!.ApplyTemplate();
|
||||
items.RemoveAt(0);
|
||||
|
||||
Assert.Equal(0, target.SelectedIndex);
|
||||
@@ -138,7 +138,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
private class ResetOnAdd : List<string>, INotifyCollectionChanged
|
||||
{
|
||||
public event NotifyCollectionChangedEventHandler CollectionChanged;
|
||||
public event NotifyCollectionChangedEventHandler? CollectionChanged;
|
||||
|
||||
public new void Add(string item)
|
||||
{
|
||||
|
||||
+4
-4
@@ -319,7 +319,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
public void Handles_Null_SelectedItem_When_SelectedValueBinding_Assigned()
|
||||
{
|
||||
// Issue #11220
|
||||
var items = new object[] { null };
|
||||
var items = new object?[] { null };
|
||||
var sic = new SelectingItemsControl
|
||||
{
|
||||
ItemsSource = items,
|
||||
@@ -366,15 +366,15 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
internal class TestClass
|
||||
{
|
||||
public TestClass(string name, string alt)
|
||||
public TestClass(string? name, string? alt)
|
||||
{
|
||||
Name = name;
|
||||
AltProperty = alt;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
public string? Name { get; set; }
|
||||
|
||||
public string AltProperty { get; set; }
|
||||
public string? AltProperty { get; set; }
|
||||
|
||||
public static List<TestClass> GetItems()
|
||||
{
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
Assert.Equal(0, target.SelectedIndex);
|
||||
Assert.Same(target.Items[0], target.SelectedItem);
|
||||
Assert.Same("first", ((TabItem)target.SelectedItem).Name);
|
||||
Assert.Same("first", ((TabItem)target.SelectedItem!).Name);
|
||||
}
|
||||
|
||||
private Control CreateTabStripTemplate(TabStrip parent, INameScope scope)
|
||||
|
||||
@@ -242,8 +242,8 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
|
||||
var border = contentControl.GetTemplateChildren().OfType<Border>().Single();
|
||||
var presenter = contentControl.GetTemplateChildren().OfType<ContentPresenter>().Single();
|
||||
var decorator = (Decorator)presenter.Content;
|
||||
var textBlock = (TextBlock)decorator.Child;
|
||||
var decorator = (Decorator)presenter.Content!;
|
||||
var textBlock = (TextBlock)decorator.Child!;
|
||||
|
||||
Assert.Equal(target, contentControl.TemplatedParent);
|
||||
Assert.Equal(contentControl, border.TemplatedParent);
|
||||
@@ -289,7 +289,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
||||
target.ApplyTemplate();
|
||||
|
||||
var decorator = (Decorator)target.GetVisualChildren().Single();
|
||||
var border = (Border)decorator.Child;
|
||||
var border = (Border)decorator.Child!;
|
||||
|
||||
Assert.Equal(target, decorator.TemplatedParent);
|
||||
Assert.Equal(target, border.TemplatedParent);
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
InitializeScrollViewer(target);
|
||||
|
||||
Assert.IsType<TextBlock>(target.Presenter.Child);
|
||||
Assert.IsType<TextBlock>(target.Presenter!.Child);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -473,7 +473,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
public void MenuScrollBar_Should_Be_Visible_When_Specified_Visible()
|
||||
{
|
||||
Converters.MenuScrollingVisibilityConverter converter = Converters.MenuScrollingVisibilityConverter.Instance;
|
||||
IList<object> args = new List<object> {ScrollBarVisibility.Visible,400d,1800d,500d};
|
||||
var args = new List<object?> {ScrollBarVisibility.Visible,400d,1800d,500d};
|
||||
var result = converter.Convert(args, typeof(ScrollBarVisibility), "0", System.Globalization.CultureInfo.CurrentCulture);
|
||||
Assert.Equal(true, result);
|
||||
}
|
||||
@@ -590,7 +590,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
[!!Track.ValueProperty] = scrollBar[!!RangeBase.ValueProperty],
|
||||
[!Track.ViewportSizeProperty] = scrollBar[!ScrollBar.ViewportSizeProperty],
|
||||
[!Track.OrientationProperty] = scrollBar[!ScrollBar.OrientationProperty],
|
||||
[!Track.DeferThumbDragProperty] = scrollBar.TemplatedParent[!ScrollViewer.IsDeferredScrollingEnabledProperty],
|
||||
[!Track.DeferThumbDragProperty] = scrollBar.TemplatedParent![!ScrollViewer.IsDeferredScrollingEnabledProperty],
|
||||
Thumb = new Thumb
|
||||
{
|
||||
Template = new FuncControlTemplate<Thumb>(CreateThumbTemplate),
|
||||
@@ -620,7 +620,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
target.ApplyTemplate();
|
||||
|
||||
var presenter = (ScrollContentPresenter)target.Presenter;
|
||||
var presenter = (ScrollContentPresenter)target.Presenter!;
|
||||
presenter.AttachToScrollViewer();
|
||||
presenter.UpdateChild();
|
||||
}
|
||||
|
||||
@@ -26,12 +26,12 @@ namespace Avalonia.Controls.UnitTests
|
||||
FontSize = 20
|
||||
};
|
||||
|
||||
target.Inlines.Add(run);
|
||||
target.Inlines!.Add(run);
|
||||
|
||||
target.Measure(Size.Infinity);
|
||||
|
||||
target.SelectionStart = 0;
|
||||
target.SelectionEnd = run.Text.Length;
|
||||
target.SelectionEnd = run.Text!.Length;
|
||||
|
||||
target.Measure(Size.Infinity);
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ namespace Avalonia.Controls.UnitTests.Selection
|
||||
var target = CreateTarget(nullSource: true);
|
||||
|
||||
target.SelectRange(1, 2);
|
||||
Assert.Equal(new object[] { null, null }, target.WritableSelectedItems);
|
||||
Assert.Equal(new object?[] { null, null }, target.WritableSelectedItems);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -156,7 +156,7 @@ namespace Avalonia.Controls.UnitTests.Selection
|
||||
var target = CreateTarget(nullSource: true);
|
||||
|
||||
target.SelectRange(1, 2);
|
||||
Assert.Equal(new object[] { null, null }, target.WritableSelectedItems);
|
||||
Assert.Equal(new object?[] { null, null }, target.WritableSelectedItems);
|
||||
|
||||
target.Source = new[] { "foo", "bar", "baz" };
|
||||
Assert.Equal(new[] { "bar", "baz" }, target.WritableSelectedItems);
|
||||
@@ -171,7 +171,7 @@ namespace Avalonia.Controls.UnitTests.Selection
|
||||
Assert.Equal(new[] { "bar", "baz" }, target.WritableSelectedItems);
|
||||
|
||||
target.Source = null;
|
||||
Assert.Equal(new object[] { null, null }, target.WritableSelectedItems);
|
||||
Assert.Equal(new object?[] { null, null }, target.WritableSelectedItems);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -218,7 +218,7 @@ namespace Avalonia.Controls.UnitTests.Selection
|
||||
|
||||
target.SelectedIndex = 1;
|
||||
|
||||
var changed = new List<string>();
|
||||
var changed = new List<string?>();
|
||||
|
||||
target.PropertyChanged += (s, e) => changed.Add(e.PropertyName);
|
||||
|
||||
@@ -248,7 +248,7 @@ namespace Avalonia.Controls.UnitTests.Selection
|
||||
|
||||
Assert.Equal(0, target.SelectedIndex);
|
||||
|
||||
items.Reset(new string[] { "baz", "foo", "bar" });
|
||||
items.Reset(["baz", "foo", "bar"]);
|
||||
|
||||
Assert.Equal("foo", target.SelectedItem);
|
||||
Assert.Equal(1, target.SelectedIndex);
|
||||
@@ -269,7 +269,7 @@ namespace Avalonia.Controls.UnitTests.Selection
|
||||
|
||||
private static InternalSelectionModel CreateTarget(
|
||||
bool singleSelect = false,
|
||||
IList source = null,
|
||||
IList? source = null,
|
||||
bool nullSource = false)
|
||||
{
|
||||
source ??= !nullSource ? new[] { "foo", "bar", "baz" } : null;
|
||||
@@ -299,7 +299,7 @@ namespace Avalonia.Controls.UnitTests.Selection
|
||||
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
|
||||
public event NotifyCollectionChangedEventHandler CollectionChanged;
|
||||
public event NotifyCollectionChangedEventHandler? CollectionChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +88,7 @@ namespace Avalonia.Controls.UnitTests.Shapes
|
||||
|
||||
target.Measure(new Size(500, 500));
|
||||
|
||||
Assert.NotNull(target.RenderedGeometry);
|
||||
Assert.Null(target.RenderedGeometry.Transform);
|
||||
}
|
||||
|
||||
@@ -109,12 +110,15 @@ namespace Avalonia.Controls.UnitTests.Shapes
|
||||
target.Measure(new Size(500, 500));
|
||||
target.Arrange(new Rect(0, 0, 500, 500));
|
||||
|
||||
Assert.NotNull(target.RenderedGeometry);
|
||||
|
||||
if (expectedScaleX == 1 && expectedScaleY == 1)
|
||||
{
|
||||
Assert.Null(target.RenderedGeometry.Transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.NotNull(target.RenderedGeometry.Transform);
|
||||
Assert.Equal(Matrix.CreateScale(expectedScaleX, expectedScaleY), target.RenderedGeometry.Transform.Value);
|
||||
}
|
||||
}
|
||||
@@ -135,6 +139,8 @@ namespace Avalonia.Controls.UnitTests.Shapes
|
||||
target.Arrange(new Rect(0, 0, 400, 400));
|
||||
|
||||
Assert.Equal(new Rect(0, 0, 100, 200), geometry.Rect);
|
||||
Assert.NotNull(target.RenderedGeometry);
|
||||
Assert.NotNull(target.RenderedGeometry.Transform);
|
||||
Assert.Equal(Matrix.CreateScale(2, 2), target.RenderedGeometry.Transform.Value);
|
||||
Assert.Equal(new Rect(0, 0, 400, 400), target.Bounds);
|
||||
}
|
||||
@@ -153,6 +159,8 @@ namespace Avalonia.Controls.UnitTests.Shapes
|
||||
target.Measure(new Size(200, 200));
|
||||
target.Arrange(new Rect(0, 0, 200, 200));
|
||||
|
||||
Assert.NotNull(target.RenderedGeometry);
|
||||
Assert.NotNull(target.RenderedGeometry.Transform);
|
||||
Assert.Equal(Matrix.CreateScale(2, 2), target.RenderedGeometry.Transform.Value);
|
||||
|
||||
target.Measure(new Size(300, 300));
|
||||
@@ -173,6 +181,8 @@ namespace Avalonia.Controls.UnitTests.Shapes
|
||||
|
||||
target.Measure(new Size(200, 200));
|
||||
target.Arrange(new Rect(0, 0, 200, 200));
|
||||
Assert.NotNull(target.RenderedGeometry);
|
||||
Assert.NotNull(target.RenderedGeometry.Transform);
|
||||
Assert.Equal(Matrix.CreateScale(2, 2), target.RenderedGeometry.Transform.Value);
|
||||
|
||||
target.Arrange(new Rect(0, 0, 300, 300));
|
||||
|
||||
@@ -13,7 +13,7 @@ public class SplitButtonTests : ScopedTestBase
|
||||
public void SplitButton_CommandParameter_Does_Not_Change_While_Execution()
|
||||
{
|
||||
var target = new SplitButton();
|
||||
object lastParamenter = "A";
|
||||
object? lastParamenter = "A";
|
||||
var generator = new Random();
|
||||
var command = new TestCommand(parameter =>
|
||||
{
|
||||
@@ -56,12 +56,12 @@ public class SplitButtonTests : ScopedTestBase
|
||||
}
|
||||
}
|
||||
|
||||
private static KeyEventArgs CreateKeyDownEvent(Key key, Interactive source = null)
|
||||
private static KeyEventArgs CreateKeyDownEvent(Key key, Interactive? source = null)
|
||||
{
|
||||
return new KeyEventArgs { RoutedEvent = InputElement.KeyDownEvent, Key = key, Source = source };
|
||||
}
|
||||
|
||||
private static KeyEventArgs CreateKeyUpEvent(Key key, Interactive source = null)
|
||||
private static KeyEventArgs CreateKeyUpEvent(Key key, Interactive? source = null)
|
||||
{
|
||||
return new KeyEventArgs { RoutedEvent = InputElement.KeyUpEvent, Key = key, Source = source };
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
splitView.IsPaneOpen = true;
|
||||
|
||||
splitView.RaiseEvent(new PointerReleasedEventArgs(splitView,
|
||||
null, wnd, new Point(1270, 30), 0,
|
||||
null!, wnd, new Point(1270, 30), 0,
|
||||
new PointerPointProperties(),
|
||||
KeyModifiers.None,
|
||||
MouseButton.Left));
|
||||
@@ -172,7 +172,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
splitView.IsPaneOpen = true;
|
||||
|
||||
splitView.RaiseEvent(new PointerReleasedEventArgs(splitView,
|
||||
null, wnd, new Point(1270, 30), 0,
|
||||
null!, wnd, new Point(1270, 30), 0,
|
||||
new PointerPointProperties(),
|
||||
KeyModifiers.None,
|
||||
MouseButton.Left));
|
||||
@@ -207,7 +207,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
splitView.IsPaneOpen = true;
|
||||
|
||||
clickBorder.RaiseEvent(new PointerReleasedEventArgs(splitView,
|
||||
null, wnd, new Point(5, 5), 0,
|
||||
null!, wnd, new Point(5, 5), 0,
|
||||
new PointerPointProperties(),
|
||||
KeyModifiers.None,
|
||||
MouseButton.Left));
|
||||
@@ -322,7 +322,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
splitView.IsPaneOpen = true;
|
||||
|
||||
splitView.RaiseEvent(new PointerReleasedEventArgs(splitView,
|
||||
null, wnd, new Point(1270, 30), 0,
|
||||
null!, wnd, new Point(1270, 30), 0,
|
||||
new PointerPointProperties(),
|
||||
KeyModifiers.None,
|
||||
MouseButton.Left));
|
||||
@@ -336,7 +336,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
splitView.DisplayMode = SplitViewDisplayMode.Inline;
|
||||
|
||||
splitView.RaiseEvent(new PointerReleasedEventArgs(splitView,
|
||||
null, wnd, new Point(1270, 30), 0,
|
||||
null!, wnd, new Point(1270, 30), 0,
|
||||
new PointerPointProperties(),
|
||||
KeyModifiers.None,
|
||||
MouseButton.Left));
|
||||
|
||||
@@ -281,8 +281,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
ApplyTemplate(target);
|
||||
|
||||
target.ContentPart.UpdateChild();
|
||||
var dataContext = ((TextBlock)target.ContentPart.Child).DataContext;
|
||||
target.ContentPart!.UpdateChild();
|
||||
var dataContext = ((TextBlock)target.ContentPart.Child!).DataContext;
|
||||
Assert.Equal(items[0], dataContext);
|
||||
|
||||
target.SelectedIndex = 1;
|
||||
@@ -337,7 +337,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
.Select(x => x.Header)
|
||||
.ToList();
|
||||
|
||||
Assert.Equal(new object[] { null, null }, result);
|
||||
Assert.Equal(new object?[] { null, null }, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -358,7 +358,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
target.SelectedIndex = 2;
|
||||
|
||||
var page = (TabItem)target.SelectedItem;
|
||||
var page = Assert.IsType<TabItem>(target.SelectedItem);
|
||||
|
||||
Assert.Null(page.Content);
|
||||
}
|
||||
@@ -376,7 +376,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var root = new TestRoot(target);
|
||||
|
||||
ApplyTemplate(target);
|
||||
target.ContentPart.UpdateChild();
|
||||
target.ContentPart!.UpdateChild();
|
||||
|
||||
var content = Assert.IsType<TextBlock>(target.ContentPart.Child);
|
||||
Assert.Equal("bar", content.Tag);
|
||||
@@ -395,7 +395,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var root = new TestRoot(target);
|
||||
|
||||
ApplyTemplate(target);
|
||||
((ContentPresenter)target.ContentPart).UpdateChild();
|
||||
target.ContentPart!.UpdateChild();
|
||||
|
||||
Assert.Equal(null, Assert.IsType<TextBlock>(target.ContentPart.Child).Tag);
|
||||
|
||||
@@ -473,7 +473,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
<TabControl Name='tabs' ItemsSource='{Binding Tabs}'/>
|
||||
</Window>";
|
||||
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
|
||||
var tabControl = window.FindControl<TabControl>("tabs");
|
||||
var tabControl = window.GetControl<TabControl>("tabs");
|
||||
|
||||
tabControl.DataContext = new { Tabs = new List<string>() };
|
||||
window.ApplyTemplate();
|
||||
@@ -601,6 +601,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
RaiseKeyEvent(button, Key.Tab);
|
||||
|
||||
var item = target.ContainerFromIndex(1);
|
||||
Assert.NotNull(item);
|
||||
Assert.Same(item, root.FocusManager.GetFocusedElement());
|
||||
|
||||
RaiseKeyEvent(item, Key.Tab);
|
||||
@@ -747,7 +748,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
new TabItem { Header = "_Disabled", IsEnabled = false },
|
||||
}
|
||||
};
|
||||
kd.SetFocusedElement((TabItem)tabControl.Items[selectedTabIndex], NavigationMethod.Unspecified, KeyModifiers.None);
|
||||
kd.SetFocusedElement((TabItem?)tabControl.Items[selectedTabIndex], NavigationMethod.Unspecified, KeyModifiers.None);
|
||||
|
||||
var root = new TestTopLevel(impl.Object)
|
||||
{
|
||||
@@ -756,7 +757,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
};
|
||||
|
||||
root.ApplyTemplate();
|
||||
root.Presenter.UpdateChild();
|
||||
root.Presenter!.UpdateChild();
|
||||
ApplyTemplate(tabControl);
|
||||
|
||||
KeyDown(root, Key.LeftAlt);
|
||||
@@ -847,7 +848,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
private readonly ILayoutManager _layoutManager;
|
||||
public bool IsClosed { get; private set; }
|
||||
|
||||
public TestTopLevel(ITopLevelImpl impl, ILayoutManager layoutManager = null)
|
||||
public TestTopLevel(ITopLevelImpl impl, ILayoutManager? layoutManager = null)
|
||||
: base(impl)
|
||||
{
|
||||
_layoutManager = layoutManager ?? new LayoutManager(this);
|
||||
@@ -877,7 +878,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
target.ApplyTemplate();
|
||||
|
||||
target.Presenter.ApplyTemplate();
|
||||
target.Presenter!.ApplyTemplate();
|
||||
|
||||
foreach (var tabItem in target.GetLogicalChildren().OfType<TabItem>())
|
||||
{
|
||||
@@ -885,10 +886,10 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
tabItem.ApplyTemplate();
|
||||
|
||||
tabItem.Presenter.UpdateChild();
|
||||
tabItem.Presenter!.UpdateChild();
|
||||
}
|
||||
|
||||
target.ContentPart.ApplyTemplate();
|
||||
target.ContentPart!.ApplyTemplate();
|
||||
}
|
||||
|
||||
private class Item
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
Assert.True(target.IsMeasureValid);
|
||||
|
||||
target.Inlines.Add(new Run("Hello"));
|
||||
target.Inlines!.Add(new Run("Hello"));
|
||||
|
||||
Assert.False(target.IsMeasureValid);
|
||||
|
||||
@@ -177,7 +177,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
var target = new TextBlock();
|
||||
|
||||
target.Inlines.Add(new TextBox { Text = "Hello"});
|
||||
target.Inlines!.Add(new TextBox { Text = "Hello"});
|
||||
|
||||
target.Measure(Size.Infinity);
|
||||
|
||||
@@ -201,7 +201,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var textBox = new TextBox { Text = "Hello", Template = TextBoxTests.CreateTemplate() };
|
||||
|
||||
target.Inlines.Add(textBox);
|
||||
target.Inlines!.Add(textBox);
|
||||
|
||||
target.Measure(Size.Infinity);
|
||||
|
||||
@@ -228,7 +228,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var inline = new Run("Hello");
|
||||
|
||||
target.Inlines.Add(inline);
|
||||
target.Inlines!.Add(inline);
|
||||
|
||||
target.Measure(Size.Infinity);
|
||||
|
||||
@@ -268,7 +268,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var run = new Run("Hello");
|
||||
|
||||
target.Inlines.Add(run);
|
||||
target.Inlines!.Add(run);
|
||||
|
||||
target.Measure(Size.Infinity);
|
||||
|
||||
@@ -308,7 +308,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
var target = new TextBlock();
|
||||
|
||||
target.Inlines.Add(new Border());
|
||||
target.Inlines!.Add(new Border());
|
||||
|
||||
target.Measure(Size.Infinity);
|
||||
|
||||
@@ -331,7 +331,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var run = new InlineUIContainer(control);
|
||||
|
||||
target.Inlines.Add(run);
|
||||
target.Inlines!.Add(run);
|
||||
|
||||
target.Measure(Size.Infinity);
|
||||
|
||||
@@ -402,7 +402,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Image imageControl = new Image { Source = image };
|
||||
InlineUIContainer container = new InlineUIContainer(imageControl);
|
||||
|
||||
target.Inlines.Add(new Run("The child should not be limited by position on line."));
|
||||
target.Inlines!.Add(new Run("The child should not be limited by position on line."));
|
||||
target.Inlines.Add(container);
|
||||
|
||||
target.Measure(new Size(100, 100));
|
||||
@@ -420,7 +420,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
var target = new TextBlock();
|
||||
|
||||
target.Inlines.Add(new Run("Hello World"));
|
||||
target.Inlines!.Add(new Run("Hello World"));
|
||||
|
||||
Assert.Equal(null, target.Text);
|
||||
|
||||
@@ -441,7 +441,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
{
|
||||
var target = new TextBlock();
|
||||
|
||||
target.Inlines.Add(new Run("Hello World"));
|
||||
target.Inlines!.Add(new Run("Hello World"));
|
||||
|
||||
Assert.Equal(1, target.Inlines.Count);
|
||||
|
||||
|
||||
@@ -59,9 +59,10 @@ namespace Avalonia.Controls.UnitTests
|
||||
Assert.Null(DataValidationErrors.GetErrors(target));
|
||||
target.Text = "20";
|
||||
|
||||
IEnumerable<object> errors = DataValidationErrors.GetErrors(target);
|
||||
Assert.Single(errors);
|
||||
Assert.IsType<InvalidOperationException>(errors.Single());
|
||||
var errors = DataValidationErrors.GetErrors(target);
|
||||
Assert.NotNull(errors);
|
||||
var error = Assert.Single(errors);
|
||||
Assert.IsType<InvalidOperationException>(error);
|
||||
target.Text = "1";
|
||||
Assert.Null(DataValidationErrors.GetErrors(target));
|
||||
}
|
||||
@@ -84,9 +85,9 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
target.Text = "20";
|
||||
|
||||
IEnumerable<object> errors = DataValidationErrors.GetErrors(target);
|
||||
Assert.Single(errors);
|
||||
var error = Assert.IsType<string>(errors.Single());
|
||||
var errors = DataValidationErrors.GetErrors(target);
|
||||
Assert.NotNull(errors);
|
||||
var error = Assert.IsType<string>(Assert.Single(errors));
|
||||
Assert.StartsWith("Error: ", error);
|
||||
}
|
||||
}
|
||||
@@ -121,7 +122,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
new ClrPropertyInfo(
|
||||
nameof(ExceptionTest.LessThan10),
|
||||
target => ((ExceptionTest)target).LessThan10,
|
||||
(target, value) => ((ExceptionTest)target).LessThan10 = (int)value,
|
||||
(target, value) => ((ExceptionTest)target).LessThan10 = (int)value!,
|
||||
typeof(int)),
|
||||
PropertyInfoAccessorFactory.CreateInpcPropertyAccessor)
|
||||
.Build();
|
||||
@@ -215,13 +216,13 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
public bool HasErrors => _lessThan10 >= 10;
|
||||
|
||||
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
|
||||
public event EventHandler<DataErrorsChangedEventArgs>? ErrorsChanged;
|
||||
|
||||
public IEnumerable GetErrors(string propertyName)
|
||||
public IEnumerable GetErrors(string? propertyName)
|
||||
{
|
||||
IList<string> result;
|
||||
_errors.TryGetValue(propertyName, out result);
|
||||
return result;
|
||||
if (propertyName is not null && _errors.TryGetValue(propertyName, out var result))
|
||||
return result;
|
||||
return Array.Empty<string?>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,15 +49,11 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var desc = timePicker.GetVisualDescendants();
|
||||
Assert.True(desc.Count() > 1);//Should be layoutroot grid & button
|
||||
Grid container = null;
|
||||
|
||||
Assert.True(desc.ElementAt(1) is Button);
|
||||
var button = Assert.IsAssignableFrom<Button>(desc.ElementAt(1));
|
||||
var container = Assert.IsAssignableFrom<Grid>(button.Content);
|
||||
|
||||
container = (desc.ElementAt(1) as Button).Content as Grid;
|
||||
Assert.True(container != null);
|
||||
|
||||
var periodTextHost = container.Children[6] as Border;
|
||||
Assert.True(periodTextHost != null);
|
||||
var periodTextHost = Assert.IsAssignableFrom<Border>(container.Children[6]);
|
||||
Assert.True(periodTextHost.IsVisible);
|
||||
|
||||
timePicker.ClockIdentifier = "24HourClock";
|
||||
@@ -79,15 +75,11 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var desc = timePicker.GetVisualDescendants();
|
||||
Assert.True(desc.Count() > 1);//Should be layoutroot grid & button
|
||||
Grid container = null;
|
||||
|
||||
Assert.True(desc.ElementAt(1) is Button);
|
||||
var button = Assert.IsAssignableFrom<Button>(desc.ElementAt(1));
|
||||
var container = Assert.IsAssignableFrom<Grid>(button.Content);
|
||||
|
||||
container = (desc.ElementAt(1) as Button).Content as Grid;
|
||||
Assert.True(container != null);
|
||||
|
||||
var periodTextHost = container.Children[4] as Border;
|
||||
Assert.True(periodTextHost != null);
|
||||
var periodTextHost = Assert.IsAssignableFrom<Border>(container.Children[4]);
|
||||
Assert.True(periodTextHost.IsVisible);
|
||||
|
||||
timePicker.UseSeconds = false;
|
||||
@@ -117,9 +109,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Assert.True(desc.ElementAt(2) is Popup);
|
||||
var popup = (Popup)desc.ElementAt(2);
|
||||
|
||||
Assert.True(popup.Child is TimePickerPresenter);
|
||||
var timePickerPresenter = (TimePickerPresenter)popup.Child;
|
||||
|
||||
var timePickerPresenter = Assert.IsAssignableFrom<TimePickerPresenter>(popup.Child);
|
||||
var panel = (Panel)timePickerPresenter.VisualChildren[0];
|
||||
var acceptBtn = (Button)panel.VisualChildren[0];
|
||||
|
||||
@@ -169,22 +159,16 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
var desc = timePicker.GetVisualDescendants();
|
||||
Assert.True(desc.Count() > 1);//Should be layoutroot grid & button
|
||||
Grid container = null;
|
||||
|
||||
Assert.True(desc.ElementAt(1) is Button);
|
||||
var button = Assert.IsAssignableFrom<Button>(desc.ElementAt(1));
|
||||
var container = Assert.IsAssignableFrom<Grid>(button.Content);
|
||||
|
||||
container = (desc.ElementAt(1) as Button).Content as Grid;
|
||||
Assert.True(container != null);
|
||||
|
||||
var hourTextHost = container.Children[0] as Border;
|
||||
Assert.True(hourTextHost != null);
|
||||
var hourText = hourTextHost.Child as TextBlock;
|
||||
var minuteTextHost = container.Children[2] as Border;
|
||||
Assert.True(minuteTextHost != null);
|
||||
var minuteText = minuteTextHost.Child as TextBlock;
|
||||
var secondTextHost = container.Children[4] as Border;
|
||||
Assert.True(secondTextHost != null);
|
||||
var secondText = secondTextHost.Child as TextBlock;
|
||||
var hourTextHost = Assert.IsAssignableFrom<Border>(container.Children[0]);
|
||||
var hourText = Assert.IsAssignableFrom<TextBlock>(hourTextHost.Child);
|
||||
var minuteTextHost = Assert.IsAssignableFrom<Border>(container.Children[2]);
|
||||
var minuteText = Assert.IsAssignableFrom<TextBlock>(minuteTextHost.Child);
|
||||
var secondTextHost = Assert.IsAssignableFrom<Border>(container.Children[4]);
|
||||
var secondText = Assert.IsAssignableFrom<TextBlock>(secondTextHost.Child);
|
||||
|
||||
TimeSpan ts = TimeSpan.FromHours(10);
|
||||
timePicker.SelectedTime = ts;
|
||||
@@ -214,15 +198,11 @@ namespace Avalonia.Controls.UnitTests
|
||||
var desc = timePicker.GetVisualDescendants();
|
||||
Assert.True(desc.Count() > 1); //Should be layoutroot grid & button
|
||||
|
||||
Assert.True(desc.ElementAt(1) is Button);
|
||||
var button = Assert.IsAssignableFrom<Button>(desc.ElementAt(1));
|
||||
var container = Assert.IsAssignableFrom<Grid>(button.Content);
|
||||
|
||||
var container = (desc.ElementAt(1) as Button).Content as Grid;
|
||||
Assert.True(container != null);
|
||||
|
||||
var periodTextHost = container.Children[6] as Border;
|
||||
Assert.NotNull(periodTextHost);
|
||||
var periodText = periodTextHost.Child as TextBlock;
|
||||
Assert.NotNull(periodTextHost);
|
||||
var periodTextHost = Assert.IsAssignableFrom<Border>(container.Children[6]);
|
||||
var periodText = Assert.IsAssignableFrom<TextBlock>(periodTextHost.Child);
|
||||
|
||||
TimeSpan ts = TimeSpan.FromHours(10);
|
||||
timePicker.SelectedTime = ts;
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
protected override void VerifyToolTipType(Control control)
|
||||
{
|
||||
var toolTip = control.GetValue(ToolTip.ToolTipProperty);
|
||||
Assert.NotNull(toolTip);
|
||||
Assert.IsType<PopupRoot>(toolTip.PopupHost);
|
||||
Assert.Same(toolTip.VisualRoot, toolTip.PopupHost);
|
||||
}
|
||||
@@ -38,7 +39,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
_toolTipOpenSubscription = ToolTip.IsOpenProperty.Changed.Subscribe(new AnonymousObserver<AvaloniaPropertyChangedEventArgs<bool>>(e =>
|
||||
{
|
||||
if (e.Sender is Visual { VisualRoot: {} root } visual)
|
||||
OverlayLayer.GetOverlayLayer(visual).Measure(root.ClientSize);
|
||||
OverlayLayer.GetOverlayLayer(visual)!.Measure(root.ClientSize);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -59,6 +60,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
protected override void VerifyToolTipType(Control control)
|
||||
{
|
||||
var toolTip = control.GetValue(ToolTip.ToolTipProperty);
|
||||
Assert.NotNull(toolTip);
|
||||
Assert.IsType<OverlayPopupHost>(toolTip.PopupHost);
|
||||
Assert.Same(toolTip.VisualRoot, control.VisualRoot);
|
||||
}
|
||||
@@ -164,10 +166,10 @@ namespace Avalonia.Controls.UnitTests
|
||||
SetupWindowAndActivateToolTip(target);
|
||||
|
||||
AssertToolTipOpen(target);
|
||||
Assert.Equal("Tip", target.GetValue(ToolTip.ToolTipProperty).Content);
|
||||
Assert.Equal("Tip", target.GetValue(ToolTip.ToolTipProperty)?.Content);
|
||||
|
||||
ToolTip.SetTip(target, "Tip1");
|
||||
Assert.Equal("Tip1", target.GetValue(ToolTip.ToolTipProperty).Content);
|
||||
Assert.Equal("Tip1", target.GetValue(ToolTip.ToolTipProperty)?.Content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +213,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
window.Presenter.ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
|
||||
Assert.Empty(toolTip.Classes);
|
||||
}
|
||||
@@ -234,7 +236,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
window.Presenter.ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
|
||||
ToolTip.SetIsOpen(decorator, true);
|
||||
|
||||
@@ -263,7 +265,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
window.Presenter.ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
|
||||
ToolTip.SetIsOpen(decorator, true);
|
||||
AssertToolTipOpen(decorator);
|
||||
@@ -436,7 +438,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
[ToolTip.ShowDelayProperty] = 0
|
||||
};
|
||||
|
||||
var eventsOrder = new List<(string eventName, object sender, object source)>();
|
||||
var eventsOrder = new List<(string eventName, object? sender, object? source)>();
|
||||
|
||||
ToolTip.AddToolTipOpeningHandler(target,
|
||||
(sender, args) => eventsOrder.Add(("Opening", sender, args.Source)));
|
||||
@@ -454,7 +456,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Assert.Equal(
|
||||
new[]
|
||||
{
|
||||
("Opening", (object)target, (object)target),
|
||||
("Opening", (object?)target, (object?)target),
|
||||
("Closing", target, target)
|
||||
},
|
||||
eventsOrder);
|
||||
@@ -522,14 +524,14 @@ namespace Avalonia.Controls.UnitTests
|
||||
AssertToolTipOpen(target);
|
||||
|
||||
var topLevel = TopLevel.GetTopLevel(target);
|
||||
topLevel.PlatformImpl.Input(new RawPointerEventArgs(s_mouseDevice, (ulong)DateTime.Now.Ticks, topLevel,
|
||||
topLevel!.PlatformImpl!.Input!(new RawPointerEventArgs(s_mouseDevice, (ulong)DateTime.Now.Ticks, topLevel,
|
||||
RawPointerEventType.LeaveWindow, default(RawPointerPoint), RawInputModifiers.None));
|
||||
|
||||
Assert.False(ToolTip.GetIsOpen(target));
|
||||
}
|
||||
}
|
||||
|
||||
private Action<Control> SetupWindowAndGetMouseEnterAction(Control windowContent, [CallerMemberName] string testName = null)
|
||||
private Action<Control?> SetupWindowAndGetMouseEnterAction(Control windowContent, [CallerMemberName] string? testName = null)
|
||||
{
|
||||
var windowImpl = MockWindowingPlatform.CreateWindowMock();
|
||||
SetupWindowMock(windowImpl);
|
||||
@@ -545,7 +547,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
window.ApplyStyling();
|
||||
window.ApplyTemplate();
|
||||
window.Presenter.ApplyTemplate();
|
||||
window.Presenter!.ApplyTemplate();
|
||||
window.Show();
|
||||
|
||||
Assert.True(windowContent.IsAttachedToVisualTree);
|
||||
@@ -553,7 +555,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Assert.True(windowContent.IsVisible);
|
||||
|
||||
var controlIds = new Dictionary<Control, int>();
|
||||
IInputRoot lastRoot = null;
|
||||
IInputRoot? lastRoot = null;
|
||||
|
||||
return control =>
|
||||
{
|
||||
@@ -575,15 +577,15 @@ namespace Avalonia.Controls.UnitTests
|
||||
hitTesterMock.Setup(m => m.HitTestFirst(point, window, It.IsAny<Func<Visual, bool>>()))
|
||||
.Returns(control);
|
||||
|
||||
var root = (IInputRoot)control?.VisualRoot ?? window;
|
||||
var root = (IInputRoot?)control?.VisualRoot ?? window;
|
||||
var timestamp = (ulong)DateTime.Now.Ticks;
|
||||
|
||||
windowImpl.Object.Input(new RawPointerEventArgs(s_mouseDevice, timestamp, root,
|
||||
windowImpl.Object.Input!(new RawPointerEventArgs(s_mouseDevice, timestamp, root,
|
||||
RawPointerEventType.Move, point, RawInputModifiers.None));
|
||||
|
||||
if (lastRoot != null && lastRoot != root)
|
||||
{
|
||||
((TopLevel)lastRoot).PlatformImpl?.Input(new RawPointerEventArgs(s_mouseDevice, timestamp,
|
||||
((TopLevel)lastRoot).PlatformImpl?.Input!(new RawPointerEventArgs(s_mouseDevice, timestamp,
|
||||
lastRoot, RawPointerEventType.LeaveWindow, new Point(-1,-1), RawInputModifiers.None));
|
||||
}
|
||||
|
||||
@@ -593,7 +595,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
};
|
||||
}
|
||||
|
||||
private void SetupWindowAndActivateToolTip(Control windowContent, Control targetOverride = null, [CallerMemberName] string testName = null) =>
|
||||
private void SetupWindowAndActivateToolTip(Control windowContent, Control? targetOverride = null, [CallerMemberName] string? testName = null) =>
|
||||
SetupWindowAndGetMouseEnterAction(windowContent, testName)(targetOverride ?? windowContent);
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
// The user has resized the window, so we can no longer auto-size.
|
||||
var target = new TestTopLevel(impl.Object);
|
||||
impl.Object.Resized(new Size(100, 200), WindowResizeReason.Unspecified);
|
||||
impl.Object.Resized!(new Size(100, 200), WindowResizeReason.Unspecified);
|
||||
|
||||
Assert.Equal(100, target.Width);
|
||||
Assert.Equal(200, target.Height);
|
||||
@@ -160,7 +160,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var target = new TestTopLevel(impl.Object);
|
||||
target.Closed += (s, e) => raised = true;
|
||||
|
||||
impl.Object.Closed();
|
||||
impl.Object.Closed!();
|
||||
|
||||
Assert.True(raised);
|
||||
}
|
||||
@@ -184,7 +184,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
++raised;
|
||||
};
|
||||
|
||||
impl.Object.Closed();
|
||||
impl.Object.Closed!();
|
||||
|
||||
Assert.Equal(1, raised);
|
||||
}
|
||||
@@ -215,7 +215,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
PhysicalKey.A,
|
||||
"a");
|
||||
|
||||
impl.Object.Input(input);
|
||||
impl.Object.Input!(input);
|
||||
|
||||
inputManagerMock.Verify(x => x.ProcessInput(input));
|
||||
}
|
||||
@@ -234,7 +234,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.Content = child;
|
||||
target.ApplyTemplate();
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => target.Presenter.ApplyTemplate());
|
||||
Assert.Throws<InvalidOperationException>(() => target.Presenter!.ApplyTemplate());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var raised = false;
|
||||
|
||||
target.ResourcesChanged += (_, __) => raised = true;
|
||||
Application.Current.Resources.Add("foo", "bar");
|
||||
Application.Current!.Resources.Add("foo", "bar");
|
||||
|
||||
Assert.True(raised);
|
||||
}
|
||||
@@ -264,7 +264,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var layoutManager = new Mock<ILayoutManager>();
|
||||
var target = new TestTopLevel(impl.Object, layoutManager.Object);
|
||||
|
||||
impl.Object.Closed();
|
||||
impl.Object.Closed!();
|
||||
|
||||
layoutManager.Verify(x => x.Dispose());
|
||||
}
|
||||
@@ -297,12 +297,13 @@ namespace Avalonia.Controls.UnitTests
|
||||
}
|
||||
};
|
||||
|
||||
Application.Current.Styles.Add(style);
|
||||
var application = Application.Current!;
|
||||
application.Styles.Add(style);
|
||||
target.LayoutManager.ExecuteInitialLayoutPass();
|
||||
|
||||
Assert.Equal(new Thickness(2), child.BorderThickness);
|
||||
|
||||
Application.Current.Styles.Remove(style);
|
||||
application.Styles.Remove(style);
|
||||
|
||||
Assert.Equal(new Thickness(0), child.BorderThickness);
|
||||
}
|
||||
@@ -333,7 +334,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
private readonly ILayoutManager _layoutManager;
|
||||
public bool IsClosed { get; private set; }
|
||||
|
||||
public TestTopLevel(ITopLevelImpl impl, ILayoutManager layoutManager = null)
|
||||
public TestTopLevel(ITopLevelImpl impl, ILayoutManager? layoutManager = null)
|
||||
: base(impl)
|
||||
{
|
||||
_layoutManager = layoutManager ?? new LayoutManager(this);
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls.Utils;
|
||||
using Avalonia.UnitTests;
|
||||
using Avalonia.VisualTree;
|
||||
using Xunit;
|
||||
|
||||
namespace Avalonia.Controls.UnitTests.Utils
|
||||
@@ -20,7 +15,7 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
var grandParent = new Border();
|
||||
var grandParent2 = new Border();
|
||||
|
||||
StyledElement currentParent = null;
|
||||
StyledElement? currentParent = null;
|
||||
var subscription = AncestorFinder.Create(child, typeof (Border)).Subscribe(s => currentParent = s);
|
||||
|
||||
Assert.Null(currentParent);
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
|
||||
public void Add(string s) => _inner.Add(s);
|
||||
|
||||
public event NotifyCollectionChangedEventHandler CollectionChanged
|
||||
public event NotifyCollectionChangedEventHandler? CollectionChanged
|
||||
{
|
||||
add => _inner.CollectionChanged += value;
|
||||
remove => _inner.CollectionChanged -= value;
|
||||
|
||||
@@ -6,7 +6,7 @@ using Avalonia.Input.Raw;
|
||||
using Avalonia.Platform;
|
||||
using Avalonia.UnitTests;
|
||||
using Xunit;
|
||||
using Factory = System.Func<int, System.Action<object>, Avalonia.Controls.Window, Avalonia.AvaloniaObject>;
|
||||
using Factory = System.Func<int, System.Action<object?>?, Avalonia.Controls.Window, Avalonia.AvaloniaObject>;
|
||||
|
||||
namespace Avalonia.Controls.UnitTests.Utils
|
||||
{
|
||||
@@ -28,7 +28,7 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
tl.Content = button;
|
||||
tl.Template = CreateWindowTemplate();
|
||||
tl.ApplyTemplate();
|
||||
tl.Presenter.ApplyTemplate();
|
||||
tl.Presenter!.ApplyTemplate();
|
||||
|
||||
HotKeyManager.SetHotKey(button, gesture1);
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
|
||||
var gesture = new KeyGesture(Key.A, KeyModifiers.Control);
|
||||
|
||||
var action = new Action<object>(parameter =>
|
||||
var action = new Action<object?>(parameter =>
|
||||
{
|
||||
if (parameter is int value)
|
||||
{
|
||||
@@ -79,7 +79,7 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
|
||||
root.Template = CreateWindowTemplate();
|
||||
root.ApplyTemplate();
|
||||
root.Presenter.ApplyTemplate();
|
||||
root.Presenter!.ApplyTemplate();
|
||||
|
||||
HotKeyManager.SetHotKey(element, gesture);
|
||||
|
||||
@@ -110,19 +110,20 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
|
||||
var gesture = new KeyGesture(Key.A, KeyModifiers.Control);
|
||||
|
||||
var action = new Action<object>(parameter =>
|
||||
var action = new Action<object?>(parameter =>
|
||||
{
|
||||
isExecuted = true;
|
||||
});
|
||||
|
||||
var root = new Window();
|
||||
var element = factory(0, action, root) as InputElement;
|
||||
var element = (InputElement)factory(0, action, root);
|
||||
Assert.NotNull(element);
|
||||
|
||||
element.IsEnabled = false;
|
||||
|
||||
root.Template = CreateWindowTemplate();
|
||||
root.ApplyTemplate();
|
||||
root.Presenter.ApplyTemplate();
|
||||
root.Presenter!.ApplyTemplate();
|
||||
|
||||
HotKeyManager.SetHotKey(element, gesture);
|
||||
|
||||
@@ -152,13 +153,13 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
|
||||
var gesture = new KeyGesture(Key.A, KeyModifiers.Control);
|
||||
|
||||
void Clickable_Click(object sender, Interactivity.RoutedEventArgs e)
|
||||
void Clickable_Click(object? sender, Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
clickExecutedCount++;
|
||||
}
|
||||
|
||||
var root = new Window();
|
||||
var element = factory(0, default, root) as InputElement;
|
||||
var element = (InputElement)factory(0, null, root);
|
||||
if (element is IClickableControl clickable)
|
||||
{
|
||||
clickable.Click += Clickable_Click;
|
||||
@@ -166,7 +167,7 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
|
||||
root.Template = CreateWindowTemplate();
|
||||
root.ApplyTemplate();
|
||||
root.Presenter.ApplyTemplate();
|
||||
root.Presenter!.ApplyTemplate();
|
||||
|
||||
HotKeyManager.SetHotKey(element, gesture);
|
||||
|
||||
@@ -209,18 +210,18 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
|
||||
var gesture = new KeyGesture(Key.A, KeyModifiers.Control);
|
||||
|
||||
void DoExecute(object parameter)
|
||||
void DoExecute(object? parameter)
|
||||
{
|
||||
commandExecutedCount++;
|
||||
}
|
||||
|
||||
void Clickable_Click(object sender, Interactivity.RoutedEventArgs e)
|
||||
void Clickable_Click(object? sender, Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
clickExecutedCount++;
|
||||
}
|
||||
|
||||
var root = new Window();
|
||||
var element = factory(0, DoExecute, root) as InputElement;
|
||||
var element = (InputElement)factory(0, DoExecute, root);
|
||||
if (element is IClickableControl clickable)
|
||||
{
|
||||
clickable.Click += Clickable_Click;
|
||||
@@ -228,7 +229,7 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
|
||||
root.Template = CreateWindowTemplate();
|
||||
root.ApplyTemplate();
|
||||
root.Presenter.ApplyTemplate();
|
||||
root.Presenter!.ApplyTemplate();
|
||||
|
||||
HotKeyManager.SetHotKey(element, gesture);
|
||||
|
||||
@@ -266,7 +267,7 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
{nameof(MenuItem),withCommand ? MakeMenu : MakeMenuWithoutCommand},
|
||||
};
|
||||
|
||||
private static AvaloniaObject MakeMenu(int expectedParameter, Action<object> action, Window root)
|
||||
private static AvaloniaObject MakeMenu(int expectedParameter, Action<object?>? action, Window root)
|
||||
{
|
||||
var menuitem = new MenuItem()
|
||||
{
|
||||
@@ -281,7 +282,7 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
return menuitem;
|
||||
}
|
||||
|
||||
private static AvaloniaObject MakeButton(int expectedParameter, Action<object> action, Window root)
|
||||
private static AvaloniaObject MakeButton(int expectedParameter, Action<object?>? action, Window root)
|
||||
{
|
||||
var button = new Button()
|
||||
{
|
||||
@@ -293,7 +294,7 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
return button;
|
||||
}
|
||||
|
||||
private static AvaloniaObject MakeMenuWithoutCommand(int expectedParameter, Action<object> action, Window root)
|
||||
private static AvaloniaObject MakeMenuWithoutCommand(int expectedParameter, Action<object?>? action, Window root)
|
||||
{
|
||||
var menuitem = new MenuItem()
|
||||
{
|
||||
@@ -306,7 +307,7 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
return menuitem;
|
||||
}
|
||||
|
||||
private static AvaloniaObject MakeButtonWithoutCommand(int expectedParameter, Action<object> action, Window root)
|
||||
private static AvaloniaObject MakeButtonWithoutCommand(int expectedParameter, Action<object?>? action, Window root)
|
||||
{
|
||||
var button = new Button()
|
||||
{
|
||||
@@ -330,19 +331,19 @@ namespace Avalonia.Controls.UnitTests.Utils
|
||||
|
||||
class Command : System.Windows.Input.ICommand
|
||||
{
|
||||
private readonly Action<object> _execeute;
|
||||
private readonly Action<object?>? _execute;
|
||||
|
||||
#pragma warning disable 67 // Event not used
|
||||
public event EventHandler CanExecuteChanged;
|
||||
public event EventHandler? CanExecuteChanged;
|
||||
#pragma warning restore 67 // Event not used
|
||||
|
||||
public Command(Action<object> execeute)
|
||||
public Command(Action<object?>? execute)
|
||||
{
|
||||
_execeute = execeute;
|
||||
_execute = execute;
|
||||
}
|
||||
public bool CanExecute(object parameter) => true;
|
||||
public bool CanExecute(object? parameter) => true;
|
||||
|
||||
public void Execute(object parameter) => _execeute?.Invoke(parameter);
|
||||
public void Execute(object? parameter) => _execute?.Invoke(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace Avalonia.Controls.UnitTests.Utils;
|
||||
|
||||
internal class TestCommand : ICommand
|
||||
{
|
||||
private readonly Func<object, bool> _canExecute;
|
||||
private readonly Action<object> _execute;
|
||||
private EventHandler _canExecuteChanged;
|
||||
private readonly Func<object?, bool> _canExecute;
|
||||
private readonly Action<object?> _execute;
|
||||
private EventHandler? _canExecuteChanged;
|
||||
private bool _enabled = true;
|
||||
|
||||
public TestCommand(bool enabled = true)
|
||||
@@ -17,7 +17,7 @@ internal class TestCommand : ICommand
|
||||
_execute = _ => { };
|
||||
}
|
||||
|
||||
public TestCommand(Func<object, bool> canExecute, Action<object> execute = null)
|
||||
public TestCommand(Func<object?, bool> canExecute, Action<object?>? execute = null)
|
||||
{
|
||||
_canExecute = canExecute;
|
||||
_execute = execute ?? (_ => { });
|
||||
@@ -38,15 +38,15 @@ internal class TestCommand : ICommand
|
||||
|
||||
public int SubscriptionCount { get; private set; }
|
||||
|
||||
public event EventHandler CanExecuteChanged
|
||||
public event EventHandler? CanExecuteChanged
|
||||
{
|
||||
add { _canExecuteChanged += value; ++SubscriptionCount; }
|
||||
remove { _canExecuteChanged -= value; --SubscriptionCount; }
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter) => _canExecute(parameter);
|
||||
public bool CanExecute(object? parameter) => _canExecute(parameter);
|
||||
|
||||
public void Execute(object parameter) => _execute(parameter);
|
||||
public void Execute(object? parameter) => _execute(parameter);
|
||||
|
||||
public void RaiseCanExecuteChanged() => _canExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Subjects;
|
||||
using Moq;
|
||||
using Avalonia.Controls.Presenters;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Input.Raw;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Platform;
|
||||
using Avalonia.Rendering;
|
||||
using Avalonia.Rendering.Composition;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.UnitTests;
|
||||
using Xunit;
|
||||
|
||||
@@ -44,7 +36,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var target = new TestWindowBase(impl.Object);
|
||||
target.Activated += (s, e) => raised = true;
|
||||
|
||||
impl.Object.Activated();
|
||||
impl.Object.Activated!();
|
||||
|
||||
Assert.True(raised);
|
||||
}
|
||||
@@ -62,7 +54,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var target = new TestWindowBase(impl.Object);
|
||||
target.Deactivated += (s, e) => raised = true;
|
||||
|
||||
impl.Object.Deactivated();
|
||||
impl.Object.Deactivated!();
|
||||
|
||||
Assert.True(raised);
|
||||
}
|
||||
@@ -120,7 +112,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var target = new TestWindowBase(windowImpl.Object);
|
||||
|
||||
target.Show();
|
||||
windowImpl.Object.Closed();
|
||||
windowImpl.Object.Closed!();
|
||||
|
||||
Assert.False(target.IsVisible);
|
||||
}
|
||||
@@ -219,7 +211,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var target = new TestWindowBase(windowImpl.Object);
|
||||
|
||||
target.Show();
|
||||
windowImpl.Object.Closed();
|
||||
windowImpl.Object.Closed!();
|
||||
Assert.True(((CompositingRenderer)target.Renderer).IsDisposed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
window.Show();
|
||||
Assert.True(window.IsVisible);
|
||||
|
||||
windowImpl.Object.Closed();
|
||||
windowImpl.Object.Closed!();
|
||||
|
||||
Assert.False(window.IsVisible);
|
||||
}
|
||||
@@ -196,7 +196,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
}
|
||||
else
|
||||
{
|
||||
var cancel = window.PlatformImpl.Closing(WindowCloseReason.WindowClosing);
|
||||
var cancel = window.PlatformImpl!.Closing!(WindowCloseReason.WindowClosing);
|
||||
|
||||
Assert.Equal(false, cancel);
|
||||
}
|
||||
@@ -258,7 +258,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
}
|
||||
else
|
||||
{
|
||||
var cancel = window.PlatformImpl.Closing(WindowCloseReason.WindowClosing);
|
||||
var cancel = window.PlatformImpl!.Closing!(WindowCloseReason.WindowClosing);
|
||||
|
||||
Assert.Equal(true, cancel);
|
||||
}
|
||||
@@ -344,7 +344,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var target = new Window(windowImpl.Object);
|
||||
var task = target.ShowDialog<bool>(parent);
|
||||
|
||||
windowImpl.Object.Closed();
|
||||
windowImpl.Object.Closed!();
|
||||
|
||||
var result = await task;
|
||||
Assert.False(result);
|
||||
@@ -387,7 +387,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
var target = new Window(windowImpl.Object);
|
||||
var task = target.ShowDialog<bool>(parent);
|
||||
|
||||
windowImpl.Object.Closed();
|
||||
windowImpl.Object.Closed!();
|
||||
await task;
|
||||
|
||||
var openedRaised = false;
|
||||
@@ -927,8 +927,8 @@ namespace Avalonia.Controls.UnitTests
|
||||
|
||||
// Size before and after DPI change is a real-world example, with size after DPI
|
||||
// change coming from Win32 WM_DPICHANGED.
|
||||
target.PlatformImpl.ScalingChanged(1.5);
|
||||
target.PlatformImpl.Resized(
|
||||
target.PlatformImpl!.ScalingChanged!(1.5);
|
||||
target.PlatformImpl!.Resized!(
|
||||
new Size(210.66666666666666, 118.66666666666667),
|
||||
WindowResizeReason.DpiChange);
|
||||
|
||||
@@ -987,7 +987,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
target.Width = 410;
|
||||
target.LayoutManager.ExecuteLayoutPass();
|
||||
|
||||
var windowImpl = Mock.Get(target.PlatformImpl);
|
||||
var windowImpl = Mock.Get(target.PlatformImpl!);
|
||||
windowImpl.Verify(x => x.Resize(new Size(410, 800), WindowResizeReason.Application));
|
||||
Assert.Equal(410, target.Width);
|
||||
}
|
||||
@@ -1013,7 +1013,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Assert.Equal(400, target.Width);
|
||||
Assert.Equal(800, target.Height);
|
||||
|
||||
target.PlatformImpl.Resized(new Size(410, 800), WindowResizeReason.User);
|
||||
target.PlatformImpl!.Resized!(new Size(410, 800), WindowResizeReason.User);
|
||||
|
||||
Assert.Equal(410, target.Width);
|
||||
Assert.Equal(800, target.Height);
|
||||
@@ -1040,7 +1040,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Assert.Equal(400, target.Width);
|
||||
Assert.Equal(800, target.Height);
|
||||
|
||||
target.PlatformImpl.Resized(new Size(400, 810), WindowResizeReason.User);
|
||||
target.PlatformImpl!.Resized!(new Size(400, 810), WindowResizeReason.User);
|
||||
|
||||
Assert.Equal(400, target.Width);
|
||||
Assert.Equal(810, target.Height);
|
||||
@@ -1068,7 +1068,7 @@ namespace Avalonia.Controls.UnitTests
|
||||
Assert.Equal(400, target.Width);
|
||||
Assert.Equal(800, target.Height);
|
||||
|
||||
target.PlatformImpl.Resized(new Size(410, 810), WindowResizeReason.Unspecified);
|
||||
target.PlatformImpl!.Resized!(new Size(410, 810), WindowResizeReason.Unspecified);
|
||||
|
||||
Assert.Equal(400, target.Width);
|
||||
Assert.Equal(800, target.Height);
|
||||
|
||||
@@ -12,11 +12,11 @@ namespace Avalonia.UnitTests
|
||||
{
|
||||
private static readonly Size s_screenSize = new Size(1280, 1024);
|
||||
private readonly Func<IWindowImpl>? _windowImpl;
|
||||
private readonly Func<IWindowBaseImpl, IPopupImpl>? _popupImpl;
|
||||
private readonly Func<IWindowBaseImpl, IPopupImpl?>? _popupImpl;
|
||||
|
||||
public MockWindowingPlatform(
|
||||
Func<IWindowImpl>? windowImpl = null,
|
||||
Func<IWindowBaseImpl, IPopupImpl>? popupImpl = null )
|
||||
Func<IWindowBaseImpl, IPopupImpl?>? popupImpl = null )
|
||||
{
|
||||
_windowImpl = windowImpl;
|
||||
_popupImpl = popupImpl;
|
||||
|
||||
Reference in New Issue
Block a user