summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests/Issues/Bz45299.xaml.cs
blob: 791e870f522e51bb80fca4d47b68cba0f23f5fee (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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Xamarin.Forms;
using Xamarin.Forms.Core.UnitTests;

namespace Xamarin.Forms.Xaml.UnitTests
{
	public class Bz45299Control : ContentView
	{
		public static readonly BindableProperty PortraitLayoutProperty =
		   BindableProperty.Create(nameof(PortraitLayout), typeof(Bz45299OrientationLayout), typeof(Bz45299Control));
		public Bz45299OrientationLayout PortraitLayout {
			get { return (Bz45299OrientationLayout)GetValue(PortraitLayoutProperty); }
			set { this.SetValue(PortraitLayoutProperty, value); }
		}

	}

	public class Bz45299OrientationLayout : BindableObject
	{
		public static readonly BindableProperty SizeProperty =
		   BindableProperty.Create(nameof(Size), typeof(Bz45299UISize), typeof(Bz45299OrientationLayout), Bz45299UISize.Zero);
		public Bz45299UISize Size {
			get { return (Bz45299UISize)GetValue(SizeProperty); }
			set { SetValue(SizeProperty, value); }
		}

		public static readonly BindableProperty SpacingProperty =
		   BindableProperty.Create(nameof(Spacing), typeof(Bz45299UILength), typeof(Bz45299OrientationLayout), Bz45299UILength.Zero);
		public Bz45299UILength Spacing {
			get { return (Bz45299UILength)GetValue(SpacingProperty); }
			set { SetValue(SpacingProperty, value); }
		}

		public static readonly BindableProperty CountProperty =
		   BindableProperty.Create(nameof(Count), typeof(int), typeof(Bz45299OrientationLayout), 1);
		public int Count {
			get { return (int)GetValue(CountProperty); }
			set { SetValue(CountProperty, value); }
		}
	}

	[TypeConverter(typeof(Bz45299UILengthTypeConverter))]
	public class Bz45299UILength
	{
		public static Bz45299UILength Zero => new Bz45299UILength { Value = 0 };

		public double Value { get; set; }

		public static implicit operator string(Bz45299UILength uiLength) => uiLength.Value.ToString();
		public static implicit operator double(Bz45299UILength uiLength) => uiLength.Value;

		public static implicit operator Bz45299UILength(string value) => Zero;
		public static implicit operator Bz45299UILength(long value) => Zero;
		public static implicit operator Bz45299UILength(ulong value) => Zero;
		public static implicit operator Bz45299UILength(int value) => Zero;
		public static implicit operator Bz45299UILength(uint value) => Zero;
		public static implicit operator Bz45299UILength(double value) => Zero;
		public static implicit operator Bz45299UILength(float value) => Zero;
	}

	public class Bz45299UILengthTypeConverter : TypeConverter
	{
		static readonly Type StringType = typeof(string);
		public override bool CanConvertFrom(Type sourceType)
		{
			if (sourceType != StringType)
				return false;

			return true;
		}

		public override object ConvertFromInvariantString(string value) => Bz45299UILength.Zero;
	}

	[TypeConverter(typeof(Bz45299UISizeTypeConverter))]
	public class Bz45299UISize
	{
		public static Bz45299UISize Zero => new Bz45299UISize { Width = 0, Height = 0 };

		public Bz45299UILength Width { get; set; }
		public Bz45299UILength Height { get; set; }

		public static implicit operator Bz45299UISize(string value) => Zero;
		public static implicit operator Size(Bz45299UISize uiSize) => new Size(uiSize.Width, uiSize.Height);
		public static implicit operator Bz45299UISize(Size size) => new Bz45299UISize { Width = size.Width, Height = size.Height };
	}

	public class Bz45299UISizeTypeConverter : TypeConverter
	{
		private static readonly Type StringType = typeof(string);

		public override bool CanConvertFrom(Type sourceType)
		{
			if (sourceType != StringType)
				return false;

			return true;
		}

		public override object ConvertFromInvariantString(string value) => Bz45299UISize.Zero;
	}

	public partial class Bz45299 : ContentPage
	{
		public Bz45299()
		{
			InitializeComponent();
		}
		public Bz45299(bool useCompiledXaml)
		{
			//this stub will be replaced at compile time
		}

		[TestFixture]
		class Tests
		{
			[SetUp]
			public void Setup()
			{
				Device.PlatformServices = new MockPlatformServices();
			}

			[TearDown]
			public void TearDown()
			{
				Device.PlatformServices = null;
			}

			[TestCase(true)]
			[TestCase(false)]
			public void XamlCCustomTypeConverter(bool useCompiledXaml)
			{
				var p = new Bz45299(useCompiledXaml);
				Assert.AreEqual(0d, p.ctrl.PortraitLayout.Spacing.Value);
			}
		}
	}
}