2016-08-16 21:33:44 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using NUnit.Framework;
|
2017-04-07 10:48:17 +03:00
|
|
|
|
using Xamarin.Forms.Core.UnitTests;
|
2016-08-16 21:33:44 +03:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2017-04-20 21:53:13 +03:00
|
|
|
|
return new Command(() => {});
|
2016-08-16 21:33:44 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
return ProvideValue(serviceProvider);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-20 21:53:13 +03:00
|
|
|
|
public partial class TypeExtension : ContentPage
|
2016-08-16 21:33:44 +03:00
|
|
|
|
{
|
|
|
|
|
public TypeExtension()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TypeExtension(bool useCompiledXaml)
|
|
|
|
|
{
|
|
|
|
|
//this stub will be replaced at compile time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class Tests
|
|
|
|
|
{
|
2017-04-07 10:48:17 +03:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
Device.PlatformServices = new MockPlatformServices();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDown()
|
|
|
|
|
{
|
|
|
|
|
Device.PlatformServices = null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 21:33:44 +03:00
|
|
|
|
[TestCase(false)]
|
|
|
|
|
[TestCase(true)]
|
|
|
|
|
public void NestedMarkupExtensionInsideDataTemplate(bool useCompiledXaml)
|
|
|
|
|
{
|
2017-04-20 21:53:13 +03:00
|
|
|
|
var page = new TypeExtension(useCompiledXaml);
|
|
|
|
|
var listView = page.listview;
|
2016-08-16 21:33:44 +03:00
|
|
|
|
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);
|
|
|
|
|
}
|
2017-04-20 21:53:13 +03:00
|
|
|
|
|
|
|
|
|
[TestCase(false)]
|
|
|
|
|
[TestCase(true)]
|
|
|
|
|
//https://bugzilla.xamarin.com/show_bug.cgi?id=55027
|
|
|
|
|
public void TypeExtensionSupportsNamespace(bool useCompiledXaml)
|
|
|
|
|
{
|
|
|
|
|
var page=new TypeExtension(useCompiledXaml);
|
|
|
|
|
var button = page.button0;
|
|
|
|
|
Assert.That(button.CommandParameter, Is.EqualTo(typeof(TypeExtension)));
|
|
|
|
|
}
|
2016-08-16 21:33:44 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|