forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreviewerReflectionTests.cs
51 lines (43 loc) · 1.43 KB
/
PreviewerReflectionTests.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
using System;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Core.UnitTests
{
[TestFixture]
public class PreviewerReflectionTests
{
class FakePlatform : IPlatform
{
public SizeRequest GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint)
{
throw new NotImplementedException();
}
}
[Test]
public void PageHasPlatformProperty()
{
var page = new Page();
var setPlatform = page.GetType().GetProperty("Platform", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
Assert.That(setPlatform, Is.Not.Null, "Previewer requires that Page have a property called 'Platform'");
TestDelegate setValue = () => setPlatform.SetValue(page, new FakePlatform(), null);
Assert.That(setValue, Throws.Nothing, "'Page.Platform' must have a setter");
}
[Test]
public void RegisterAllExists()
{
var type = typeof(Registrar);
var methods = type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic);
var method = methods.Single(t =>
{
var parameters = t.GetParameters();
return t.Name == "RegisterAll"
&& parameters.Length == 1
&& parameters[0].ParameterType == typeof(Type[]);
});
Assert.That(method, Is.Not.Null, "Previewer requires that Registrar have a static non-public method "
+ "'RegisterAll' which takes a single parameter of Type[]");
}
}
}