diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2017-04-06 23:13:49 +0200 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2017-04-06 14:13:49 -0700 |
commit | 0ee636003b6d1083ea4caeed85ef3efbc815ed06 (patch) | |
tree | 861ba1a66b1b72be663719437ace87179cd3c03d /Xamarin.Forms.Xaml.UnitTests | |
parent | eb3db860e47da2974bddf6f0f959799f12e962c5 (diff) | |
download | xamarin-forms-0ee636003b6d1083ea4caeed85ef3efbc815ed06.tar.gz xamarin-forms-0ee636003b6d1083ea4caeed85ef3efbc815ed06.tar.bz2 xamarin-forms-0ee636003b6d1083ea4caeed85ef3efbc815ed06.zip |
Fix 54334 (#855)
* [C] unset the FromStyle flag on manual setting
* [C] Do not reset overriden values to default
* complete the fix
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests')
6 files changed, 195 insertions, 4 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml.cs index bd0fe48e..6353b537 100644 --- a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml.cs +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml.cs @@ -44,10 +44,10 @@ namespace Xamarin.Forms.Xaml.UnitTests Assert.NotNull (image0); cell0.BindingContext = new {IsSelected = true}; - Assert.AreEqual ("Remove.png", (image0.Source as FileImageSource).File); + Assert.AreEqual ("Remove.png", (image0.Source as FileImageSource)?.File); cell0.BindingContext = new {IsSelected = false}; - Assert.AreEqual ("Add.png", (image0.Source as FileImageSource).File); + Assert.AreEqual ("Add.png", (image0.Source as FileImageSource)?.File); var cell1 = template.CreateContent () as ViewCell; Assert.NotNull (cell1); @@ -55,10 +55,10 @@ namespace Xamarin.Forms.Xaml.UnitTests Assert.NotNull (image1); cell1.BindingContext = new {IsSelected = true}; - Assert.AreEqual ("Remove.png", (image1.Source as FileImageSource).File); + Assert.AreEqual ("Remove.png", (image1.Source as FileImageSource)?.File); cell1.BindingContext = new {IsSelected = false}; - Assert.AreEqual ("Add.png", (image1.Source as FileImageSource).File); + Assert.AreEqual ("Add.png", (image1.Source as FileImageSource)?.File); } } } diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz41048.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz41048.xaml new file mode 100644 index 00000000..81cf4aec --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz41048.xaml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ContentPage + xmlns="http://xamarin.com/schemas/2014/forms" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + x:Class="Xamarin.Forms.Xaml.UnitTests.Bz41048"> + <ContentPage.Resources> + <ResourceDictionary> + <!-- Standard Style --> + <Style x:Key="StandardLabelStyle" TargetType="Label"> + <Setter Property="TextColor" Value="Red"/> + <Setter Property="LineBreakMode" Value="TailTruncation"/> + </Style> + + <!-- Derived style with bold font --> + <Style x:Key="StandarBoldLabelStyle" TargetType="Label" BasedOn="{StaticResource StandardLabelStyle}"> + <Setter Property="FontAttributes" Value="Bold"/> + </Style> + + <!-- Use the StandardLabelStyle as implicit style for all labels --> + <Style TargetType="Label" BasedOn="{StaticResource StandardLabelStyle}"/> + </ResourceDictionary> + </ContentPage.Resources> + <Label x:Name="label0" + Style="{StaticResource StandarBoldLabelStyle}" + LineBreakMode="WordWrap" /> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz41048.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz41048.xaml.cs new file mode 100644 index 00000000..af3ee9a8 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz41048.xaml.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz41048 : ContentPage + { + public Bz41048() + { + InitializeComponent(); + } + + public Bz41048(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() + { + Application.Current = null; + Device.PlatformServices = null; + } + + [TestCase(true)] + [TestCase(false)] + public void StyleDoesNotOverrideValues(bool useCompiledXaml) + { + var layout = new Bz41048(useCompiledXaml); + var label = layout.label0; + Assert.That (label.TextColor, Is.EqualTo(Color.Red)); + Assert.That (label.FontAttributes, Is.EqualTo(FontAttributes.Bold)); + Assert.That (label.LineBreakMode, Is.EqualTo(LineBreakMode.WordWrap)); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz54334.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz54334.xaml new file mode 100644 index 00000000..e1f618b3 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz54334.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" x:Class="Xamarin.Forms.Xaml.UnitTests.Bz54334"> +<StackLayout Padding="10"> + <Label x:Name="label" HorizontalTextAlignment="Center" Text="I have a set textcolor, but in since pre-3 styles will override it.." TextColor="Black" /> + <Label x:Name="themedLabel" HorizontalTextAlignment="Center" Text="I dont have a set textcolor, syles can override me as much as they want" /> + <Button x:Name="btn" Text="Change Theme"></Button> + </StackLayout> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz54334.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz54334.xaml.cs new file mode 100644 index 00000000..7d8c4d4c --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz54334.xaml.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class Bz54334App : Application + { + bool daymode = true; + public Bz54334App(bool useCompiledXaml) + { + Resources = new ResourceDictionary{ + new Style(typeof(Label)) { + Setters = { + new Setter {Property = Label.TextColorProperty, Value=Color.Blue} + } + } + }; + MainPage = new Bz54334(useCompiledXaml); + MessagingCenter.Subscribe<ContentPage>(this, "ChangeTheme", (s) => { + ToggleTheme(); + }); + } + + void ToggleTheme() + { + Resources = daymode ? new ResourceDictionary{ + new Style(typeof(Label)) { + Setters = { + new Setter {Property = Label.TextColorProperty, Value=Color.Red} + } + } + } : new ResourceDictionary{ + new Style(typeof(Label)) { + Setters = { + new Setter {Property = Label.TextColorProperty, Value=Color.Blue} + } + } + }; + daymode = !daymode; + } + } + + public partial class Bz54334 : ContentPage + { + public Bz54334() + { + InitializeComponent(); + } + public Bz54334(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() + { + Application.Current = null; + Device.PlatformServices = null; + } + + [TestCase(true)] + [TestCase(false)] + public void Foo(bool useCompiledXaml) + { + var app = Application.Current = new Bz54334App(useCompiledXaml); + var page = app.MainPage as Bz54334; + var l0 = page.label; + var l1 = page.themedLabel; + + Assert.That(l0.TextColor, Is.EqualTo(Color.Black)); + Assert.That(l1.TextColor, Is.EqualTo(Color.Blue)); + + MessagingCenter.Send<ContentPage>(page, "ChangeTheme"); + Assert.That(l0.TextColor, Is.EqualTo(Color.Black)); + Assert.That(l1.TextColor, Is.EqualTo(Color.Red)); + + MessagingCenter.Send<ContentPage>(page, "ChangeTheme"); + Assert.That(l0.TextColor, Is.EqualTo(Color.Black)); + Assert.That(l1.TextColor, Is.EqualTo(Color.Blue)); + + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj index e807c1b3..7041001c 100644 --- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj +++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj @@ -461,6 +461,12 @@ <Compile Include="Issues\Bz53203.xaml.cs"> <DependentUpon>Bz53203.xaml</DependentUpon> </Compile> + <Compile Include="Issues\Bz54334.xaml.cs"> + <DependentUpon>Bz54334.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz41048.xaml.cs"> + <DependentUpon>Bz41048.xaml</DependentUpon> + </Compile> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" /> @@ -842,6 +848,12 @@ <EmbeddedResource Include="Issues\Bz53203.xaml"> <Generator>MSBuild:UpdateDesignTimeXaml</Generator> </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz54334.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz41048.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> </ItemGroup> <ItemGroup> <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> |