summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml.cs
blob: 6f9ef80a6adfba37780e26984243a5dc52e924f8 (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
using System;
using System.Collections.Generic;
using System.Windows.Input;
using Xamarin.Forms;
using NUnit.Framework;

namespace Xamarin.Forms.Xaml.UnitTests
{
	public enum NavigationOperation
	{
		Forward,
		Back,
		Replace,
	}

	[ContentProperty(nameof(Operation))]
	public class NavigateExtension : IMarkupExtension<ICommand>
	{
		public NavigationOperation Operation { get; set; }

		public Type Type { get; set; }

		public ICommand ProvideValue(IServiceProvider serviceProvider)
		{
			return new Command(() => { });
		}

		object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
		{
			return ProvideValue(serviceProvider);
		}
	}

	public partial class TypeExtension : ListView
	{
		public TypeExtension()
		{
			InitializeComponent();
		}

		public TypeExtension(bool useCompiledXaml)
		{
			//this stub will be replaced at compile time
		}

		[TestFixture]
		public class Tests
		{
			[TestCase(false)]
			[TestCase(true)]
			public void NestedMarkupExtensionInsideDataTemplate(bool useCompiledXaml)
			{
				var listView = new TypeExtension(useCompiledXaml);
				listView.ItemsSource = new string [2];

				var cell = (ViewCell)listView.TemplatedItems [0];
				var button = (Button)cell.View;
				Assert.IsNotNull(button.Command);

				cell = (ViewCell)listView.TemplatedItems [1];
				button = (Button)cell.View;
				Assert.IsNotNull(button.Command);
			}
		}
	}
}