summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2017-02-02 15:28:59 +0100
committerGitHub <noreply@github.com>2017-02-02 15:28:59 +0100
commit750b0346ccd5e06fc6ae7a7edaac9d745d8e1e65 (patch)
tree089ffffbbb96df8dbd04318f58924ce941169c3d /Xamarin.Forms.Xaml.UnitTests
parenteacbc1acf4cc2b95b98099d069e7bfa31c89f4f8 (diff)
downloadxamarin-forms-750b0346ccd5e06fc6ae7a7edaac9d745d8e1e65.tar.gz
xamarin-forms-750b0346ccd5e06fc6ae7a7edaac9d745d8e1e65.tar.bz2
xamarin-forms-750b0346ccd5e06fc6ae7a7edaac9d745d8e1e65.zip
[Xaml] do not set properties with private setters (#717)
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Issues/Bz44216.xaml9
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Issues/Bz44216.xaml.cs58
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj6
3 files changed, 73 insertions, 0 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz44216.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz44216.xaml
new file mode 100644
index 00000000..fd0cfb4d
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz44216.xaml
@@ -0,0 +1,9 @@
+<?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.Bz44216">
+ <ContentPage.Behaviors>
+ <local:Bz44216Behavior MinLengh="5" />
+ </ContentPage.Behaviors>
+</ContentPage>
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz44216.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz44216.xaml.cs
new file mode 100644
index 00000000..b6ad87b7
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz44216.xaml.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using NUnit.Framework;
+using Xamarin.Forms;
+using Xamarin.Forms.Core.UnitTests;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ public class Bz44216Behavior : Behavior<ContentPage>
+ {
+ static readonly BindableProperty MinLenghProperty = BindableProperty.Create("MinLengh", typeof(int), typeof(Bz44216Behavior), 1);
+
+ public int MinLengh {
+ get { return (int)base.GetValue(MinLenghProperty); }
+ private set { base.SetValue(MinLenghProperty, value > 0 ? value : 1); }
+ }
+ }
+
+ [XamlCompilation(XamlCompilationOptions.Skip)]
+ public partial class Bz44216 : ContentPage
+ {
+ public Bz44216()
+ {
+ InitializeComponent();
+ }
+
+ public Bz44216(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 DonSetValueOnPrivateBP(bool useCompiledXaml)
+ {
+ if (useCompiledXaml)
+ Assert.Throws(new XamlParseExceptionConstraint(7, 26, s => s.StartsWith("No property,", StringComparison.Ordinal)), () => MockCompiler.Compile(typeof(Bz44216)));
+ else
+ Assert.Throws(new XamlParseExceptionConstraint(7, 26, s=> s.StartsWith("Cannot assign property", StringComparison.Ordinal)), () => new Bz44216(useCompiledXaml));
+ }
+ }
+ }
+}
diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
index efbd9aab..4b3e5c86 100644
--- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
+++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
@@ -439,6 +439,9 @@
<Compile Include="Issues\Bz45891.xaml.cs">
<DependentUpon>Bz45891.xaml</DependentUpon>
</Compile>
+ <Compile Include="Issues\Bz44216.xaml.cs">
+ <DependentUpon>Bz44216.xaml</DependentUpon>
+ </Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
@@ -799,6 +802,9 @@
<EmbeddedResource Include="Issues\Bz45891.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
+ <EmbeddedResource Include="Issues\Bz44216.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />