Xamarin.Forms/Xamarin.Forms.Core.UnitTests/LinearGradientBrushTests.cs

130 строки
3.7 KiB
C#
Исходник Постоянная ссылка Обычный вид История

[Enhancement] Brushes (#9220) * Added brushes to Core, Core Gallery and the iOS implementation * Implemented brushes on UWP * Improved UWP brushes implementation * Changes to improve the brushes Core Gallery samples * Added default SolidColorBrush colors * Improved brushes samples adding more options * Implement brushes on Android * Fixed Brush Background on Android ImageButton * Initial code to add support to brushes using CSS * Support more CSS gradient options Added more unit tests * Changes in Core Gallery brushes samples * Reuse same ColorTypeConverter in the GradientBrushParser * Fixed brush issues on specific controles (Android: Page) (iOS: Label, ImageButton, NavBar) * Updated brushes unit tests * Added new sample in Core Gallery Fixed angle issue in UWP LinearGradientBrush * Fixed UWP issue updating brushes in Buttons * Improved UWP UpdateBackground logic in VisualElementRenderer * Fixed UWP build errors Fixed some UWP brushes issues * Added WPF implementation * Fixed issue verifying brushes in iOS VisualElementRenderer * Fixed iOS brushes in BoxView * Added scroll to LinearGradientPointsGallery sample * Fixed iOS brushes size issue * Implemented brushes in macOS * Uncommented wrong method to update image brushes resizing the App Window * Fixed Windows Build * Fixed broken unit tests * Added more comments in UWP RadialGradientBrush * Added BrushExperimental flag * Notify VisualElement Background changes if some Brush property have changed * Fixed brush issue in Android Button using CornerRadius * Fixed unnecessary border color issue applying brushes to Layouts in Android * Fixed brushes unit tests * Removed EditorBrowsable label in BackgroundColor until deprecate it * - fix whitespace * Changed IsEmpty Brush property to be abstract and implemented it in every brush. * Changed IGradientShader to GradientShader * Fixed BindableBrushGallery issue on iOS/macOS * Fixed wrong iOS right RadialGradientBrush * Fixed Brush in iOS NavBar iOS < 13 * Fixed iOS Brush on Button and Label * Fixed Build errors * Replace UWP Community Toolkit RadialGradientBrush class by WinUI 2.4 RadialGradientBrush * Fixed broken unit test * Fixed brushes issues on macOS resizing the Window or on iOS rotation, etc. * Added the option to choose the BorderColor in the Brushes Playground * Removed duplicated ShapeRenderer Compile line in Platform iOS csproj * Removed unnecessary changes * Added Visual Brush samples * Implemented Brushes in iOS Visual Renderers * Only show the access to the Brushes Visual sample in Android and iOS * Added brushes support to shapes * Fixed Build error * Removed unnecessary changes * Added Brushes support to Android Material ActivityIndicator * Added brushes support to Android Visual Frame * Updated Visual Android Renderers * Fixed BoxView Brush issue * Updated brush views sample to add more BoxView cases * Added brushes tests classes * More Brushes unit tests * Added more controls to test in the BrushesViewGallery * Added new Brushes sample * Fixed build error * Updated AnimateShapeGallery to use a Brush * Fixed CoreGallery Core samples allowing to use the Background property * Added Brushes platform unit tests * - apply background color if solid brush is empty * - fix visual checkbox * Fixed the build * Fixed issue on Shapes * Updated MaterialButtonRenderer to use IsOneOf with several properties * Removed unnecesary change in UWP Styles * Use IsOneOf in UWP BackgroundTracker * Added IsNullOrEmpty Brush method * Removed unnecessary brush updates * Added more constructors to LinearGradientBrush and RadialGradientBrush * Fixed UWP NavBar BarBackgroundColor issue * Removed unnecessary line in UWP BoxViewRenderer * Fixed NRE in iOS ButtonRenderer * Updated iOS Button SetBackground logic * Implemented Shell FlyoutBackground Co-authored-by: Shane Neuville <shneuvil@microsoft.com> Co-authored-by: Samantha Houts <samhouts@users.noreply.github.com>
2020-07-17 17:44:13 +03:00
using NUnit.Framework;
namespace Xamarin.Forms.Core.UnitTests
{
public class LinearGradientBrushTests : BaseTestFixture
{
[SetUp]
public override void Setup()
{
base.Setup();
}
[Test]
public void TestConstructor()
{
LinearGradientBrush linearGradientBrush = new LinearGradientBrush();
Assert.AreEqual(1.0d, linearGradientBrush.EndPoint.X, "EndPoint.X");
Assert.AreEqual(1.0d, linearGradientBrush.EndPoint.Y, "EndPoint.Y");
[Enhancement] Brushes (#9220) * Added brushes to Core, Core Gallery and the iOS implementation * Implemented brushes on UWP * Improved UWP brushes implementation * Changes to improve the brushes Core Gallery samples * Added default SolidColorBrush colors * Improved brushes samples adding more options * Implement brushes on Android * Fixed Brush Background on Android ImageButton * Initial code to add support to brushes using CSS * Support more CSS gradient options Added more unit tests * Changes in Core Gallery brushes samples * Reuse same ColorTypeConverter in the GradientBrushParser * Fixed brush issues on specific controles (Android: Page) (iOS: Label, ImageButton, NavBar) * Updated brushes unit tests * Added new sample in Core Gallery Fixed angle issue in UWP LinearGradientBrush * Fixed UWP issue updating brushes in Buttons * Improved UWP UpdateBackground logic in VisualElementRenderer * Fixed UWP build errors Fixed some UWP brushes issues * Added WPF implementation * Fixed issue verifying brushes in iOS VisualElementRenderer * Fixed iOS brushes in BoxView * Added scroll to LinearGradientPointsGallery sample * Fixed iOS brushes size issue * Implemented brushes in macOS * Uncommented wrong method to update image brushes resizing the App Window * Fixed Windows Build * Fixed broken unit tests * Added more comments in UWP RadialGradientBrush * Added BrushExperimental flag * Notify VisualElement Background changes if some Brush property have changed * Fixed brush issue in Android Button using CornerRadius * Fixed unnecessary border color issue applying brushes to Layouts in Android * Fixed brushes unit tests * Removed EditorBrowsable label in BackgroundColor until deprecate it * - fix whitespace * Changed IsEmpty Brush property to be abstract and implemented it in every brush. * Changed IGradientShader to GradientShader * Fixed BindableBrushGallery issue on iOS/macOS * Fixed wrong iOS right RadialGradientBrush * Fixed Brush in iOS NavBar iOS < 13 * Fixed iOS Brush on Button and Label * Fixed Build errors * Replace UWP Community Toolkit RadialGradientBrush class by WinUI 2.4 RadialGradientBrush * Fixed broken unit test * Fixed brushes issues on macOS resizing the Window or on iOS rotation, etc. * Added the option to choose the BorderColor in the Brushes Playground * Removed duplicated ShapeRenderer Compile line in Platform iOS csproj * Removed unnecessary changes * Added Visual Brush samples * Implemented Brushes in iOS Visual Renderers * Only show the access to the Brushes Visual sample in Android and iOS * Added brushes support to shapes * Fixed Build error * Removed unnecessary changes * Added Brushes support to Android Material ActivityIndicator * Added brushes support to Android Visual Frame * Updated Visual Android Renderers * Fixed BoxView Brush issue * Updated brush views sample to add more BoxView cases * Added brushes tests classes * More Brushes unit tests * Added more controls to test in the BrushesViewGallery * Added new Brushes sample * Fixed build error * Updated AnimateShapeGallery to use a Brush * Fixed CoreGallery Core samples allowing to use the Background property * Added Brushes platform unit tests * - apply background color if solid brush is empty * - fix visual checkbox * Fixed the build * Fixed issue on Shapes * Updated MaterialButtonRenderer to use IsOneOf with several properties * Removed unnecesary change in UWP Styles * Use IsOneOf in UWP BackgroundTracker * Added IsNullOrEmpty Brush method * Removed unnecessary brush updates * Added more constructors to LinearGradientBrush and RadialGradientBrush * Fixed UWP NavBar BarBackgroundColor issue * Removed unnecessary line in UWP BoxViewRenderer * Fixed NRE in iOS ButtonRenderer * Updated iOS Button SetBackground logic * Implemented Shell FlyoutBackground Co-authored-by: Shane Neuville <shneuvil@microsoft.com> Co-authored-by: Samantha Houts <samhouts@users.noreply.github.com>
2020-07-17 17:44:13 +03:00
}
[Test]
public void TestConstructorUsingGradientStopCollection()
{
var gradientStops = new GradientStopCollection
{
new GradientStop { Color = Color.Red, Offset = 0.1f },
new GradientStop { Color = Color.Orange, Offset = 0.8f }
};
LinearGradientBrush linearGradientBrush = new LinearGradientBrush(gradientStops, new Point(0, 0), new Point(0, 1));
Assert.AreNotEqual(0, linearGradientBrush.GradientStops.Count, "GradientStops");
Assert.AreEqual(0.0d, linearGradientBrush.EndPoint.X, "EndPoint.X");
Assert.AreEqual(1.0d, linearGradientBrush.EndPoint.Y, "EndPoint.Y");
}
[Test]
public void TestEmptyLinearGradientBrush()
{
LinearGradientBrush nullLinearGradientBrush = new LinearGradientBrush();
Assert.AreEqual(true, nullLinearGradientBrush.IsEmpty, "IsEmpty");
LinearGradientBrush linearGradientBrush = new LinearGradientBrush
{
StartPoint = new Point(0, 0),
EndPoint = new Point(1, 0),
GradientStops = new GradientStopCollection
{
new GradientStop { Color = Color.Orange, Offset = 0.1f },
new GradientStop { Color = Color.Red, Offset = 0.8f }
}
};
Assert.AreEqual(false, linearGradientBrush.IsEmpty, "IsEmpty");
}
[Test]
public void TestNullOrEmptyLinearGradientBrush()
{
LinearGradientBrush nullLinearGradientBrush = null;
Assert.AreEqual(true, Brush.IsNullOrEmpty(nullLinearGradientBrush), "IsNullOrEmpty");
LinearGradientBrush emptyLinearGradientBrush = new LinearGradientBrush();
Assert.AreEqual(true, Brush.IsNullOrEmpty(emptyLinearGradientBrush), "IsNullOrEmpty");
LinearGradientBrush linearGradientBrush = new LinearGradientBrush
{
StartPoint = new Point(0, 0),
EndPoint = new Point(1, 0),
GradientStops = new GradientStopCollection
{
new GradientStop { Color = Color.Orange, Offset = 0.1f },
new GradientStop { Color = Color.Red, Offset = 0.8f }
}
};
Assert.AreEqual(false, Brush.IsNullOrEmpty(linearGradientBrush), "IsNullOrEmpty");
}
[Test]
public void TestLinearGradientBrushPoints()
{
LinearGradientBrush linearGradientBrush = new LinearGradientBrush
{
StartPoint = new Point(0, 0),
EndPoint = new Point(1, 0)
};
Assert.AreEqual(0, linearGradientBrush.StartPoint.X);
Assert.AreEqual(0, linearGradientBrush.StartPoint.Y);
Assert.AreEqual(1, linearGradientBrush.EndPoint.X);
Assert.AreEqual(0, linearGradientBrush.EndPoint.Y);
}
[Test]
public void TestLinearGradientBrushOnlyOneGradientStop()
{
LinearGradientBrush linearGradientBrush = new LinearGradientBrush
{
GradientStops = new GradientStopCollection
{
new GradientStop { Color = Color.Red, }
},
StartPoint = new Point(0, 0),
EndPoint = new Point(1, 0)
};
Assert.IsNotNull(linearGradientBrush);
}
[Test]
public void TestLinearGradientBrushGradientStops()
{
LinearGradientBrush linearGradientBrush = new LinearGradientBrush
{
GradientStops = new GradientStopCollection
{
new GradientStop { Color = Color.Red, Offset = 0.1f },
new GradientStop { Color = Color.Blue, Offset = 1.0f }
},
StartPoint = new Point(0, 0),
EndPoint = new Point(1, 0)
};
Assert.AreEqual(2, linearGradientBrush.GradientStops.Count);
}
}
}