-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
RotationTests.cs
106 lines (94 loc) · 2.5 KB
/
RotationTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections;
using System.Threading.Tasks;
using NUnit.Framework;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
namespace Xamarin.Forms.Platform.UAP.UnitTests
{
[TestFixture]
public class RotationTests : PlatformTestFixture
{
static IEnumerable RotationXCases
{
get
{
foreach (var element in BasicViews)
{
element.RotationX = 33.0;
yield return CreateTestCase(element);
}
}
}
static IEnumerable RotationYCases
{
get
{
foreach (var element in BasicViews)
{
element.RotationY = 86.0;
yield return CreateTestCase(element);
}
}
}
static IEnumerable RotationCases
{
get
{
foreach (var element in BasicViews)
{
element.Rotation = 23.0;
yield return CreateTestCase(element);
}
}
}
[Test, Category("RotationX"), TestCaseSource(nameof(RotationXCases))]
[Description("View X rotation should match renderer X rotation")]
public async Task RotationXConsistent(View view)
{
var expected = view.RotationX;
var actual = await GetRendererProperty(view, ver => GetRotationX(ver.ContainerElement));
Assert.That(actual, Is.EqualTo(expected));
}
[Test, Category("RotationY"), TestCaseSource(nameof(RotationYCases))]
[Description("View Y rotation should match renderer Y rotation")]
public async Task RotationYConsistent(View view)
{
var expected = view.RotationY;
var actual = await GetRendererProperty(view, ver => GetRotationY(ver.ContainerElement));
Assert.That(actual, Is.EqualTo(expected));
}
[Test, Category("Rotation"), TestCaseSource(nameof(RotationCases))]
[Description("View rotation should match renderer rotation")]
public async Task RotationConsistent(View view)
{
var expected = view.Rotation;
var actual = await GetRendererProperty(view, ver => GetRotation(ver.ContainerElement));
Assert.That(actual, Is.EqualTo(expected));
}
double GetRotationX(FrameworkElement fe)
{
if (fe.Projection is PlaneProjection planeProjection)
{
return -planeProjection.RotationX;
}
throw new Exception("No rotation found");
}
double GetRotationY(FrameworkElement fe)
{
if (fe.Projection is PlaneProjection planeProjection)
{
return -planeProjection.RotationY;
}
throw new Exception("No rotation found");
}
double GetRotation(FrameworkElement fe)
{
if (fe.RenderTransform is CompositeTransform compositeTransform)
{
return compositeTransform.Rotation;
}
throw new Exception("No rotation found");
}
}
}