blob: d00f1f41da85848b2ddcfa7dfeb10a0fcb945644 (
plain)
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
|
using System;
using NUnit.Framework;
namespace Xamarin.Forms.Xaml.UnitTests
{
public abstract class Unreported005RelativeToView : IMarkupExtension
{
protected Unreported005RelativeToView()
{
Factor = 1;
}
public string ElementName { get; set; }
public double Factor { get; set; }
public double Constant { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
var element = new ReferenceExtension { Name = ElementName }.ProvideValue(serviceProvider) as View;
if (element != null) {
var result = Constraint.RelativeToView(element, (layout, view) => DeterminePosition(view) + Constant);
return result;
}
return null;
}
protected virtual double DeterminePosition(VisualElement view)
{
var result = DetermineStart(view) + DetermineExtent(view) * Factor;
return result;
}
protected abstract double DetermineExtent(VisualElement view);
protected abstract double DetermineStart(VisualElement view);
}
public class Unreported005RelativeToViewHorizontal : Unreported005RelativeToView
{
protected override double DetermineExtent(VisualElement view)
{
return view.Width;
}
protected override double DetermineStart(VisualElement view)
{
return view.X;
}
}
//[XamlCompilation(XamlCompilationOptions.Skip)]
public partial class Unreported005 : ContentPage
{
public Unreported005()
{
InitializeComponent();
}
public Unreported005(bool useCompiledXaml)
{
//this stub will be replaced at compile time
}
[TestFixture]
class Tests
{
[TestCase(true), TestCase(false)]
public void CustomMarkupExtensionWorks(bool useCompiledXaml)
{
var page = new Unreported005(useCompiledXaml);
Assert.That(RelativeLayout.GetXConstraint(page.after), Is.TypeOf<Constraint>());
Assert.NotNull(RelativeLayout.GetXConstraint(page.after));
}
}
}
}
|