diff --git a/Avalonia.sln b/Avalonia.sln index c6509817ce..a29f3dd754 100644 --- a/Avalonia.sln +++ b/Avalonia.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26730.10 +VisualStudioVersion = 15.0.27004.2008 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Base", "src\Avalonia.Base\Avalonia.Base.csproj", "{B09B78D8-9B26-48B0-9149-D64A2F120F3F}" EndProject @@ -155,7 +155,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Props", "Props", "{F3AC8BC1 build\ReactiveUI.props = build\ReactiveUI.props build\Rx.props = build\Rx.props build\Serilog.props = build\Serilog.props - build\Serilog.Sinks.Trace.props = build\Serilog.Sinks.Trace.props build\SharpDX.props = build\SharpDX.props build\SkiaSharp.Desktop.props = build\SkiaSharp.Desktop.props build\SkiaSharp.props = build\SkiaSharp.props diff --git a/appveyor.yml b/appveyor.yml index 76d1ae3e1c..ba3680d0b9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -os: Visual Studio 2017 +os: Previous Visual Studio 2017 platform: - Any CPU skip_branch_with_pr: true diff --git a/build/MonoMac.props b/build/MonoMac.props index 452177ca5d..5cf19ef503 100644 --- a/build/MonoMac.props +++ b/build/MonoMac.props @@ -1,5 +1,5 @@  - + diff --git a/build/Serilog.Sinks.Trace.props b/build/Serilog.Sinks.Trace.props deleted file mode 100644 index ef79fd7669..0000000000 --- a/build/Serilog.Sinks.Trace.props +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/build/Serilog.props b/build/Serilog.props index e9bd39f6af..a814cf998d 100644 --- a/build/Serilog.props +++ b/build/Serilog.props @@ -1,5 +1,7 @@  - + + + diff --git a/packages.cake b/packages.cake index 9e78ee75d5..bc290fce22 100644 --- a/packages.cake +++ b/packages.cake @@ -107,6 +107,8 @@ public class Packages context.Information("Setting NuGet package dependencies versions:"); var SerilogVersion = packageVersions["Serilog"].FirstOrDefault().Item1; + var SerilogSinksDebugVersion = packageVersions["Serilog.Sinks.Debug"].FirstOrDefault().Item1; + var SerilogSinksTraceVersion = packageVersions["Serilog.Sinks.Trace"].FirstOrDefault().Item1; var SpracheVersion = packageVersions["Sprache"].FirstOrDefault().Item1; var SystemReactiveVersion = packageVersions["System.Reactive"].FirstOrDefault().Item1; var ReactiveUIVersion = packageVersions["reactiveui"].FirstOrDefault().Item1; @@ -243,6 +245,8 @@ public class Packages Dependencies = new DependencyBuilder(this) { new NuSpecDependency() { Id = "Serilog", Version = SerilogVersion }, + new NuSpecDependency() { Id = "Serilog.Sinks.Debug", Version = SerilogSinksDebugVersion }, + new NuSpecDependency() { Id = "Serilog.Sinks.Trace", Version = SerilogSinksTraceVersion }, new NuSpecDependency() { Id = "Sprache", Version = SpracheVersion }, new NuSpecDependency() { Id = "System.Reactive", Version = SystemReactiveVersion }, new NuSpecDependency() { Id = "Avalonia.Remote.Protocol", Version = parameters.Version }, @@ -251,6 +255,8 @@ public class Packages new NuSpecDependency() { Id = "Microsoft.Extensions.DependencyModel", TargetFramework = "netcoreapp2.0", Version = "1.1.0" }, new NuSpecDependency() { Id = "NETStandard.Library", TargetFramework = "netcoreapp2.0", Version = "1.6.0" }, new NuSpecDependency() { Id = "Serilog", TargetFramework = "netcoreapp2.0", Version = SerilogVersion }, + new NuSpecDependency() { Id = "Serilog.Sinks.Debug", TargetFramework = "netcoreapp2.0", Version = SerilogSinksDebugVersion }, + new NuSpecDependency() { Id = "Serilog.Sinks.Trace", TargetFramework = "netcoreapp2.0", Version = SerilogSinksTraceVersion }, new NuSpecDependency() { Id = "Sprache", TargetFramework = "netcoreapp2.0", Version = SpracheVersion }, new NuSpecDependency() { Id = "System.Reactive", TargetFramework = "netcoreapp2.0", Version = SystemReactiveVersion }, new NuSpecDependency() { Id = "Avalonia.Remote.Protocol", TargetFramework = "netcoreapp2.0", Version = parameters.Version }, diff --git a/samples/BindingTest/App.xaml.cs b/samples/BindingTest/App.xaml.cs index 42e5716541..ccad1d0ba9 100644 --- a/samples/BindingTest/App.xaml.cs +++ b/samples/BindingTest/App.xaml.cs @@ -16,22 +16,11 @@ namespace BindingTest private static void Main() { - InitializeLogging(); - AppBuilder.Configure() .UsePlatformDetect() .UseReactiveUI() + .LogToDebug() .Start(); } - - private static void InitializeLogging() - { -#if DEBUG - SerilogLogger.Initialize(new LoggerConfiguration() - .MinimumLevel.Warning() - .WriteTo.Trace(outputTemplate: "{Area}: {Message}") - .CreateLogger()); -#endif - } } } diff --git a/samples/BindingTest/BindingTest.csproj b/samples/BindingTest/BindingTest.csproj index 4f82303c3a..9f3fed5522 100644 --- a/samples/BindingTest/BindingTest.csproj +++ b/samples/BindingTest/BindingTest.csproj @@ -151,7 +151,6 @@ - \ No newline at end of file diff --git a/samples/ControlCatalog.Desktop/ControlCatalog.Desktop.csproj b/samples/ControlCatalog.Desktop/ControlCatalog.Desktop.csproj index 3f4679086e..cfa2f89b0e 100644 --- a/samples/ControlCatalog.Desktop/ControlCatalog.Desktop.csproj +++ b/samples/ControlCatalog.Desktop/ControlCatalog.Desktop.csproj @@ -135,5 +135,4 @@ - \ No newline at end of file diff --git a/samples/ControlCatalog.Desktop/Program.cs b/samples/ControlCatalog.Desktop/Program.cs index 20bf4ed342..b151cabf43 100644 --- a/samples/ControlCatalog.Desktop/Program.cs +++ b/samples/ControlCatalog.Desktop/Program.cs @@ -12,8 +12,6 @@ namespace ControlCatalog { static void Main(string[] args) { - InitializeLogging(); - // TODO: Make this work with GTK/Skia/Cairo depending on command-line args // again. BuildAvaloniaApp().Start(); @@ -23,18 +21,7 @@ namespace ControlCatalog /// This method is needed for IDE previewer infrastructure /// public static AppBuilder BuildAvaloniaApp() - => AppBuilder.Configure().UsePlatformDetect(); - - // This will be made into a runtime configuration extension soon! - private static void InitializeLogging() - { -#if DEBUG - SerilogLogger.Initialize(new LoggerConfiguration() - .MinimumLevel.Warning() - .WriteTo.Trace(outputTemplate: "{Area}: {Message}") - .CreateLogger()); -#endif - } + => AppBuilder.Configure().LogToDebug().UsePlatformDetect(); private static void ConfigureAssetAssembly(AppBuilder builder) { diff --git a/samples/ControlCatalog/ControlCatalog.csproj b/samples/ControlCatalog/ControlCatalog.csproj index 11ff531514..0b4463ddb7 100644 --- a/samples/ControlCatalog/ControlCatalog.csproj +++ b/samples/ControlCatalog/ControlCatalog.csproj @@ -44,6 +44,9 @@ Designer + + Designer + Designer @@ -107,6 +110,9 @@ ButtonPage.xaml + + CalendarPage.xaml + CanvasPage.xaml diff --git a/samples/ControlCatalog/MainView.xaml b/samples/ControlCatalog/MainView.xaml index 0940316ce9..311a61a6dc 100644 --- a/samples/ControlCatalog/MainView.xaml +++ b/samples/ControlCatalog/MainView.xaml @@ -7,6 +7,7 @@ + diff --git a/samples/ControlCatalog/Pages/CalendarPage.xaml b/samples/ControlCatalog/Pages/CalendarPage.xaml new file mode 100644 index 0000000000..a433fd1add --- /dev/null +++ b/samples/ControlCatalog/Pages/CalendarPage.xaml @@ -0,0 +1,47 @@ + + + Calendar + A calendar control for selecting dates + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/ControlCatalog/Pages/CalendarPage.xaml.cs b/samples/ControlCatalog/Pages/CalendarPage.xaml.cs new file mode 100644 index 0000000000..e3e9a3444e --- /dev/null +++ b/samples/ControlCatalog/Pages/CalendarPage.xaml.cs @@ -0,0 +1,28 @@ +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using System; + +namespace ControlCatalog.Pages +{ + public class CalendarPage : UserControl + { + public CalendarPage() + { + this.InitializeComponent(); + + var today = DateTime.Today; + var cal1 = this.FindControl("DisplayDatesCalendar"); + cal1.DisplayDateStart = today.AddDays(-25); + cal1.DisplayDateEnd = today.AddDays(25); + + var cal2 = this.FindControl("BlackoutDatesCalendar"); + cal2.BlackoutDates.AddDatesInPast(); + cal2.BlackoutDates.Add(new CalendarDateRange(today.AddDays(6))); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +} diff --git a/samples/ControlCatalog/Pages/CarouselPage.xaml b/samples/ControlCatalog/Pages/CarouselPage.xaml index 317159cd8d..4a5b2cea26 100644 --- a/samples/ControlCatalog/Pages/CarouselPage.xaml +++ b/samples/ControlCatalog/Pages/CarouselPage.xaml @@ -9,7 +9,7 @@ - + @@ -28,6 +28,14 @@ Crossfade + + + Orientation + + Horizontal + Vertical + + \ No newline at end of file diff --git a/samples/ControlCatalog/Pages/CarouselPage.xaml.cs b/samples/ControlCatalog/Pages/CarouselPage.xaml.cs index 1c408c8ed7..272290e679 100644 --- a/samples/ControlCatalog/Pages/CarouselPage.xaml.cs +++ b/samples/ControlCatalog/Pages/CarouselPage.xaml.cs @@ -11,6 +11,7 @@ namespace ControlCatalog.Pages private Button _left; private Button _right; private DropDown _transition; + private DropDown _orientation; public CarouselPage() { @@ -18,6 +19,7 @@ namespace ControlCatalog.Pages _left.Click += (s, e) => _carousel.Previous(); _right.Click += (s, e) => _carousel.Next(); _transition.SelectionChanged += TransitionChanged; + _orientation.SelectionChanged += TransitionChanged; } private void InitializeComponent() @@ -27,6 +29,7 @@ namespace ControlCatalog.Pages _left = this.FindControl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Avalonia.Themes.Default/CheckBox.xaml b/src/Avalonia.Themes.Default/CheckBox.xaml index 195ec098c9..ef96e7ed4f 100644 --- a/src/Avalonia.Themes.Default/CheckBox.xaml +++ b/src/Avalonia.Themes.Default/CheckBox.xaml @@ -12,14 +12,23 @@ Width="18" Height="18" VerticalAlignment="Center"> - + + + + + + diff --git a/src/Avalonia.Themes.Default/DefaultTheme.xaml b/src/Avalonia.Themes.Default/DefaultTheme.xaml index 48f530cca8..ae00f0757a 100644 --- a/src/Avalonia.Themes.Default/DefaultTheme.xaml +++ b/src/Avalonia.Themes.Default/DefaultTheme.xaml @@ -36,4 +36,8 @@ + + + + diff --git a/src/Avalonia.Themes.Default/RadioButton.xaml b/src/Avalonia.Themes.Default/RadioButton.xaml index 996f46023e..0a0eb48564 100644 --- a/src/Avalonia.Themes.Default/RadioButton.xaml +++ b/src/Avalonia.Themes.Default/RadioButton.xaml @@ -20,6 +20,14 @@ UseLayoutRounding="False" HorizontalAlignment="Center" VerticalAlignment="Center"/> + + + diff --git a/src/Avalonia.Visuals/Animation/PageSlide.cs b/src/Avalonia.Visuals/Animation/PageSlide.cs index 015f22ec14..ebc358379d 100644 --- a/src/Avalonia.Visuals/Animation/PageSlide.cs +++ b/src/Avalonia.Visuals/Animation/PageSlide.cs @@ -15,6 +15,15 @@ namespace Avalonia.Animation /// public class PageSlide : IPageTransition { + /// + /// The axis on which the PageSlide should occur + /// + public enum SlideAxis + { + Horizontal, + Vertical + } + /// /// Initializes a new instance of the class. /// @@ -26,9 +35,11 @@ namespace Avalonia.Animation /// Initializes a new instance of the class. /// /// The duration of the animation. - public PageSlide(TimeSpan duration) + /// The axis on which the animation should occur + public PageSlide(TimeSpan duration, SlideAxis orientation = SlideAxis.Horizontal) { Duration = duration; + Orientation = orientation; } /// @@ -36,6 +47,11 @@ namespace Avalonia.Animation /// public TimeSpan Duration { get; set; } + /// + /// Gets the duration of the animation. + /// + public SlideAxis Orientation { get; set; } + /// /// Starts the animation. /// @@ -55,7 +71,8 @@ namespace Avalonia.Animation { var tasks = new List(); var parent = GetVisualParent(from, to); - var distance = parent.Bounds.Width; + var distance = Orientation == SlideAxis.Horizontal ? parent.Bounds.Width : parent.Bounds.Height; + var translateProperty = Orientation == SlideAxis.Horizontal ? TranslateTransform.XProperty : TranslateTransform.YProperty; if (from != null) { @@ -63,7 +80,7 @@ namespace Avalonia.Animation from.RenderTransform = transform; tasks.Add(Animate.Property( transform, - TranslateTransform.XProperty, + translateProperty, 0.0, forward ? -distance : distance, LinearEasing.For(), @@ -77,7 +94,7 @@ namespace Avalonia.Animation to.IsVisible = true; tasks.Add(Animate.Property( transform, - TranslateTransform.XProperty, + translateProperty, forward ? distance : -distance, 0.0, LinearEasing.For(), diff --git a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/portable.xaml.github b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/portable.xaml.github index f226a516fe..d50ae8335e 160000 --- a/src/Markup/Avalonia.Markup.Xaml/PortableXaml/portable.xaml.github +++ b/src/Markup/Avalonia.Markup.Xaml/PortableXaml/portable.xaml.github @@ -1 +1 @@ -Subproject commit f226a516fe2bc191145c1fbf732f5a087f121a33 +Subproject commit d50ae8335eb50d4b9606de6f5fa1cbbc78bfd72f diff --git a/tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs b/tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs index 28d384fabd..2933893f7a 100644 --- a/tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs +++ b/tests/Avalonia.Base.UnitTests/AvaloniaPropertyTests.cs @@ -113,8 +113,8 @@ namespace Avalonia.Base.UnitTests { var p1 = new TestProperty("p1", typeof(Class1)); - Assert.NotEqual(p1, null); - Assert.NotEqual(null, p1); + Assert.NotNull(p1); + Assert.NotNull(p1); Assert.False(p1 == null); Assert.False(null == p1); Assert.False(p1.Equals(null)); diff --git a/tests/Avalonia.Base.UnitTests/PriorityValueTests.cs b/tests/Avalonia.Base.UnitTests/PriorityValueTests.cs index 7956f385e1..6ca1364f96 100644 --- a/tests/Avalonia.Base.UnitTests/PriorityValueTests.cs +++ b/tests/Avalonia.Base.UnitTests/PriorityValueTests.cs @@ -206,7 +206,7 @@ namespace Avalonia.Base.UnitTests Assert.Equal(2, target.GetBindings().Count()); disposable.Dispose(); - Assert.Equal(1, target.GetBindings().Count()); + Assert.Single(target.GetBindings()); } [Fact] @@ -248,7 +248,7 @@ namespace Avalonia.Base.UnitTests Assert.Equal(2, target.GetBindings().Count()); subject.OnCompleted(); - Assert.Equal(1, target.GetBindings().Count()); + Assert.Single(target.GetBindings()); } [Fact] diff --git a/tests/Avalonia.Controls.UnitTests/CalendarTests.cs b/tests/Avalonia.Controls.UnitTests/CalendarTests.cs new file mode 100644 index 0000000000..4c45b1b230 --- /dev/null +++ b/tests/Avalonia.Controls.UnitTests/CalendarTests.cs @@ -0,0 +1,277 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + +using Xunit; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Avalonia.Controls.UnitTests +{ + public class CalendarTests + { + private static bool CompareDates(DateTime first, DateTime second) + { + return first.Year == second.Year && + first.Month == second.Month && + first.Day == second.Day; + } + + [Fact] + public void SelectedDatesChanged_Should_Fire_When_SelectedDate_Set() + { + bool handled = false; + Calendar calendar = new Calendar(); + calendar.SelectionMode = CalendarSelectionMode.SingleDate; + calendar.SelectedDatesChanged += new EventHandler(delegate + { + handled = true; + }); + DateTime value = new DateTime(2000, 10, 10); + calendar.SelectedDate = value; + Assert.True(handled); + } + + [Fact] + public void DisplayDateChanged_Should_Fire_When_DisplayDate_Set() + { + bool handled = false; + Calendar calendar = new Calendar(); + calendar.SelectionMode = CalendarSelectionMode.SingleDate; + calendar.DisplayDateChanged += new EventHandler(delegate + { + handled = true; + }); + DateTime value = new DateTime(2000, 10, 10); + calendar.DisplayDate = value; + Assert.True(handled); + } + + [Fact] + public void Setting_Selected_Date_To_Blackout_Date_Should_Throw() + { + Calendar calendar = new Calendar(); + calendar.BlackoutDates.AddDatesInPast(); + + Assert.ThrowsAny( + () => calendar.SelectedDate = DateTime.Today.AddDays(-1)); + } + + [Fact] + public void Setting_Selected_Date_To_Blackout_Date_Should_Throw_Range() + { + Calendar calendar = new Calendar(); + calendar.BlackoutDates.Add(new CalendarDateRange(DateTime.Today, DateTime.Today.AddDays(10))); + + calendar.SelectedDate = DateTime.Today.AddDays(-1); + Assert.True(CompareDates(calendar.SelectedDate.Value, DateTime.Today.AddDays(-1))); + Assert.True(CompareDates(calendar.SelectedDate.Value, calendar.SelectedDates[0])); + + calendar.SelectedDate = DateTime.Today.AddDays(11); + Assert.True(CompareDates(calendar.SelectedDate.Value, DateTime.Today.AddDays(11))); + Assert.True(CompareDates(calendar.SelectedDate.Value, calendar.SelectedDates[0])); + + Assert.ThrowsAny( + () => calendar.SelectedDate = DateTime.Today.AddDays(5)); + } + + [Fact] + public void Adding_Blackout_Dates_Containing_Selected_Date_Should_Throw() + { + Calendar calendar = new Calendar(); + calendar.SelectedDate = DateTime.Today.AddDays(5); + + Assert.ThrowsAny( + () => calendar.BlackoutDates.Add(new CalendarDateRange(DateTime.Today, DateTime.Today.AddDays(10)))); + } + + [Fact] + public void DisplayDateStartEnd_Should_Constrain_Display_Date() + { + Calendar calendar = new Calendar(); + calendar.SelectionMode = CalendarSelectionMode.SingleDate; + calendar.DisplayDateStart = new DateTime(2005, 12, 30); + + DateTime value = new DateTime(2005, 12, 15); + calendar.DisplayDate = value; + Assert.True(CompareDates(calendar.DisplayDate, calendar.DisplayDateStart.Value)); + + value = new DateTime(2005, 12, 30); + calendar.DisplayDate = value; + Assert.True(CompareDates(calendar.DisplayDate, value)); + + value = DateTime.MaxValue; + calendar.DisplayDate = value; + Assert.True(CompareDates(calendar.DisplayDate, value)); + + calendar.DisplayDateEnd = new DateTime(2010, 12, 30); + Assert.True(CompareDates(calendar.DisplayDate, calendar.DisplayDateEnd.Value)); + } + + [Fact] + public void Setting_DisplayDateEnd_Should_Alter_DispalyDate_And_DisplayDateStart() + { + Calendar calendar = new Calendar(); + DateTime value = new DateTime(2000, 1, 30); + + calendar.DisplayDate = value; + calendar.DisplayDateEnd = value; + calendar.DisplayDateStart = value; + Assert.True(CompareDates(calendar.DisplayDateStart.Value, value)); + Assert.True(CompareDates(calendar.DisplayDateEnd.Value, value)); + + value = value.AddMonths(2); + calendar.DisplayDateStart = value; + Assert.True(CompareDates(calendar.DisplayDateStart.Value, value)); + Assert.True(CompareDates(calendar.DisplayDateEnd.Value, value)); + Assert.True(CompareDates(calendar.DisplayDate, value)); + } + + [Fact] + public void Display_Date_Range_End_Will_Contain_SelectedDate() + { + Calendar calendar = new Calendar(); + calendar.SelectionMode = CalendarSelectionMode.SingleDate; + + calendar.SelectedDate = DateTime.MaxValue; + Assert.True(CompareDates((DateTime)calendar.SelectedDate, DateTime.MaxValue)); + + calendar.DisplayDateEnd = DateTime.MaxValue.AddDays(-1); + Assert.True(CompareDates((DateTime)calendar.DisplayDateEnd, DateTime.MaxValue)); + } + + + /// + /// The days added to the SelectedDates collection. + /// + private IList _selectedDatesChangedAddedDays; + + /// + /// The days removed from the SelectedDates collection. + /// + private IList _selectedDateChangedRemovedDays; + + /// + /// The number of times the SelectedDatesChanged event has been fired. + /// + private int _selectedDatesChangedCount; + + /// + /// Handle the SelectedDatesChanged event. + /// + /// The calendar. + /// Event arguments. + private void OnSelectedDatesChanged(object sender, SelectionChangedEventArgs e) + { + _selectedDatesChangedAddedDays = + e.AddedItems + .Cast() + .ToList(); + _selectedDateChangedRemovedDays = + e.RemovedItems + .Cast() + .ToList(); + _selectedDatesChangedCount++; + } + + /// + /// Clear the variables used to track the SelectedDatesChanged event. + /// + private void ResetSelectedDatesChanged() + { + if (_selectedDatesChangedAddedDays != null) + { + _selectedDatesChangedAddedDays.Clear(); + } + + if (_selectedDateChangedRemovedDays != null) + { + _selectedDateChangedRemovedDays.Clear(); + } + + _selectedDatesChangedCount = 0; + } + + [Fact] + public void SingleDate_Selection_Behavior() + { + ResetSelectedDatesChanged(); + Calendar calendar = new Calendar(); + calendar.SelectedDatesChanged += new EventHandler(OnSelectedDatesChanged); + calendar.SelectionMode = CalendarSelectionMode.SingleDate; + calendar.SelectedDate = DateTime.Today; + Assert.True(CompareDates(calendar.SelectedDate.Value, DateTime.Today)); + Assert.True(calendar.SelectedDates.Count == 1); + Assert.True(CompareDates(calendar.SelectedDates[0], DateTime.Today)); + Assert.True(_selectedDatesChangedCount == 1); + Assert.True(_selectedDatesChangedAddedDays.Count == 1); + Assert.True(_selectedDateChangedRemovedDays.Count == 0); + ResetSelectedDatesChanged(); + + calendar.SelectedDate = DateTime.Today; + Assert.True(CompareDates(calendar.SelectedDate.Value, DateTime.Today)); + Assert.True(calendar.SelectedDates.Count == 1); + Assert.True(CompareDates(calendar.SelectedDates[0], DateTime.Today)); + Assert.True(_selectedDatesChangedCount == 0); + + calendar.ClearValue(Calendar.SelectedDateProperty); + + calendar.SelectionMode = CalendarSelectionMode.None; + Assert.True(calendar.SelectedDates.Count == 0); + Assert.Null(calendar.SelectedDate); + + calendar.SelectionMode = CalendarSelectionMode.SingleDate; + + calendar.SelectedDates.Add(DateTime.Today.AddDays(1)); + Assert.True(CompareDates(calendar.SelectedDate.Value, DateTime.Today.AddDays(1))); + Assert.True(calendar.SelectedDates.Count == 1); + + Assert.ThrowsAny( + () => calendar.SelectedDates.Add(DateTime.Today.AddDays(2))); + } + + [Fact] + public void SingleRange_Selection_Behavior() + { + ResetSelectedDatesChanged(); + Calendar calendar = new Calendar(); + calendar.SelectedDatesChanged += new EventHandler(OnSelectedDatesChanged); + calendar.SelectionMode = CalendarSelectionMode.SingleRange; + calendar.SelectedDate = DateTime.Today; + Assert.True(CompareDates(calendar.SelectedDate.Value, DateTime.Today)); + Assert.True(calendar.SelectedDates.Count == 1); + Assert.True(CompareDates(calendar.SelectedDates[0], DateTime.Today)); + Assert.True(_selectedDatesChangedCount == 1); + Assert.True(_selectedDatesChangedAddedDays.Count == 1); + Assert.True(_selectedDateChangedRemovedDays.Count == 0); + ResetSelectedDatesChanged(); + + calendar.SelectedDates.Clear(); + Assert.Null(calendar.SelectedDate); + ResetSelectedDatesChanged(); + + calendar.SelectedDates.AddRange(DateTime.Today, DateTime.Today.AddDays(10)); + Assert.True(CompareDates(calendar.SelectedDate.Value, DateTime.Today)); + Assert.True(calendar.SelectedDates.Count == 11); + ResetSelectedDatesChanged(); + + calendar.SelectedDates.AddRange(DateTime.Today, DateTime.Today.AddDays(10)); + Assert.True(calendar.SelectedDates.Count == 11); + Assert.True(_selectedDatesChangedCount == 0); + ResetSelectedDatesChanged(); + + calendar.SelectedDates.AddRange(DateTime.Today.AddDays(-20), DateTime.Today); + Assert.True(CompareDates(calendar.SelectedDate.Value, DateTime.Today.AddDays(-20))); + Assert.True(calendar.SelectedDates.Count == 21); + Assert.True(_selectedDatesChangedCount == 1); + Assert.True(_selectedDatesChangedAddedDays.Count == 21); + Assert.True(_selectedDateChangedRemovedDays.Count == 11); + ResetSelectedDatesChanged(); + + calendar.SelectedDates.Add(DateTime.Today.AddDays(100)); + Assert.True(CompareDates(calendar.SelectedDate.Value, DateTime.Today.AddDays(100))); + Assert.True(calendar.SelectedDates.Count == 1); + } + } +} diff --git a/tests/Avalonia.Controls.UnitTests/CarouselTests.cs b/tests/Avalonia.Controls.UnitTests/CarouselTests.cs index e91ab02327..4ce83056c6 100644 --- a/tests/Avalonia.Controls.UnitTests/CarouselTests.cs +++ b/tests/Avalonia.Controls.UnitTests/CarouselTests.cs @@ -47,7 +47,7 @@ namespace Avalonia.Controls.UnitTests target.ApplyTemplate(); target.Presenter.ApplyTemplate(); - Assert.Equal(1, target.GetLogicalChildren().Count()); + Assert.Single(target.GetLogicalChildren()); var child = target.GetLogicalChildren().Single(); @@ -69,9 +69,9 @@ namespace Avalonia.Controls.UnitTests target.ApplyTemplate(); target.Presenter.ApplyTemplate(); - Assert.Equal(1, target.ItemContainerGenerator.Containers.Count()); + Assert.Single(target.ItemContainerGenerator.Containers); target.SelectedIndex = 1; - Assert.Equal(1, target.ItemContainerGenerator.Containers.Count()); + Assert.Single(target.ItemContainerGenerator.Containers); } [Fact] @@ -88,7 +88,7 @@ namespace Avalonia.Controls.UnitTests target.ApplyTemplate(); target.Presenter.ApplyTemplate(); - Assert.Equal(1, target.ItemContainerGenerator.Containers.Count()); + Assert.Single(target.ItemContainerGenerator.Containers); target.SelectedIndex = 1; Assert.Equal(2, target.ItemContainerGenerator.Containers.Count()); } diff --git a/tests/Avalonia.Controls.UnitTests/ClassesTests.cs b/tests/Avalonia.Controls.UnitTests/ClassesTests.cs index c9b9d9f82c..8d2e23d027 100644 --- a/tests/Avalonia.Controls.UnitTests/ClassesTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ClassesTests.cs @@ -161,5 +161,15 @@ namespace Avalonia.Controls.UnitTests Assert.Equal(new[] { ":baz" }, target); } + + [Fact] + public void RemoveAll_Should_Remove_Classes() + { + var target = new Classes("foo", "bar", "baz"); + + target.RemoveAll(new[] { "bar", "baz" }); + + Assert.Equal(new[] { "foo" }, target); + } } } diff --git a/tests/Avalonia.Controls.UnitTests/ControlTests.cs b/tests/Avalonia.Controls.UnitTests/ControlTests.cs index 3506a1606b..313c0b1253 100644 --- a/tests/Avalonia.Controls.UnitTests/ControlTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ControlTests.cs @@ -19,7 +19,7 @@ namespace Avalonia.Controls.UnitTests { var target = new Control(); - Assert.Equal(0, target.Classes.Count); + Assert.Empty(target.Classes); } [Fact] diff --git a/tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs b/tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs index f01eecf647..50610cf595 100644 --- a/tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs @@ -323,7 +323,7 @@ namespace Avalonia.Controls.UnitTests Template = GetTemplate(), }; - Assert.True(target.Classes.Contains(":empty")); + Assert.Contains(":empty", target.Classes); } [Fact] @@ -335,7 +335,7 @@ namespace Avalonia.Controls.UnitTests Items = new[] { 1, 2, 3 }, }; - Assert.False(target.Classes.Contains(":empty")); + Assert.DoesNotContain(":empty", target.Classes); } [Fact] @@ -349,7 +349,7 @@ namespace Avalonia.Controls.UnitTests target.Items = new int[0]; - Assert.True(target.Classes.Contains(":empty")); + Assert.Contains(":empty", target.Classes); } [Fact] diff --git a/tests/Avalonia.Controls.UnitTests/Presenters/CarouselPresenterTests.cs b/tests/Avalonia.Controls.UnitTests/Presenters/CarouselPresenterTests.cs index 260c070406..a50fe852c3 100644 --- a/tests/Avalonia.Controls.UnitTests/Presenters/CarouselPresenterTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Presenters/CarouselPresenterTests.cs @@ -91,9 +91,9 @@ namespace Avalonia.Controls.UnitTests.Presenters }; target.ApplyTemplate(); - Assert.Equal(1, target.ItemContainerGenerator.Containers.Count()); + Assert.Single(target.ItemContainerGenerator.Containers); target.SelectedIndex = 1; - Assert.Equal(1, target.ItemContainerGenerator.Containers.Count()); + Assert.Single(target.ItemContainerGenerator.Containers); } [Fact] @@ -107,8 +107,8 @@ namespace Avalonia.Controls.UnitTests.Presenters }; target.ApplyTemplate(); - Assert.Equal(1, target.ItemContainerGenerator.Containers.Count()); - Assert.Equal(1, target.Panel.Children.Count); + Assert.Single(target.ItemContainerGenerator.Containers); + Assert.Single(target.Panel.Children); target.SelectedIndex = 1; Assert.Equal(2, target.ItemContainerGenerator.Containers.Count()); Assert.Equal(2, target.Panel.Children.Count); @@ -134,24 +134,24 @@ namespace Avalonia.Controls.UnitTests.Presenters items.Add("foo"); target.SelectedIndex = 0; - Assert.Equal(1, target.ItemContainerGenerator.Containers.Count()); - Assert.Equal(1, target.Panel.Children.Count); + Assert.Single(target.ItemContainerGenerator.Containers); + Assert.Single(target.Panel.Children); items.Add("bar"); - Assert.Equal(1, target.ItemContainerGenerator.Containers.Count()); - Assert.Equal(1, target.Panel.Children.Count); + Assert.Single(target.ItemContainerGenerator.Containers); + Assert.Single(target.Panel.Children); target.SelectedIndex = 1; Assert.Equal(2, target.ItemContainerGenerator.Containers.Count()); Assert.Equal(2, target.Panel.Children.Count); items.Remove(items[0]); - Assert.Equal(1, target.ItemContainerGenerator.Containers.Count()); - Assert.Equal(1, target.Panel.Children.Count); + Assert.Single(target.ItemContainerGenerator.Containers); + Assert.Single(target.Panel.Children); items.Remove(items[0]); - Assert.Equal(0, target.ItemContainerGenerator.Containers.Count()); - Assert.Equal(0, target.Panel.Children.Count); + Assert.Empty(target.ItemContainerGenerator.Containers); + Assert.Empty(target.Panel.Children); } [Fact] @@ -171,12 +171,12 @@ namespace Avalonia.Controls.UnitTests.Presenters items.Add("foo"); target.SelectedIndex = 0; - Assert.Equal(1, target.ItemContainerGenerator.Containers.Count()); - Assert.Equal(1, target.Panel.Children.Count); + Assert.Single(target.ItemContainerGenerator.Containers); + Assert.Single(target.Panel.Children); items.Add("bar"); - Assert.Equal(1, target.ItemContainerGenerator.Containers.Count()); - Assert.Equal(1, target.Panel.Children.Count); + Assert.Single(target.ItemContainerGenerator.Containers); + Assert.Single(target.Panel.Children); target.SelectedIndex = 1; Assert.Equal(2, target.ItemContainerGenerator.Containers.Count()); @@ -184,13 +184,13 @@ namespace Avalonia.Controls.UnitTests.Presenters Assert.Equal(0, target.ItemContainerGenerator.Containers.First().Index); items.Remove(items[0]); - Assert.Equal(1, target.ItemContainerGenerator.Containers.Count()); - Assert.Equal(1, target.Panel.Children.Count); + Assert.Single(target.ItemContainerGenerator.Containers); + Assert.Single(target.Panel.Children); Assert.Equal(0, target.ItemContainerGenerator.Containers.First().Index); items.Remove(items[0]); - Assert.Equal(0, target.ItemContainerGenerator.Containers.Count()); - Assert.Equal(0, target.Panel.Children.Count); + Assert.Empty(target.ItemContainerGenerator.Containers); + Assert.Empty(target.Panel.Children); } private class TestItem : ContentControl diff --git a/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Standalone.cs b/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Standalone.cs index 027e162877..6716456c78 100644 --- a/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Standalone.cs +++ b/tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Standalone.cs @@ -42,7 +42,7 @@ namespace Avalonia.Controls.UnitTests.Presenters var logicalChildren = target.GetLogicalChildren(); - Assert.Equal(1, logicalChildren.Count()); + Assert.Single(logicalChildren); Assert.Equal(content, logicalChildren.First()); } @@ -190,7 +190,7 @@ namespace Avalonia.Controls.UnitTests.Presenters var logicalChildren = target.GetLogicalChildren(); - Assert.Equal(1, logicalChildren.Count()); + Assert.Single(logicalChildren); target.Content = "bar"; target.UpdateChild(); @@ -199,7 +199,7 @@ namespace Avalonia.Controls.UnitTests.Presenters logicalChildren = target.GetLogicalChildren(); - Assert.Equal(1, logicalChildren.Count()); + Assert.Single(logicalChildren); Assert.NotEqual(foo, logicalChildren.First()); } diff --git a/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests.cs b/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests.cs index ef7e1062ec..048cdb2ccb 100644 --- a/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests.cs @@ -87,7 +87,7 @@ namespace Avalonia.Controls.UnitTests.Presenters target.ApplyTemplate(); items.RemoveAt(0); - Assert.Equal(1, target.Panel.Children.Count); + Assert.Single(target.Panel.Children); Assert.Equal("bar", ((ContentPresenter)target.Panel.Children[0]).Content); Assert.Equal("bar", ((ContentPresenter)target.ItemContainerGenerator.ContainerFromIndex(0)).Content); } diff --git a/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs b/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs index 51433cc08e..80cc13ab78 100644 --- a/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs +++ b/tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs @@ -704,7 +704,7 @@ namespace Avalonia.Controls.UnitTests.Presenters target.Measure(new Size(100, 100)); target.Arrange(new Rect(target.DesiredSize)); - Assert.Equal(0, target.Panel.Children.Count); + Assert.Empty(target.Panel.Children); items.AddRange(defaultItems.Select(s => s + " new")); diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs b/tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs index 85a450e1dc..06b3202a83 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs @@ -194,7 +194,7 @@ namespace Avalonia.Controls.UnitTests.Primitives target.Open(); - Assert.Equal(1, target.PopupRoot.GetVisualChildren().Count()); + Assert.Single(target.PopupRoot.GetVisualChildren()); var templatedChild = target.PopupRoot.GetVisualChildren().Single(); Assert.IsType(templatedChild); diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/ScrollBarTests.cs b/tests/Avalonia.Controls.UnitTests/Primitives/ScrollBarTests.cs index 5b1ade9c47..0af4d791c7 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/ScrollBarTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/ScrollBarTests.cs @@ -24,7 +24,7 @@ namespace Avalonia.Controls.UnitTests.Primitives var track = (Track)target.GetTemplateChildren().First(x => x.Name == "track"); target.Value = 50; - Assert.Equal(track.Value, 50); + Assert.Equal(50, track.Value); } [Fact] @@ -39,7 +39,7 @@ namespace Avalonia.Controls.UnitTests.Primitives var track = (Track)target.GetTemplateChildren().First(x => x.Name == "track"); track.Value = 50; - Assert.Equal(target.Value, 50); + Assert.Equal(50, target.Value); } [Fact] @@ -56,7 +56,7 @@ namespace Avalonia.Controls.UnitTests.Primitives target.Value = 25; track.Value = 50; - Assert.Equal(target.Value, 50); + Assert.Equal(50, target.Value); } [Fact] diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/ToggleButtonTests.cs b/tests/Avalonia.Controls.UnitTests/Primitives/ToggleButtonTests.cs new file mode 100644 index 0000000000..db60d05a34 --- /dev/null +++ b/tests/Avalonia.Controls.UnitTests/Primitives/ToggleButtonTests.cs @@ -0,0 +1,57 @@ +using Avalonia.Markup.Xaml.Data; +using Avalonia.UnitTests; + +using Xunit; + +namespace Avalonia.Controls.Primitives.UnitTests +{ + public class ToggleButtonTests + { + private const string uncheckedClass = ":unchecked"; + private const string checkedClass = ":checked"; + private const string indeterminateClass = ":indeterminate"; + + [Theory] + [InlineData(false, uncheckedClass, false)] + [InlineData(false, uncheckedClass, true)] + [InlineData(true, checkedClass, false)] + [InlineData(true, checkedClass, true)] + [InlineData(null, indeterminateClass, false)] + [InlineData(null, indeterminateClass, true)] + public void ToggleButton_Has_Correct_Class_According_To_Is_Checked(bool? isChecked, string expectedClass, bool isThreeState) + { + var toggleButton = new ToggleButton(); + toggleButton.IsThreeState = isThreeState; + toggleButton.IsChecked = isChecked; + + Assert.Contains(expectedClass, toggleButton.Classes); + } + + [Fact] + public void ToggleButton_Is_Checked_Binds_To_Bool() + { + var toggleButton = new ToggleButton(); + var source = new Class1(); + + toggleButton.DataContext = source; + toggleButton.Bind(ToggleButton.IsCheckedProperty, new Binding("Foo")); + + source.Foo = true; + Assert.True(toggleButton.IsChecked); + + source.Foo = false; + Assert.False(toggleButton.IsChecked); + } + + private class Class1 : NotifyingBase + { + private bool _foo; + + public bool Foo + { + get { return _foo; } + set { _foo = value; RaisePropertyChanged(); } + } + } + } +} diff --git a/tests/Avalonia.Controls.UnitTests/RadioButtonTests.cs b/tests/Avalonia.Controls.UnitTests/RadioButtonTests.cs new file mode 100644 index 0000000000..37fb52beeb --- /dev/null +++ b/tests/Avalonia.Controls.UnitTests/RadioButtonTests.cs @@ -0,0 +1,36 @@ +using Avalonia.Markup.Xaml.Data; +using Avalonia.UnitTests; + +using Xunit; + +namespace Avalonia.Controls.UnitTests +{ + public class RadioButtonTests + { + [Theory] + [InlineData(false)] + [InlineData(true)] + public void Indeterminate_RadioButton_Is_Not_Unchecked_After_Checking_Other_Radio_Button(bool isThreeState) + { + var panel = new Panel(); + + var radioButton1 = new RadioButton(); + radioButton1.IsThreeState = false; + radioButton1.IsChecked = false; + + var radioButton2 = new RadioButton(); + radioButton2.IsThreeState = isThreeState; + radioButton2.IsChecked = null; + + panel.Children.Add(radioButton1); + panel.Children.Add(radioButton2); + + Assert.Null(radioButton2.IsChecked); + + radioButton1.IsChecked = true; + + Assert.True(radioButton1.IsChecked); + Assert.Null(radioButton2.IsChecked); + } + } +} diff --git a/tests/Avalonia.Controls.UnitTests/TextBoxTests_DataValidation.cs b/tests/Avalonia.Controls.UnitTests/TextBoxTests_DataValidation.cs index ff3634b9fe..daf2715d84 100644 --- a/tests/Avalonia.Controls.UnitTests/TextBoxTests_DataValidation.cs +++ b/tests/Avalonia.Controls.UnitTests/TextBoxTests_DataValidation.cs @@ -33,11 +33,11 @@ namespace Avalonia.Controls.UnitTests target.ApplyTemplate(); - Assert.False(target.Classes.Contains(":error")); + Assert.DoesNotContain(":error", target.Classes); target.Text = "20"; - Assert.True(target.Classes.Contains(":error")); + Assert.Contains(":error", target.Classes); target.Text = "1"; - Assert.False(target.Classes.Contains(":error")); + Assert.DoesNotContain(":error", target.Classes); } } @@ -57,7 +57,7 @@ namespace Avalonia.Controls.UnitTests Assert.Null(target.DataValidationErrors); target.Text = "20"; - Assert.Equal(1, target.DataValidationErrors.Count()); + Assert.Single(target.DataValidationErrors); Assert.IsType(target.DataValidationErrors.Single()); target.Text = "1"; Assert.Null(target.DataValidationErrors); diff --git a/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs b/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs index 00d4af7e4d..1a07bdc7d1 100644 --- a/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs +++ b/tests/Avalonia.Layout.UnitTests/FullLayoutTests.cs @@ -109,7 +109,7 @@ namespace Avalonia.Layout.UnitTests var presenters = scrollViewer.GetTemplateChildren().OfType().ToList(); Assert.Equal(2, scrollBars.Count); - Assert.Equal(1, presenters.Count); + Assert.Single(presenters); var presenter = presenters[0]; Assert.Equal(new Size(190, 190), presenter.Bounds.Size); diff --git a/tests/Avalonia.LeakTests/ControlTests.cs b/tests/Avalonia.LeakTests/ControlTests.cs index 979127cd14..fe3ad59bb4 100644 --- a/tests/Avalonia.LeakTests/ControlTests.cs +++ b/tests/Avalonia.LeakTests/ControlTests.cs @@ -155,7 +155,7 @@ namespace Avalonia.LeakTests // template applied. LayoutManager.Instance.ExecuteInitialLayoutPass(window); Assert.IsType(window.Presenter.Child); - Assert.NotEqual(0, window.Presenter.Child.GetVisualChildren().Count()); + Assert.NotEmpty(window.Presenter.Child.GetVisualChildren()); // Clear the content and ensure the TextBox is removed. window.Content = null; @@ -290,7 +290,7 @@ namespace Avalonia.LeakTests // Do a layout and make sure that TreeViewItems get realized. LayoutManager.Instance.ExecuteInitialLayoutPass(window); - Assert.Equal(1, target.ItemContainerGenerator.Containers.Count()); + Assert.Single(target.ItemContainerGenerator.Containers); // Clear the content and ensure the TreeView is removed. window.Content = null; diff --git a/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_DataValidation.cs b/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_DataValidation.cs index 125bd84f3d..9bf1e4711b 100644 --- a/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_DataValidation.cs +++ b/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_DataValidation.cs @@ -78,6 +78,10 @@ namespace Avalonia.Markup.UnitTests.Data var data = new IndeiTest(); var observer = new ExpressionObserver(data, nameof(data.MustBePositive), true); var result = new List(); + + var errmsg = string.Empty; + try { typeof(IndeiTest).GetProperty(nameof(IndeiTest.MustBePositive)).SetValue(data, "foo"); } + catch(Exception e) { errmsg = e.Message; } observer.Subscribe(x => result.Add(x)); observer.SetValue(5); @@ -99,7 +103,7 @@ namespace Avalonia.Markup.UnitTests.Data // Exception is thrown by trying to set value to "foo". new BindingNotification( - new ArgumentException("Object of type 'System.String' cannot be converted to type 'System.Int32'."), + new ArgumentException(errmsg), BindingErrorType.DataValidationError), // Value is set then validation is updated. diff --git a/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Negation.cs b/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Negation.cs index 6a23a24051..f4aa85c393 100644 --- a/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Negation.cs +++ b/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Negation.cs @@ -19,7 +19,7 @@ namespace Avalonia.Markup.UnitTests.Data var target = new ExpressionObserver(data, "!Foo"); var result = await target.Take(1); - Assert.Equal(false, result); + Assert.False((bool)result); GC.KeepAlive(data); } @@ -31,7 +31,7 @@ namespace Avalonia.Markup.UnitTests.Data var target = new ExpressionObserver(data, "!Foo"); var result = await target.Take(1); - Assert.Equal(true, result); + Assert.True((bool)result); GC.KeepAlive(data); } @@ -43,7 +43,7 @@ namespace Avalonia.Markup.UnitTests.Data var target = new ExpressionObserver(data, "!Foo"); var result = await target.Take(1); - Assert.Equal(false, result); + Assert.False((bool)result); GC.KeepAlive(data); } @@ -55,7 +55,7 @@ namespace Avalonia.Markup.UnitTests.Data var target = new ExpressionObserver(data, "!Foo"); var result = await target.Take(1); - Assert.Equal(true, result); + Assert.True((bool)result); GC.KeepAlive(data); } @@ -67,7 +67,7 @@ namespace Avalonia.Markup.UnitTests.Data var target = new ExpressionObserver(data, "!Foo"); var result = await target.Take(1); - Assert.Equal(false, result); + Assert.False((bool)result); GC.KeepAlive(data); } diff --git a/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Task.cs b/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Task.cs index c251f4398a..87a8be045b 100644 --- a/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Task.cs +++ b/tests/Avalonia.Markup.UnitTests/Data/ExpressionObserverTests_Task.cs @@ -28,7 +28,7 @@ namespace Avalonia.Markup.UnitTests.Data tcs.SetResult("foo"); sync.ExecutePostedCallbacks(); - Assert.Equal(1, result.Count); + Assert.Single(result); Assert.IsType>(result[0]); GC.KeepAlive(data); diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests_Source.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests_Source.cs index c6006f3afb..1fbf8b679d 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests_Source.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Data/BindingTests_Source.cs @@ -23,7 +23,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Data target.Bind(TextBlock.TextProperty, binding); - Assert.Equal(target.Text, "foo"); + Assert.Equal("foo", target.Text); } public class Source : INotifyPropertyChanged diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs index 03dc5374e0..ffd666fe12 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs @@ -79,6 +79,20 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml Assert.Equal(21.0, TextBlock.GetFontSize(target)); } + [Fact] + public void Attached_Property_With_Namespace_Is_Set() + { + var xaml = + @""; + + var target = AvaloniaXamlLoader.Parse(xaml); + + Assert.NotNull(target); + Assert.Equal("Bar", BasicTestsAttachedPropertyHolder.GetFoo(target)); + } + [Fact] public void Attached_Property_Supports_Binding() { @@ -105,7 +119,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml var target = AvaloniaXamlLoader.Parse(xaml); - Assert.Equal(0, target.Children.Count); + Assert.Empty(target.Children); Assert.Equal("Foo", ToolTip.GetTip(target)); } @@ -363,7 +377,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml var styles = AvaloniaXamlLoader.Parse(xaml); - Assert.Equal(1, styles.Count); + Assert.Single(styles); var style = (Style)styles[0]; @@ -391,13 +405,13 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml var styles = AvaloniaXamlLoader.Parse(xaml); - Assert.Equal(1, styles.Count); + Assert.Single(styles); var style = (Style)styles[0]; var setters = style.Setters.Cast().ToArray(); - Assert.Equal(1, setters.Length); + Assert.Single(setters); Assert.Equal(TextBlock.FontSizeProperty, setters[0].Property); Assert.Equal(21.0, setters[0].Value); @@ -445,7 +459,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml "; var styles = AvaloniaXamlLoader.Parse(xaml); - Assert.Equal(1, styles.Count); + Assert.Single(styles); var style = (Style)styles[0]; @@ -674,7 +688,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml var style = AvaloniaXamlLoader.Parse