summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2017-04-07 09:48:17 +0200
committerGitHub <noreply@github.com>2017-04-07 09:48:17 +0200
commit5ea000a76d03a5328fe18761fbdf8b05e26a170b (patch)
tree128b2a0f74276be3081c3cada0716ad9bf64fa46 /Xamarin.Forms.Xaml.UnitTests
parent5f2796e160f99bad31c1b06a2d1f328b5ed02ba3 (diff)
downloadxamarin-forms-5ea000a76d03a5328fe18761fbdf8b05e26a170b.tar.gz
xamarin-forms-5ea000a76d03a5328fe18761fbdf8b05e26a170b.tar.bz2
xamarin-forms-5ea000a76d03a5328fe18761fbdf8b05e26a170b.zip
[Xaml] Set the TargetProperty on ServiceProvider (#847)
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Issues/Bz53275.xaml8
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Issues/Bz53275.xaml.cs57
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml.cs13
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj6
4 files changed, 84 insertions, 0 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz53275.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz53275.xaml
new file mode 100644
index 00000000..cab52a02
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz53275.xaml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests"
+ x:Class="Xamarin.Forms.Xaml.UnitTests.Bz53275"
+ ANonBindableProperty="{local:TargetProperty}">
+ <Label x:Name="label" Text="{local:TargetProperty}" />
+</ContentPage> \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz53275.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz53275.xaml.cs
new file mode 100644
index 00000000..ccef92dd
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz53275.xaml.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Reflection;
+using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ public class TargetPropertyExtension : IMarkupExtension
+ {
+ public object ProvideValue(IServiceProvider serviceProvider)
+ {
+ var targetProperty = (serviceProvider?.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget)?.TargetProperty;
+ return (targetProperty as BindableProperty)?.PropertyName ?? (targetProperty as PropertyInfo)?.Name;
+ }
+ }
+
+ public partial class Bz53275 : ContentPage
+ {
+ public Bz53275()
+ {
+ InitializeComponent();
+ }
+
+ public Bz53275(bool useCompiledXaml)
+ {
+ //this stub will be replaced at compile time
+ }
+
+ public string ANonBindableProperty { get; set; }
+
+ [TestFixture]
+ class Tests
+ {
+ [SetUp]
+ public void Setup()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Device.PlatformServices = null;
+ }
+
+ [TestCase(true)]
+ [TestCase(false)]
+ public void TargetPropertyIsSetOnMarkups(bool useCompiledXaml)
+ {
+ var page = new Bz53275(useCompiledXaml);
+ Assert.AreEqual("ANonBindableProperty", page.ANonBindableProperty);
+ var l0 = page.label;
+ Assert.AreEqual("Text", l0.Text);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml.cs
index 6f9ef80a..f1e0cd9a 100644
--- a/Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Windows.Input;
using Xamarin.Forms;
using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
@@ -46,6 +47,18 @@ namespace Xamarin.Forms.Xaml.UnitTests
[TestFixture]
public class Tests
{
+ [SetUp]
+ public void Setup()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Device.PlatformServices = null;
+ }
+
[TestCase(false)]
[TestCase(true)]
public void NestedMarkupExtensionInsideDataTemplate(bool useCompiledXaml)
diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
index 24d2bbde..a2c9d496 100644
--- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
+++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
@@ -470,6 +470,9 @@
<Compile Include="Issues\Bz41048.xaml.cs">
<DependentUpon>Bz41048.xaml</DependentUpon>
</Compile>
+ <Compile Include="Issues\Bz53275.xaml.cs">
+ <DependentUpon>Bz53275.xaml</DependentUpon>
+ </Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
@@ -860,6 +863,9 @@
<EmbeddedResource Include="Issues\Bz41048.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
+ <EmbeddedResource Include="Issues\Bz53275.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />