diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 13:02:25 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 16:13:41 -0700 |
commit | 17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch) | |
tree | b5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Xaml.UnitTests | |
download | xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2 xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip |
Initial import
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests')
183 files changed, 9688 insertions, 0 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/Compiled/FindByName.xaml b/Xamarin.Forms.Xaml.UnitTests/Compiled/FindByName.xaml new file mode 100644 index 00000000..c0b7afd7 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Compiled/FindByName.xaml @@ -0,0 +1,10 @@ +<?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.Compiled.FindByName" + x:Name="root"> + <StackLayout> + <Label Text="Foo" x:Name="label0"/> + </StackLayout> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/Compiled/FindByName.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Compiled/FindByName.xaml.cs new file mode 100644 index 00000000..0ec198e8 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Compiled/FindByName.xaml.cs @@ -0,0 +1,40 @@ +using NUnit.Framework; + +using Xamarin.Forms; + +namespace Xamarin.Forms.Xaml.UnitTests.Compiled +{ + public partial class FindByName : ContentPage + { + public FindByName () + { + InitializeComponent (); + } + + public FindByName (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class FindByNameTests + { + [TestCase (false)] + [TestCase (true)] + public void TestRootName (bool useCompiledXaml) + { + var page = new FindByName (useCompiledXaml); + Assert.AreSame (page, ((Forms.Internals.INameScope)page).FindByName ("root")); + Assert.AreSame (page, page.FindByName<FindByName> ("root")); + } + + [TestCase (false)] + [TestCase (true)] + public void TestName (bool useCompiledXaml) + { + var page = new FindByName (useCompiledXaml); + Assert.AreSame (page.label0, page.FindByName<Label> ("label0")); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Compiled/SetValue.xaml b/Xamarin.Forms.Xaml.UnitTests/Compiled/SetValue.xaml new file mode 100644 index 00000000..e60cd6db --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Compiled/SetValue.xaml @@ -0,0 +1,71 @@ +<?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.Compiled.SetValue"> + <ContentPage.Resources> + <ResourceDictionary> + <Color x:Key="purple">Purple</Color> + </ResourceDictionary> + </ContentPage.Resources> + <StackLayout> + <Label x:Name="label0" Text="Foo"/> + <Label x:Name="label1" Text="{Binding Path=labeltext}"/> + <Button x:Name="button0" Clicked="onButtonClicked" /> + <Image x:Name="image0" IsOpaque="true" /> + <Label x:Name="label2" Grid.Column="1"> + <Grid.Row>2</Grid.Row> + </Label> + <ContentView x:Name="contentview0"> + <ContentView.Content> + <Label x:Name="label3"/> + </ContentView.Content> + </ContentView> + <ContentView x:Name="contentview1"> + <Label x:Name="label4"/> + </ContentView> + <StackLayout x:Name="stack0"> + <StackLayout.Children> + <Label x:Name="label5"/> + <Label x:Name="label6"/> + </StackLayout.Children> + </StackLayout> + <StackLayout x:Name="stack1"> + <Label x:Name="label7"/> + <Label x:Name="label8"/> + </StackLayout> + <StackLayout x:Name="stack2"> + <StackLayout.Children> + <Label x:Name="label9"/> + </StackLayout.Children> + </StackLayout> + <StackLayout x:Name="stack3"> + <Label x:Name="label10"/> + </StackLayout> + <Label x:Name="label11" Text="{Binding labeltext}"/> + <ListView x:Name="listView"> + <ListView.ItemsSource> + <x:Array Type="{x:Type x:String}" x:Key="array"> + <x:String>foo</x:String> + <x:String>bar</x:String> + </x:Array> + </ListView.ItemsSource> + </ListView> + <Label x:Name="label12" TextColor="Red" /> + <Label x:Name="label13"> + <Label.TextColor> + <Color>Pink</Color> + </Label.TextColor> + </Label> + <Grid x:Name="grid0"> + <Grid.RowDefinitions> + <RowDefinition/> + <RowDefinition/> + </Grid.RowDefinitions> + <Grid.ColumnDefinitions> + <ColumnDefinition/> + </Grid.ColumnDefinitions> + </Grid> + <Label x:Name="label14" AbsoluteLayout.LayoutFlags="PositionProportional,WidthProportional" /> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Compiled/SetValue.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Compiled/SetValue.xaml.cs new file mode 100644 index 00000000..f835d59f --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Compiled/SetValue.xaml.cs @@ -0,0 +1,191 @@ +using System; +using System.Linq; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests.Compiled +{ + public partial class SetValue : ContentPage + { + public SetValue () + { + InitializeComponent (); + } + + public SetValue (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + bool fired; + void onButtonClicked (object sender, EventArgs args) + { + fired = true; + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void SetValueToBP (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.AreEqual ("Foo", page.label0.Text); + } + + [TestCase (false)] + [TestCase (true)] + public void SetBindingToBP (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.AreEqual (Label.TextProperty.DefaultValue, page.label1.Text); + + page.label1.BindingContext = new {labeltext="Foo"}; + Assert.AreEqual ("Foo", page.label1.Text); + } + + [TestCase (false)] + [TestCase (true)] + public void SetBindingWithImplicitPath (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.AreEqual (Label.TextProperty.DefaultValue, page.label11.Text); + + page.label11.BindingContext = new {labeltext="Foo"}; + Assert.AreEqual ("Foo", page.label11.Text); + } + + [TestCase (false)] + [TestCase (true)] + public void SetEvent (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.False (page.fired); + (page.button0 as IButtonController).SendClicked (); + Assert.True (page.fired); + } + + [TestCase (false)] + [TestCase (true)] + public void SetBoolValue (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.True (page.image0.IsOpaque); + } + + //TODO test all value conversions + + [TestCase (false)] + [TestCase (true)] + public void SetAttachedBP (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.AreEqual (1, Grid.GetColumn (page.label2)); + Assert.AreEqual (2, Grid.GetRow (page.label2)); + } + + [TestCase (false)] + [TestCase (true)] + public void SetContent (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.AreSame (page.label3, page.contentview0.Content); + } + + [TestCase (false)] + [TestCase (true)] + public void SetImplicitContent (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.AreSame (page.label4, page.contentview1.Content); + } + + [TestCase (false)] + [TestCase (true)] + public void SetCollectionContent (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.True (page.stack0.Children.Contains(page.label5)); + Assert.True (page.stack0.Children.Contains(page.label6)); + } + + [TestCase (false)] + [TestCase (true)] + public void SetImplicitCollectionContent (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.True (page.stack1.Children.Contains(page.label7)); + Assert.True (page.stack1.Children.Contains(page.label8)); + } + + [TestCase (false)] + [TestCase (true)] + public void SetSingleCollectionContent (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.True (page.stack2.Children.Contains(page.label9)); + } + + [TestCase (false)] + [TestCase (true)] + public void SetImplicitSingleCollectionContent (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.True (page.stack3.Children.Contains(page.label10)); + } + + [TestCase (false)] + [TestCase (true)] + public void SetPropertyDefinedOnGenericType (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.AreEqual (2, page.listView.ItemsSource.Cast<object>().Count ()); + } + + [TestCase (false)] + [TestCase (true)] + public void SetConvertibleProperties (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.AreEqual (Color.Red, page.label12.TextColor); + } + + [TestCase (false)] + [TestCase (true)] + public void SetValueTypeProperties (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.AreEqual (Color.Pink, page.label13.TextColor); + } + + [TestCase (false)] + [TestCase (true)] + public void CreateValueTypes (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.AreEqual (Color.Purple, page.Resources ["purple"]); + } + + [TestCase (false)] + [TestCase (true)] + public void DefCollections (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.AreEqual (2, page.grid0.RowDefinitions.Count); + Assert.AreEqual (1, page.grid0.ColumnDefinitions.Count); + } + + [TestCase (false)] + [TestCase (true)] + public void FlagsAreApplied (bool useCompiledXaml) + { + var page = new SetValue (useCompiledXaml); + Assert.AreEqual (AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional, AbsoluteLayout.GetLayoutFlags (page.label14)); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/ConstraintExpression.xaml b/Xamarin.Forms.Xaml.UnitTests/ConstraintExpression.xaml new file mode 100644 index 00000000..0e71a7a0 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/ConstraintExpression.xaml @@ -0,0 +1,15 @@ +<?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.ConstraintExpression" > + <RelativeLayout x:Name="relativeLayout"> + <Label x:Name="constantConstraint" + RelativeLayout.WidthConstraint="{ConstraintExpression Type=Constant, Constant=42}" /> + <Label x:Name="constraintRelativeToParent" + RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Constant=2, Factor=.5, Property=Width}" /> + <Label x:Name="foo" /> + <Label x:Name="constraintRelativeToView" + RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, Constant=2, Factor=.5, Property=Width, ElementName=foo}" /> + </RelativeLayout> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/ConstraintExpression.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/ConstraintExpression.xaml.cs new file mode 100644 index 00000000..3786ccb5 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/ConstraintExpression.xaml.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class ConstraintExpression : ContentPage + { + public ConstraintExpression () + { + InitializeComponent (); + } + + public ConstraintExpression (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void Setup () + { + Device.PlatformServices = new MockPlatformServices (); + } + + [TestCase (false)] + [TestCase (true)] + public void ConstantConstraint (bool useCompiledXaml) + { + var layout = new ConstraintExpression (useCompiledXaml); + var label = layout.constantConstraint; + var constraint = RelativeLayout.GetWidthConstraint (label); + Assert.NotNull (constraint); + Assert.AreEqual (42, constraint.Compute (null)); + } + + [TestCase (false)] + [TestCase (true)] + public void ConstraintRelativeToParent (bool useCompiledXaml) + { + var layout = new ConstraintExpression (useCompiledXaml); + layout.relativeLayout.Layout (new Rectangle (0, 0, 200, 200)); + var label = layout.constraintRelativeToParent; + var constraint = RelativeLayout.GetWidthConstraint (label); + Assert.NotNull (constraint); + Assert.AreEqual (102, constraint.Compute (layout.relativeLayout)); + } + + [TestCase (false)] + [TestCase (true)] + public void ContraintRelativeToView (bool useCompiledXaml) + { + var layout = new ConstraintExpression (useCompiledXaml) { + IsPlatformEnabled = true + }; + layout.relativeLayout.Layout (new Rectangle (0, 0, 200, 100)); + layout.foo.Layout (new Rectangle (5, 5, 190, 25)); + + var label = layout.constraintRelativeToView; + var constraint = RelativeLayout.GetWidthConstraint (label); + Assert.NotNull (constraint); + Assert.AreEqual (97, constraint.Compute (layout.relativeLayout)); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/CustomXamlView.xaml b/Xamarin.Forms.Xaml.UnitTests/CustomXamlView.xaml new file mode 100644 index 00000000..67d92bef --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/CustomXamlView.xaml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<ContentView + xmlns="http://xamarin.com/schemas/2014/forms" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + x:Class="Xamarin.Forms.Xaml.UnitTests.CustomXamlView"> + <Label x:Name="label0" Text="foobar"/> +</ContentView>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/CustomXamlView.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/CustomXamlView.xaml.cs new file mode 100644 index 00000000..6b0c862d --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/CustomXamlView.xaml.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using Xamarin.Forms; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class CustomXamlView : ContentView + { + public CustomXamlView () + { + InitializeComponent (); + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/DataTemplate.xaml b/Xamarin.Forms.Xaml.UnitTests/DataTemplate.xaml new file mode 100644 index 00000000..d1c233b7 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/DataTemplate.xaml @@ -0,0 +1,46 @@ +<?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.DataTemplate" + xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests"> + <ContentPage.Resources> + <ResourceDictionary> + <DataTemplate x:Key="celltemplate"> + <TextCell Text="{Binding}"/> + </DataTemplate> + <local:ReverseConverter x:Key="reverseConverter"/> + </ResourceDictionary> + </ContentPage.Resources> + <StackLayout> + <ListView x:Name="emptyTextCell"> + <ListView.ItemTemplate> + <DataTemplate> + <TextCell /> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> + <ListView x:Name="textCell"> + <ListView.ItemTemplate> + <DataTemplate> + <TextCell Text="{Binding}"/> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> + <ListView x:Name="fromResource" ItemTemplate="{StaticResource celltemplate}" /> + <ListView x:Name="textCellAccessResource"> + <ListView.ItemTemplate> + <DataTemplate> + <TextCell Text="{Binding Path=., Converter={StaticResource reverseConverter}}"/> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> + <ListView x:Name="viewCellAccessResource"> + <ListView.ItemTemplate> + <DataTemplate> + <ViewCell><Label Text="{Binding Path=., Converter={StaticResource reverseConverter}}"/></ViewCell> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/DataTemplate.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/DataTemplate.xaml.cs new file mode 100644 index 00000000..cfc5d1a1 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/DataTemplate.xaml.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class DataTemplate : ContentPage + { + public DataTemplate () + { + InitializeComponent (); + } + + public DataTemplate (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void EmptyTextCell (bool useCompiledXaml) + { + var layout = new DataTemplate (useCompiledXaml); + + var cell0 = layout.emptyTextCell.ItemTemplate.CreateContent (); + Assert.NotNull (cell0); + Assert.That (cell0, Is.TypeOf<TextCell> ()); + + var cell1 = layout.emptyTextCell.ItemTemplate.CreateContent (); + Assert.NotNull (cell1); + Assert.That (cell1, Is.TypeOf<TextCell> ()); + + Assert.AreNotSame (cell0, cell1); + } + + [TestCase (false)] + [TestCase (true)] + public void TextCell (bool useCompiledXaml) + { + var layout = new DataTemplate (useCompiledXaml); + var cell0 = layout.textCell.ItemTemplate.CreateContent (); + Assert.NotNull (cell0); + Assert.That (cell0, Is.TypeOf<TextCell> ()); + ((TextCell)cell0).BindingContext = "Foo"; + Assert.AreEqual ("Foo", ((TextCell)cell0).Text); + + var cell1 = layout.textCell.ItemTemplate.CreateContent (); + Assert.NotNull (cell1); + Assert.That (cell1, Is.TypeOf<TextCell> ()); + ((TextCell)cell1).BindingContext = "Bar"; + Assert.AreEqual ("Bar", ((TextCell)cell1).Text); + + Assert.AreNotSame (cell0, cell1); + } + + [TestCase (false)] + [TestCase (true)] + public void FromResource (bool useCompiledXaml) + { + var layout = new DataTemplate (useCompiledXaml); + var cell0 = layout.fromResource.ItemTemplate.CreateContent (); + Assert.NotNull (cell0); + Assert.That (cell0, Is.TypeOf<TextCell> ()); + ((TextCell)cell0).BindingContext = "Foo"; + Assert.AreEqual ("Foo", ((TextCell)cell0).Text); + + var cell1 = layout.fromResource.ItemTemplate.CreateContent (); + Assert.NotNull (cell1); + Assert.That (cell1, Is.TypeOf<TextCell> ()); + ((TextCell)cell1).BindingContext = "Bar"; + Assert.AreEqual ("Bar", ((TextCell)cell1).Text); + + Assert.AreNotSame (cell0, cell1); + } + + [TestCase (false)] + [TestCase (true)] + public void TextCellAccessResources (bool useCompiledXaml) + { + var layout = new DataTemplate (useCompiledXaml); + var cell0 = layout.textCellAccessResource.ItemTemplate.CreateContent (); + Assert.NotNull (cell0); + Assert.That (cell0, Is.TypeOf<TextCell> ()); + ((TextCell)cell0).BindingContext = "Foo"; + Assert.AreEqual ("ooF", ((TextCell)cell0).Text); + + var cell1 = layout.textCellAccessResource.ItemTemplate.CreateContent (); + Assert.NotNull (cell1); + Assert.That (cell1, Is.TypeOf<TextCell> ()); + ((TextCell)cell1).BindingContext = "Bar"; + Assert.AreEqual ("raB", ((TextCell)cell1).Text); + + Assert.AreNotSame (cell0, cell1); + } + + [TestCase (false)] + [TestCase (true)] + public void ViewCellAccessResources (bool useCompiledXaml) + { + var layout = new DataTemplate (useCompiledXaml); + var cell0 = layout.viewCellAccessResource.ItemTemplate.CreateContent (); + Assert.NotNull (cell0); + Assert.That (cell0, Is.TypeOf<ViewCell> ()); + ((ViewCell)cell0).BindingContext = "Foo"; + Assert.AreEqual ("ooF", ((Label)((ViewCell)cell0).View).Text); + + var cell1 = layout.viewCellAccessResource.ItemTemplate.CreateContent (); + Assert.NotNull (cell1); + Assert.That (cell1, Is.TypeOf<ViewCell> ()); + ((ViewCell)cell1).BindingContext = "Bar"; + Assert.AreEqual ("raB", ((Label)((ViewCell)cell1).View).Text); + + Assert.AreNotSame (cell0, cell1); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/DummyBuildEngine.cs b/Xamarin.Forms.Xaml.UnitTests/DummyBuildEngine.cs new file mode 100644 index 00000000..df76e13a --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/DummyBuildEngine.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections; +using Microsoft.Build.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class DummyBuildEngine : IBuildEngine + { + public void LogErrorEvent (BuildErrorEventArgs e) + { + } + + public void LogWarningEvent (BuildWarningEventArgs e) + { + } + + public void LogMessageEvent (BuildMessageEventArgs e) + { + } + + public void LogCustomEvent (CustomBuildEventArgs e) + { + } + + public bool BuildProjectFile (string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs) + { + return false; + } + + public bool ContinueOnError { + get { return false; } + } + + public int LineNumberOfTaskNode { + get { return 1; } + } + + public int ColumnNumberOfTaskNode { + get { return 1; } + } + + public string ProjectFileOfTaskNode { + get { return String.Empty; } + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/DynamicResource.xaml b/Xamarin.Forms.Xaml.UnitTests/DynamicResource.xaml new file mode 100644 index 00000000..3a90c26a --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/DynamicResource.xaml @@ -0,0 +1,6 @@ +<?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.DynamicResource"> + <Label Text="{DynamicResource FooBar}" x:Name="label0" /> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/DynamicResource.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/DynamicResource.xaml.cs new file mode 100644 index 00000000..703313c4 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/DynamicResource.xaml.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; + +using NUnit.Framework; + +using Xamarin.Forms; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class DynamicResource : ContentPage + { + public DynamicResource () + { + InitializeComponent (); + } + + public DynamicResource (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void TestDynamicResources (bool useCompiledXaml) + { + var layout = new DynamicResource (useCompiledXaml); + var label = layout.label0; + + Assert.Null (label.Text); + + layout.Resources = new ResourceDictionary { + {"FooBar", "FOOBAR"}, + }; + Assert.AreEqual ("FOOBAR", label.Text); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/EventsConnection.xaml b/Xamarin.Forms.Xaml.UnitTests/EventsConnection.xaml new file mode 100644 index 00000000..f9032089 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/EventsConnection.xaml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<local:BaseForEvents 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.EventsConnection"> + <StackLayout> + <local:ElementWithEvent x:Name="elementWithEvent" + Clicked="HandleClicked" /> + <local:ElementWithGenericEvent x:Name="elementWithGenericEvent" + Clicked="HandleGenericClicked"/> + <local:ElementWithEvent x:Name="eventHandlerOnBase" + Clicked="HandleClickedOnBase" /> + <local:ElementWithEvent x:Name="elementwithAsyncprivateHandler" + Clicked="HandleClickedPrivateAsync" /> + </StackLayout> +</local:BaseForEvents>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/EventsConnection.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/EventsConnection.xaml.cs new file mode 100644 index 00000000..7bab5676 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/EventsConnection.xaml.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class BaseForEvents : ContentView + { + protected int baseClicked; + protected void HandleClickedOnBase (object sender, EventArgs e) + { + baseClicked++; + } + } + + public class ElementWithEvent : ContentView + { + public event EventHandler Clicked; + + public void SendClicked () + { + var eh = Clicked; + if (eh != null) + eh (this, EventArgs.Empty); + } + } + + public class ElementWithGenericEvent : ContentView + { + public event EventHandler<ItemTappedEventArgs> Clicked; + + public void SendClicked () + { + var eh = Clicked; + if (eh != null) + eh (this, new ItemTappedEventArgs ("foo", "bar")); + } + } + + public partial class EventsConnection : BaseForEvents + { + public EventsConnection () + { + InitializeComponent (); + } + + public EventsConnection (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + int clicked; + public void HandleClicked (object sender, EventArgs e) + { + clicked++; + } + + int genericClicked; + public void HandleGenericClicked (object sender, ItemTappedEventArgs e) + { + genericClicked++; + } + + int asyncPrivateClicked; + async void HandleClickedPrivateAsync (object sender, EventArgs e) + { + asyncPrivateClicked++; + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void TestClicked (bool useCompiledXaml) + { + var layout = new EventsConnection (useCompiledXaml); + Assert.AreEqual (0, layout.clicked); + layout.elementWithEvent.SendClicked (); + Assert.AreEqual (1, layout.clicked); + } + + [TestCase (false)] + [TestCase (true)] + public void TestGenericClicked (bool useCompiledXaml) + { + var layout = new EventsConnection (useCompiledXaml); + Assert.AreEqual (0, layout.genericClicked); + layout.elementWithGenericEvent.SendClicked (); + Assert.AreEqual (1, layout.genericClicked); + } + + [TestCase (false)] + [TestCase (true)] + public void TestHandlerOnBase (bool useCompiledXaml) + { + var layout = new EventsConnection (useCompiledXaml); + Assert.AreEqual (0, layout.baseClicked); + layout.eventHandlerOnBase.SendClicked (); + Assert.AreEqual (1, layout.baseClicked); + } + + [TestCase (false)] + [TestCase (true)] + public void TestAsyncPrivateHandler (bool useCompiledXaml) + { + var layout = new EventsConnection (useCompiledXaml); + Assert.AreEqual (0, layout.asyncPrivateClicked); + layout.elementwithAsyncprivateHandler.SendClicked (); + Assert.AreEqual (1, layout.asyncPrivateClicked); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/FactoryMethodTests.cs b/Xamarin.Forms.Xaml.UnitTests/FactoryMethodTests.cs new file mode 100644 index 00000000..d6ee1886 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/FactoryMethodTests.cs @@ -0,0 +1,53 @@ +using System; +using NUnit.Framework; + +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class FactoryMethodTests : BaseTestFixture + { + [Test] + public void ThrowOnMissingCtor () + { + var xaml = @" + <local:MockView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" > + <local:MockView.Content> + <local:MockFactory> + <x:Arguments> + <x:Object/> + <x:String>bar</x:String> + <x:Int32>42</x:Int32> + </x:Arguments> + </local:MockFactory> + </local:MockView.Content> + </local:MockView>"; + Assert.Throws<MissingMethodException> (()=>new MockView ().LoadFromXaml (xaml)); + } + + [Test] + public void ThrowOnMissingMethod () + { + var xaml = @" + <local:MockView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" > + <local:MockView.Content> + <local:MockFactory x:FactoryMethod=""Factory""> + <x:Arguments> + <x:Object/> + <x:String>bar</x:String> + <x:Int32>42</x:Int32> + </x:Arguments> + </local:MockFactory> + </local:MockView.Content> + </local:MockView>"; + Assert.Throws<MissingMemberException> (()=>new MockView ().LoadFromXaml (xaml)); + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml b/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml new file mode 100644 index 00000000..a90a0378 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml @@ -0,0 +1,58 @@ +<?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.FactoryMethods"> + <StackLayout> + <local:MockView x:Name="v0"> + <local:MockView.Content> + <local:MockFactory/> + </local:MockView.Content> + </local:MockView> + <local:MockView x:Name="v1"> + <local:MockView.Content> + <local:MockFactory> + <x:Arguments> + <x:String>foo</x:String> + <x:String>bar</x:String> + </x:Arguments> + </local:MockFactory> + </local:MockView.Content> + </local:MockView> + <local:MockView x:Name="v2"> + <local:MockView.Content> + <local:MockFactory> + <x:Arguments> + <x:Int32>42</x:Int32> + </x:Arguments> + </local:MockFactory> + </local:MockView.Content> + </local:MockView> + <local:MockView x:Name="v3"> + <local:MockView.Content> + <local:MockFactory x:FactoryMethod="ParameterlessFactory"> + </local:MockFactory> + </local:MockView.Content> + </local:MockView> + <local:MockView x:Name="v4"> + <local:MockView.Content> + <local:MockFactory x:FactoryMethod="Factory"> + <x:Arguments> + <x:String>foo</x:String> + <x:Int32>42</x:Int32> + </x:Arguments> + </local:MockFactory> + </local:MockView.Content> + </local:MockView> + <local:MockView x:Name="v5"> + <local:MockView.Content> + <local:MockFactory x:FactoryMethod="Factory"> + <x:Arguments> + <x:Int32>42</x:Int32> + <x:String>foo</x:String> + </x:Arguments> + </local:MockFactory> + </local:MockView.Content> + </local:MockView> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml.cs new file mode 100644 index 00000000..42f359b7 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/FactoryMethods.xaml.cs @@ -0,0 +1,115 @@ +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class MockView : View + { + public MockFactory Content { get; set; } + } + + public class MockFactory + { + public string Content { get; set; } + public MockFactory () + { + Content = "default ctor"; + } + + public MockFactory (string arg0, string arg1) + { + Content = "alternate ctor " + arg0 + arg1; + } + + public MockFactory (int arg) + { + Content = "int ctor " + arg.ToString (); + } + + public static MockFactory ParameterlessFactory () + { + return new MockFactory { + Content = "parameterless factory", + }; + } + + public static MockFactory Factory (string arg0, int arg1) + { + return new MockFactory { + Content = "factory " + arg0 + arg1, + }; + } + + public static MockFactory Factory (int arg0, string arg1) + { + return new MockFactory { + Content = "factory " + arg0 + arg1, + }; + } + } + + public partial class FactoryMethods : ContentPage + { + public FactoryMethods () + { + InitializeComponent (); + } + + public FactoryMethods (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void TestDefaultCtor (bool useCompiledXaml) + { + var layout = new FactoryMethods (useCompiledXaml); + Assert.AreEqual ("default ctor", layout.v0.Content.Content); + } + + [TestCase (false)] + [TestCase (true)] + public void TestStringCtor (bool useCompiledXaml) + { + var layout = new FactoryMethods (useCompiledXaml); + Assert.AreEqual ("alternate ctor foobar", layout.v1.Content.Content); + } + + [TestCase (false)] + [TestCase (true)] + public void TestIntCtor (bool useCompiledXaml) + { + var layout = new FactoryMethods (useCompiledXaml); + Assert.AreEqual ("int ctor 42", layout.v2.Content.Content); + } + + [TestCase (false)] + [TestCase (true)] + public void TestArgumentlessFactoryMethod (bool useCompiledXaml) + { + var layout = new FactoryMethods (useCompiledXaml); + Assert.AreEqual ("parameterless factory", layout.v3.Content.Content); + } + + [TestCase (false)] + [TestCase (true)] + public void TestFactoryMethod (bool useCompiledXaml) + { + var layout = new FactoryMethods (useCompiledXaml); + Assert.AreEqual ("factory foo42", layout.v4.Content.Content); + } + + [TestCase (false)] + [TestCase (true)] + public void TestFactoryMethodParametersOrder (bool useCompiledXaml) + { + var layout = new FactoryMethods (useCompiledXaml); + Assert.AreEqual ("factory 42foo", layout.v5.Content.Content); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/FontConverterTests.cs b/Xamarin.Forms.Xaml.UnitTests/FontConverterTests.cs new file mode 100644 index 00000000..fc5e25b0 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/FontConverterTests.cs @@ -0,0 +1,27 @@ +using NUnit.Framework; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class FontConverterTests : BaseTestFixture + { + [TestCase ("Bold", Forms.FontAttributes.Bold)] + [TestCase ("Italic", Forms.FontAttributes.Italic)] + [TestCase ("Bold, Italic", Forms.FontAttributes.Bold | Forms.FontAttributes.Italic)] + public void FontAttributes (string attributeString, FontAttributes result) + { + var xaml = @" + <Label + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" FontAttributes=""" + result + @""" />"; + + Device.PlatformServices = new MockPlatformServices (); + + var label = new Label ().LoadFromXaml (xaml); + + Assert.AreEqual (result, label.FontAttributes); + Assert.AreEqual (result, label.Font.FontAttributes); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/GenericCollections.xaml b/Xamarin.Forms.Xaml.UnitTests/GenericCollections.xaml new file mode 100644 index 00000000..79a38df9 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/GenericCollections.xaml @@ -0,0 +1,13 @@ +<?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.GenericCollections"> + <Label x:Name="label0"> + <local:AttachedBP.AttachedBP> + <local:GenericCollection> + <x:String>Foo</x:String> + </local:GenericCollection> + </local:AttachedBP.AttachedBP> + </Label> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/GenericCollections.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/GenericCollections.xaml.cs new file mode 100644 index 00000000..95c057b0 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/GenericCollections.xaml.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using System.Collections.ObjectModel; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class AttachedBP + { + public static readonly BindableProperty AttachedBPProperty = BindableProperty.CreateAttached ( + "AttachedBP", + typeof(GenericCollection), + typeof(AttachedBP), + null); + } + + public class GenericCollection : ObservableCollection<object> + { + } + + public partial class GenericCollections : ContentPage + { + public GenericCollections () + { + InitializeComponent (); + } + + public GenericCollections (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void SupportsCrookedGenericScenarios (bool useCompiledXaml) + { + var p = new GenericCollections (); + Assert.AreEqual ("Foo", (p.label0.GetValue (AttachedBP.AttachedBPProperty) as GenericCollection) [0]); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/GenericsTests.xaml b/Xamarin.Forms.Xaml.UnitTests/GenericsTests.xaml new file mode 100644 index 00000000..da224282 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/GenericsTests.xaml @@ -0,0 +1,21 @@ +<?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:sys="clr-namespace:System;assembly=mscorlib" + xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib" + xmlns:scgs="clr-namespace:System.Collections.Generic;assembly=System" + x:Class="Xamarin.Forms.Xaml.UnitTests.GenericsTests"> + <ContentPage.Resources> + <ResourceDictionary> + <scg:List x:TypeArguments="Button" x:Key="genericButtonList"> + <Button /> + <Button /> + </scg:List> + <scg:List x:TypeArguments="Button" x:Key="genericButtonList1" x:Name="myList"/> + <scg:List x:TypeArguments="sys:String" x:Key="list"/> + <scg:Dictionary x:TypeArguments="sys:String, sys:String" x:Key="dict"/> + <scgs:Queue x:TypeArguments="scg:KeyValuePair(sys:String,sys:String)" x:Key="queue"/> + <scg:List x:TypeArguments="x:String" x:Key="stringList"/> + </ResourceDictionary> + </ContentPage.Resources> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/GenericsTests.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/GenericsTests.xaml.cs new file mode 100644 index 00000000..5a62b9fa --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/GenericsTests.xaml.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class GenericsTests : ContentPage + { + public GenericsTests () + { + InitializeComponent (); + } + + public GenericsTests (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [Test] + public void NoGenericsOnXaml2006 () + { + var xaml = @" + <ContentPage + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:scg=""clr-namespace:System.Collections.Generic;assembly=mscorlib""> + <ContentPage.Resources> + <ResourceDictionary> + <scg:List x:TypeArguments=""Button"" x:Key=""genericList""/> + </ResourceDictionary> + </ContentPage.Resources> + </ContentPage>"; + Assert.Throws (new XamlParseExceptionConstraint (8, 9), () => new ContentPage ().LoadFromXaml (xaml)); + } + + [TestCase (false)] + [TestCase (true)] + public void GenericSupportOnXaml2009 (bool useCompiledXaml) + { + var layout = new GenericsTests (useCompiledXaml); + Assert.True (layout.Resources.ContainsKey ("genericButtonList")); + var list = layout.Resources ["genericButtonList"]; + Assert.That (list, Is.TypeOf<List<Button>> ()); + Assert.AreEqual (2, ((List<Button>)list).Count); + } + + [TestCase (false)] + [TestCase (true)] + public void FindGenericByName (bool useCompiledXaml) + { + var layout = new GenericsTests (useCompiledXaml); + var list = layout.FindByName<List<Button>> ("myList"); + Assert.NotNull (list); + } + + [TestCase (false)] + [TestCase (true)] + public void TestGenericParsing (bool useCompiledXaml) + { + var layout = new GenericsTests (useCompiledXaml); + var list = layout.Resources ["list"]; + Assert.NotNull (list); + Assert.That (list, Is.TypeOf<List<String>> ()); + + var dict = layout.Resources ["dict"]; + Assert.NotNull (dict); + Assert.That (dict, Is.TypeOf<Dictionary<string,string>> ()); + + var queue = layout.Resources ["queue"]; + Assert.NotNull (dict); + Assert.That (queue, Is.TypeOf<Queue<KeyValuePair<string,string>>> ()); + } + + [TestCase (false)] + [TestCase (true)] + public void TestXamlPrimitives (bool useCompiledXaml) + { + var layout = new GenericsTests (useCompiledXaml); + var list = layout.Resources ["stringList"]; + Assert.NotNull (list); + Assert.That (list, Is.TypeOf<List<String>> ()); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/ImplicitConversions.xaml b/Xamarin.Forms.Xaml.UnitTests/ImplicitConversions.xaml new file mode 100644 index 00000000..38d20e3e --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/ImplicitConversions.xaml @@ -0,0 +1,21 @@ +<?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.ImplicitConversions"> + <StackLayout> + <DatePicker x:Name="datetime0" Date="2015-01-16"/> + <DatePicker x:Name="datetime1"> + <DatePicker.Date>2015-01-16</DatePicker.Date> + </DatePicker> + <Label x:Name="label0" Text="foobar"/> + <Label x:Name="label1"> + <Label.Text> + foobar + </Label.Text> + </Label> + <Label x:Name="label2"> + foobar + </Label> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/ImplicitConversions.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/ImplicitConversions.xaml.cs new file mode 100644 index 00000000..5eae0299 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/ImplicitConversions.xaml.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class ImplicitConversions : ContentPage + { + public ImplicitConversions () + { + InitializeComponent (); + } + + [TestFixture] + public class Tests + { + [Test] + public void Datetime () + { + var layout = new ImplicitConversions (); + + Assert.AreEqual (new DateTime (2015, 01, 16), layout.datetime0.Date); + Assert.AreEqual (new DateTime (2015, 01, 16), layout.datetime1.Date); + } + + [Test] + public void String () + { + var layout = new ImplicitConversions (); + + Assert.AreEqual ("foobar", layout.label0.Text); + Assert.AreEqual ("foobar", layout.label1.Text); + + //Issue #2122, implicit content property not trimmed + Assert.AreEqual ("foobar", layout.label2.Text); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/IsCompiledDefault.xaml b/Xamarin.Forms.Xaml.UnitTests/IsCompiledDefault.xaml new file mode 100644 index 00000000..15033daf --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/IsCompiledDefault.xaml @@ -0,0 +1,5 @@ +<?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.IsCompiledDefault"> + <ContentPage.Content> + </ContentPage.Content> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/IsCompiledDefault.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/IsCompiledDefault.xaml.cs new file mode 100644 index 00000000..e07c00b1 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/IsCompiledDefault.xaml.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class IsCompiledDefault : ContentPage + { + public IsCompiledDefault () + { + InitializeComponent (); + } + + public IsCompiledDefault (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void IsCompiled (bool useCompiledXaml) + { + var layout = new IsCompiledDefault (useCompiledXaml); + Assert.AreEqual (true, typeof (IsCompiledDefault).IsCompiled ()); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/IsCompiledSkip.xaml b/Xamarin.Forms.Xaml.UnitTests/IsCompiledSkip.xaml new file mode 100644 index 00000000..05a2d9fc --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/IsCompiledSkip.xaml @@ -0,0 +1,5 @@ +<?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.IsCompiledSkip"> + <ContentPage.Content> + </ContentPage.Content> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/IsCompiledSkip.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/IsCompiledSkip.xaml.cs new file mode 100644 index 00000000..ca5b7cbd --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/IsCompiledSkip.xaml.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using Xamarin.Forms; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [XamlCompilation (XamlCompilationOptions.Skip)] + public partial class IsCompiledSkip : ContentPage + { + public IsCompiledSkip () + { + InitializeComponent (); + } + + public IsCompiledSkip (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void IsCompiled (bool useCompiledXaml) + { + var layout = new IsCompiledDefault (useCompiledXaml); + Assert.AreEqual (false, typeof (IsCompiledSkip).IsCompiled ()); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/BPNotResolvedOnSubClass.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/BPNotResolvedOnSubClass.xaml new file mode 100644 index 00000000..ea5204a3 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/BPNotResolvedOnSubClass.xaml @@ -0,0 +1,15 @@ +<?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.BPNotResolvedOnSubClass"> + <ContentPage.Resources> + <ResourceDictionary> + <Style TargetType="Button"> + <Style.Setters> + <Setter Property="local:BPNotResolvedOnSubClass.ShadowColor" Value="#dddddd" /> + </Style.Setters> + </Style> + </ResourceDictionary> + </ContentPage.Resources> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/BPNotResolvedOnSubClass.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/BPNotResolvedOnSubClass.xaml.cs new file mode 100644 index 00000000..65bb73f1 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/BPNotResolvedOnSubClass.xaml.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class BPNotResolvedOnSubClass : ContentPage + { + public static readonly BindableProperty ShadowColorProperty = + BindableProperty.CreateAttached ("ShadowColor", typeof (Color), typeof (BPNotResolvedOnSubClass), Color.Default); + + public static Color GetShadowColor (Element bindable) // Change to Element instead of BindableObject o make fail + { + return (Color)bindable.GetValue (ShadowColorProperty); + } + + public BPNotResolvedOnSubClass () + { + InitializeComponent (); + } + + public BPNotResolvedOnSubClass (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void CorrectlyResolveBPOnSubClasses (bool useCompiledXaml) + { + var layout = new BPNotResolvedOnSubClass (useCompiledXaml); + var style = (Style)layout.Resources["Xamarin.Forms.Button"]; + Assert.NotNull (style); + + var button = new Button (); + button.Style = style; + + Assert.AreEqual (Color.FromHex ("#dddddd"), button.GetValue (ShadowColorProperty)); + } + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz24485.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz24485.xaml new file mode 100644 index 00000000..ed7ec074 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz24485.xaml @@ -0,0 +1,15 @@ +<?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.Bz24485"> + <ContentPage.Resources> + <ResourceDictionary> + <local:Bz24485Converter x:Key="ToBasicItem" /> + </ResourceDictionary> + </ContentPage.Resources> + <Grid BindingContext="{Binding Data1, Converter={StaticResource ToBasicItem}"> + <Label Text="{Binding FormattedDate}" /> + <Label Text="{Binding Date}" /> + </Grid> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz24485.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz24485.xaml.cs new file mode 100644 index 00000000..8165e8f4 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz24485.xaml.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Globalization; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class Bz24485Converter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null) + return null; + + return new { + Date = DateTime.Now.ToString("dd MMMM yyyy"), + Object = new object () + }; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } + + public partial class Bz24485 : ContentPage + { + public Bz24485 () + { + InitializeComponent (); + } + + public Bz24485 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void BindingContextWithConverter (bool useCompiledXaml) + { + var layout = new Bz24485 (useCompiledXaml); + layout.BindingContext = new { Data1 = new object ()}; + Assert.Pass (); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz24910.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz24910.xaml new file mode 100644 index 00000000..6031212c --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz24910.xaml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" + xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + x:Class="Xamarin.Forms.Xaml.UnitTests.Bz24910" > + <StackLayout> + <local:Bz24910Control x:Name="control0" Text="CustomButton" NullableInt="1" NullableDouble="2.2" /> + <local:Bz24910Control x:Name="control1" Text="CustomButton" NullableDouble="2" /> + <local:Bz24910Control x:Name="control2" Text="CustomButton" NullableInt="{x:Null}" /> + <local:Bz24910Control x:Name="control3" Text="CustomButton" NullableInt="{Binding .}" /> + <Label x:Name="control4" local:Bz24910Control.AttachedNullableInt="3" /> + <local:Bz24910Control x:Name="control5" Text="CustomButton" NullableIntProp="5" /> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz24910.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz24910.xaml.cs new file mode 100644 index 00000000..50dad4f7 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz24910.xaml.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz24910 : ContentPage + { + public Bz24910 () + { + InitializeComponent (); + } + + public Bz24910 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true), TestCase(false)] + public void AllowNullableIntProperties (bool useCompiledXaml) + { + var page = new Bz24910 (useCompiledXaml); + var control = page.control0; + Assert.AreEqual (1, control.NullableInt); + } + + [TestCase(true), TestCase(false)] + public void AllowNullableDoubleProperties (bool useCompiledXaml) + { + var page = new Bz24910 (useCompiledXaml); + var control = page.control0; + Assert.AreEqual (2.2d, control.NullableDouble); + } + + [TestCase(true), TestCase(false)] + public void ConversionForNullable (bool useCompiledXaml) + { + var page = new Bz24910 (useCompiledXaml); + var control = page.control1; + Assert.AreEqual (2d, control.NullableDouble); + } + + [TestCase(true), TestCase(false)] + public void AllowNull (bool useCompiledXaml) + { + var page = new Bz24910 (useCompiledXaml); + var control = page.control2; + Assert.Null (control.NullableInt); + } + + [TestCase(true), TestCase(false)] + public void AllowBindingToNullable (bool useCompiledXaml) + { + var page = new Bz24910 (useCompiledXaml); + var control = page.control3; + Assert.Null (control.NullableInt); + + page.BindingContext = 2; + Assert.AreEqual (2, control.NullableInt); + } + + [TestCase(true), TestCase(false)] + public void NullableAttachedBPs (bool useCompiledXaml) + { + var page = new Bz24910 (useCompiledXaml); + var control = page.control4; + Assert.AreEqual (3, Bz24910Control.GetAttachedNullableInt (control)); + } + + [TestCase(true), TestCase(false)] + public void AllowNonBindableNullable (bool useCompiledXaml) + { + var page = new Bz24910 (useCompiledXaml); + var control = page.control5; + + Assert.AreEqual (5, control.NullableIntProp); + } + } + } + + public class Bz24910Control : Button + { + public static readonly BindableProperty NullableIntProperty = + BindableProperty.Create ("NullableInt", typeof(int?), typeof(Bz24910Control), default(int?)); + + public int? NullableInt { + get { return (int?)GetValue (NullableIntProperty); } + set { SetValue (NullableIntProperty, value); } + } + + public static readonly BindableProperty NullableDoubleProperty = + BindableProperty.Create ("NullableDouble", typeof(double?), typeof(Bz24910Control), default(double?)); + + public double? NullableDouble { + get { return (double?)GetValue (NullableDoubleProperty); } + set { SetValue (NullableDoubleProperty, value); } + } + + public static readonly BindableProperty AttachedNullableIntProperty = + BindableProperty.CreateAttached<Bz24910Control, int?> (bindable => GetAttachedNullableInt (bindable), default(int?)); + + public static int? GetAttachedNullableInt (BindableObject bindable) + { + return (int?)bindable.GetValue (AttachedNullableIntProperty); + } + + public static void SetAttachedNullableInt (BindableObject bindable, int? value) + { + bindable.SetValue (AttachedNullableIntProperty, value); + } + + public int? NullableIntProp { get; set; } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27299.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27299.xaml new file mode 100644 index 00000000..fd149013 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27299.xaml @@ -0,0 +1,14 @@ +<?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.Bz27299" + xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests" + BindingContext="{Binding Bz27299, Source={StaticResource ViewModelLocator}}"> + <ContentPage.Resources> + <ResourceDictionary> + <local:Bz27299ViewModelLocator x:Key="ViewModelLocator" /> + </ResourceDictionary> + </ContentPage.Resources> + <Label x:Name="label" + Text="{Binding Text}" /> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27299.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27299.xaml.cs new file mode 100644 index 00000000..35211a1b --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27299.xaml.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class Bz27299ViewModel + { + public string Text { + get { return "Foo"; } + } + } + public class Bz27299ViewModelLocator + { + public static int Count { get; set; } + public object Bz27299 { + get { + Count++; + return new Bz27299ViewModel (); + } + } + } + + public partial class Bz27299 : ContentPage + { + public Bz27299 () + { + InitializeComponent (); + } + public Bz27299 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [SetUp] + public void SetUp () + { + Bz27299ViewModelLocator.Count = 0; + } + + [TestCase(true)] + [TestCase(false)] + public void ViewModelLocatorOnlyCalledOnce (bool useCompiledXaml) + { + Assert.AreEqual (0, Bz27299ViewModelLocator.Count); + var layout = new Bz27299 (useCompiledXaml); + Assert.AreEqual (1, Bz27299ViewModelLocator.Count); + Assert.AreEqual ("Foo", layout.label.Text); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27863.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27863.xaml new file mode 100644 index 00000000..962ede6d --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27863.xaml @@ -0,0 +1,20 @@ +<?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.Bz27863"> + <ContentPage.Resources> + <ResourceDictionary> + <local:ReverseConverter x:Key="reverseConverter"/> + <DataTemplate x:Key="SimpleMessageTemplate"> + <ViewCell> + <StackLayout > + <Label Text="{Binding Converter={StaticResource reverseConverter}}" /> + </StackLayout> + </ViewCell> + </DataTemplate> + <ListView x:Key="listview" + ItemTemplate="{StaticResource SimpleMessageTemplate}" /> + </ResourceDictionary> + </ContentPage.Resources> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27863.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27863.xaml.cs new file mode 100644 index 00000000..03ebaaf9 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27863.xaml.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz27863 : ContentPage + { + public Bz27863 () + { + InitializeComponent (); + } + + public Bz27863 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void DataTemplateInResourceDictionaries (bool useCompiledXaml) + { + var layout = new Bz27863 (useCompiledXaml); + var listview = layout.Resources ["listview"] as ListView; + Assert.NotNull (listview.ItemTemplate); + var template = listview.ItemTemplate; + var cell = template.CreateContent () as ViewCell; + cell.BindingContext = "Foo"; + Assert.AreEqual ("ooF", ((Label)((StackLayout)cell.View).Children [0]).Text); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27968.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27968.xaml new file mode 100644 index 00000000..98121ab3 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27968.xaml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<local:Bz27968Page 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.Bz27968"> + <ContentPage.Resources> + <ResourceDictionary> + <DataTemplate x:Key="template"> + <ViewCell /> + </DataTemplate> + <ListView x:Key="listView" ItemTemplate="{StaticResource template}" /> + </ResourceDictionary> + </ContentPage.Resources> +</local:Bz27968Page>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27968.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27968.xaml.cs new file mode 100644 index 00000000..2482e9f0 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz27968.xaml.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class Bz27968Page : ContentPage + { + } + + public partial class Bz27968 : Bz27968Page + { + public Bz27968 () + { + InitializeComponent (); + } + + public Bz27968 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void BaseClassIdentifiersAreValidForResources (bool useCompiledXaml) + { + var layout = new Bz27968 (useCompiledXaml); + Assert.That (layout.Resources ["listView"], Is.TypeOf<ListView> ()); + } + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28545.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28545.xaml new file mode 100644 index 00000000..66664011 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28545.xaml @@ -0,0 +1,18 @@ +<?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.Bz28545"> + <ContentPage.Resources> + <ResourceDictionary> + <Style x:Key="TitleLabel" TargetType="Label"> + <Setter Property="AbsoluteLayout.LayoutBounds" Value="1,1,AutoSize,AutoSize" /> + <Setter Property="AbsoluteLayout.LayoutFlags" Value="PositionProportional" /> + <Setter Property="TextColor" Value="Pink" /> + </Style> + </ResourceDictionary> + </ContentPage.Resources> + <AbsoluteLayout> + <Label x:Name="label" + Style="{StaticResource TitleLabel}" /> + </AbsoluteLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28545.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28545.xaml.cs new file mode 100644 index 00000000..794e7ce1 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28545.xaml.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz28545 : ContentPage + { + public Bz28545 () + { + InitializeComponent (); + } + + public Bz28545 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void TypeConverterAreAppliedForSettersToAttachedBP (bool useCompiledXaml) + { + var layout = new Bz28545 (useCompiledXaml); + Assert.AreEqual (Color.Pink, layout.label.TextColor); + Assert.AreEqual (AbsoluteLayoutFlags.PositionProportional, AbsoluteLayout.GetLayoutFlags (layout.label)); + Assert.AreEqual (new Rectangle (1, 1, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize), AbsoluteLayout.GetLayoutBounds (layout.label)); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28556.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28556.xaml new file mode 100644 index 00000000..4780ee23 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28556.xaml @@ -0,0 +1,27 @@ +<?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.Bz28556"> + <ContentPage.Resources> + <ResourceDictionary> + <Style TargetType="Entry"> + <Setter Property="TextColor" Value="Yellow" /> + <Setter Property="BackgroundColor" Value="Green" /> + <Style.Triggers> + <Trigger TargetType="Entry" Property="IsEnabled" Value="False"> + <Setter Property="TextColor" Value="Red" /> + <Setter Property="BackgroundColor" Value="Purple" /> + </Trigger> +<!-- <Trigger TargetType="Entry" Property="IsEnabled" Value="True"> + <Setter Property="TextColor" Value="Yellow" /> + <Setter Property="BackgroundColor" Value="Green" /> + </Trigger>--> + </Style.Triggers> + </Style> + </ResourceDictionary> + </ContentPage.Resources> + <StackLayout> + <Entry x:Name="entry" Text="Sample Text" /> + <Entry x:Name="disableEntry" Text="Sample Text" IsEnabled="false" /> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28556.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28556.xaml.cs new file mode 100644 index 00000000..dd5bb317 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28556.xaml.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz28556 : ContentPage + { + public Bz28556 () + { + InitializeComponent (); + } + + public Bz28556 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void SettersAppliedBeforeTriggers (bool useCompiledXaml) + { + var layout = new Bz28556 (useCompiledXaml); + + Assert.AreEqual (Color.Yellow, layout.entry.TextColor); + Assert.AreEqual (Color.Green, layout.entry.BackgroundColor); + + Assert.AreEqual (Color.Red, layout.disableEntry.TextColor); + Assert.AreEqual (Color.Purple, layout.disableEntry.BackgroundColor); + + layout.entry.IsEnabled = false; + layout.disableEntry.IsEnabled = true; + + Assert.AreEqual (Color.Yellow, layout.disableEntry.TextColor); + Assert.AreEqual (Color.Green, layout.disableEntry.BackgroundColor); + + Assert.AreEqual (Color.Red, layout.entry.TextColor); + Assert.AreEqual (Color.Purple, layout.entry.BackgroundColor); + + layout.entry.IsEnabled = true; + layout.disableEntry.IsEnabled = false; + + Assert.AreEqual (Color.Yellow, layout.entry.TextColor); + Assert.AreEqual (Color.Green, layout.entry.BackgroundColor); + + Assert.AreEqual (Color.Red, layout.disableEntry.TextColor); + Assert.AreEqual (Color.Purple, layout.disableEntry.BackgroundColor); + } + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28689.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28689.xaml new file mode 100644 index 00000000..e2d10dab --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28689.xaml @@ -0,0 +1,13 @@ +<?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.Bz28689"> + <ContentPage.Resources> + <ResourceDictionary> + <x:Array x:Key="stringArray" Type="{x:Type x:String}"> + <x:String>Test1</x:String> + <x:String>Test2</x:String> + </x:Array> + </ResourceDictionary> + </ContentPage.Resources> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28689.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28689.xaml.cs new file mode 100644 index 00000000..41a8280c --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28689.xaml.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz28689 : ContentPage + { + public Bz28689 () + { + InitializeComponent (); + } + + public Bz28689 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void XArrayInResources (bool useCompiledXaml) + { + var layout = new Bz28689 (useCompiledXaml); + var array = layout.Resources ["stringArray"]; + Assert.That (array, Is.TypeOf<string[]> ()); + var stringarray = (string[])array; + Assert.AreEqual (2, stringarray.Length); + Assert.AreEqual ("Test1", stringarray [0]); + Assert.AreEqual ("Test2", stringarray [1]); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml new file mode 100644 index 00000000..54a8b9a0 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml @@ -0,0 +1,23 @@ +<?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.Bz28719"> + <ListView x:Name="listView"> + <ListView.ItemTemplate> + <DataTemplate> + <ViewCell> + <Image Grid.Row="0" Grid.Column="0"> + <Image.Triggers> + <DataTrigger TargetType="Image" Binding="{Binding IsSelected}" Value="False"> + <Setter Property="Source" Value="Add.png" /> + </DataTrigger> + <DataTrigger TargetType="Image" Binding="{Binding IsSelected}" Value="True"> + <Setter Property="Source" Value="Remove.png" /> + </DataTrigger> + </Image.Triggers> + </Image> + </ViewCell> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml.cs new file mode 100644 index 00000000..5cd1f9cb --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz28719.xaml.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz28719 : ContentPage + { + public Bz28719 () + { + InitializeComponent (); + } + + public Bz28719 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void DataTriggerInTemplates (bool useCompiledXaml) + { + var layout = new Bz28719 (useCompiledXaml); + var template = layout.listView.ItemTemplate; + Assert.NotNull (template); + var cell0 = template.CreateContent () as ViewCell; + Assert.NotNull (cell0); + var image0 = cell0.View as Image; + Assert.NotNull (image0); + + cell0.BindingContext = new {IsSelected = true}; + Assert.AreEqual ("Remove.png", (image0.Source as FileImageSource).File); + + cell0.BindingContext = new {IsSelected = false}; + Assert.AreEqual ("Add.png", (image0.Source as FileImageSource).File); + + var cell1 = template.CreateContent () as ViewCell; + Assert.NotNull (cell1); + var image1 = cell1.View as Image; + Assert.NotNull (image1); + + cell1.BindingContext = new {IsSelected = true}; + Assert.AreEqual ("Remove.png", (image1.Source as FileImageSource).File); + + cell1.BindingContext = new {IsSelected = false}; + Assert.AreEqual ("Add.png", (image1.Source as FileImageSource).File); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz29300.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz29300.xaml new file mode 100644 index 00000000..39b961dc --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz29300.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.Bz29300"> + <local:Bz29300DummyView x:Name="dummy" + Text="Test" + NumOfRepeat="4" /> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz29300.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz29300.xaml.cs new file mode 100644 index 00000000..3548fc14 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz29300.xaml.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class Bz29300DummyView : StackLayout + { + public static readonly BindableProperty NumOfRepeatProperty = + BindableProperty.Create<Bz29300DummyView, int> (p => p.NumOfRepeat, 1, BindingMode.OneWay, null, UpdateTexts); + + public static readonly BindableProperty TextProperty = + BindableProperty.Create<Bz29300DummyView, string> (p => p.Text, string.Empty, BindingMode.OneWay, null, UpdateTexts); + + public int NumOfRepeat + { + get { return (int)GetValue(NumOfRepeatProperty); } + set { SetValue(NumOfRepeatProperty, value); } + } + + public string Text + { + get { return (string)GetValue(TextProperty); } + set { SetValue(TextProperty, value); } + } + + public Bz29300DummyView() + { + } + + static void UpdateTexts(BindableObject bindable, string oldValue, string newValue) + { + var instance = bindable as Bz29300DummyView; + instance.Children.Clear(); + for (int i = 0; i < instance.NumOfRepeat; i++) + instance.Children.Add(new Label() {Text = newValue }); + } + + static void UpdateTexts(BindableObject bindable, int oldValue, int newValue) + { + var instance = bindable as Bz29300DummyView; + if (oldValue == newValue) + return; + if (oldValue > newValue) { + for (int i = newValue; i > oldValue; i--) + instance.Children.RemoveAt(0); + } else { + for (int i = oldValue; i < newValue; i++) + instance.Children.Add(new Label() { Text = instance.Text }); + } + } + } + + public partial class Bz29300 : ContentPage + { + public Bz29300 () + { + InitializeComponent (); + } + + public Bz29300 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void AccessUserDefinedBindableProperties (bool useCompiledXaml) + { + var layout = new Bz29300 (useCompiledXaml); + Assert.AreEqual (4, layout.dummy.NumOfRepeat); + Assert.AreEqual ("Test", layout.dummy.Text); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz30074.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz30074.xaml new file mode 100644 index 00000000..85604a82 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz30074.xaml @@ -0,0 +1,12 @@ +<?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.Bz30074"> + <Image x:Name="image"> + <Image.Triggers> + <DataTrigger TargetType="Image" Binding="{Binding IsSelected}" Value="True"> + <Setter Property="Source" Value="Add.png" /> + </DataTrigger> + </Image.Triggers> + </Image> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz30074.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz30074.xaml.cs new file mode 100644 index 00000000..e1c60feb --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz30074.xaml.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz30074 : ContentPage + { + public Bz30074 () + { + InitializeComponent (); + } + + public Bz30074 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void DataTriggerInTemplates (bool useCompiledXaml) + { + var layout = new Bz30074 (useCompiledXaml); + Assert.Null (layout.image.Source); + + layout.BindingContext = new {IsSelected = true}; + Assert.AreEqual ("Add.png", ((FileImageSource)layout.image.Source).File); + + layout.BindingContext = new {IsSelected = false}; + Assert.Null (layout.image.Source); + } + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz30684.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz30684.xaml new file mode 100644 index 00000000..0dff72c2 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz30684.xaml @@ -0,0 +1,15 @@ +<?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.Bz30684"> + <StackLayout> + <Label Text="Foo" x:Name="foo" /> + <ListView x:Name="listView"> + <ListView.ItemTemplate> + <DataTemplate> + <TextCell Text="{Binding Text, Source={x:Reference foo}}" /> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz30684.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz30684.xaml.cs new file mode 100644 index 00000000..2b0ca827 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz30684.xaml.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz30684 : ContentPage + { + public Bz30684 () + { + InitializeComponent (); + } + + public Bz30684 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void XReferenceFindObjectsInParentNamescopes (bool useCompiledXaml) + { + var layout = new Bz30684 (useCompiledXaml); + var cell = (TextCell)layout.listView.TemplatedItems.GetOrCreateContent (0, null); + Assert.AreEqual ("Foo", cell.Text); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31234/A/Bz31234.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31234/A/Bz31234.xaml new file mode 100644 index 00000000..57f780a6 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31234/A/Bz31234.xaml @@ -0,0 +1,7 @@ +<?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.A.Bz31234"> + <ContentPage.Content> + </ContentPage.Content> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31234/A/Bz31234.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31234/A/Bz31234.xaml.cs new file mode 100644 index 00000000..a2c1a62c --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31234/A/Bz31234.xaml.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests.A +{ + public partial class Bz31234 : ContentPage + { + public Bz31234 () + { + InitializeComponent (); + } + + public Bz31234 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase(true), TestCase(false)] + public void ShouldPass (bool useCompiledXaml) + { + new Bz31234 (useCompiledXaml); + Assert.Pass (); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31234/B/Bz31234.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31234/B/Bz31234.xaml new file mode 100644 index 00000000..4be6af22 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31234/B/Bz31234.xaml @@ -0,0 +1,7 @@ +<?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.B.Bz31234"> + <ContentPage.Content> + </ContentPage.Content> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31234/B/Bz31234.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31234/B/Bz31234.xaml.cs new file mode 100644 index 00000000..b7b12be8 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31234/B/Bz31234.xaml.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +namespace Xamarin.Forms.Xaml.UnitTests.B +{ + public partial class Bz31234 : ContentPage + { + public Bz31234 () + { + InitializeComponent (); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31529.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31529.xaml new file mode 100644 index 00000000..ebe69f8c --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31529.xaml @@ -0,0 +1,10 @@ +<?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.Bz31529"> + <StackLayout> + <Label x:Name="label" Text="Foo" /> + <Button x:Name="button" + CommandParameter = "{Binding Text, Source= {x:Reference label}}" /> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31529.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31529.xaml.cs new file mode 100644 index 00000000..7edf9ad2 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz31529.xaml.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz31529 : ContentPage + { + public Bz31529 () + { + InitializeComponent (); + } + public Bz31529 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void AllowWhiteSpacesInMarkups (bool useCompiledXaml) + { + var layout = new Bz31529 (useCompiledXaml); + Assert.AreEqual ("Foo", layout.button.CommandParameter); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz34037.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz34037.xaml new file mode 100644 index 00000000..b5c36482 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz34037.xaml @@ -0,0 +1,37 @@ +<?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.Bz34037" + xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests" + x:Name="PageRoot"> + <ContentPage.Resources> + <ResourceDictionary> + <local:Bz34037Converter0 x:Key="MyConverter0" /> + <local:Bz34037Converter1 x:Key="MyConverter1" /> + </ResourceDictionary> + </ContentPage.Resources> + <StackLayout> + <Switch x:Name="s0"> + <Switch.Triggers> + <MultiTrigger TargetType="Switch"> + <MultiTrigger.Conditions> + <BindingCondition Value="True" + Binding="{Binding Property, Source={x:Reference PageRoot}, Converter={local:Bz34037Converter0}, ConverterParameter={x:Type x:String}}" /> + </MultiTrigger.Conditions> + <Setter Property="Switch.IsToggled" Value="True" /> + </MultiTrigger> + </Switch.Triggers> + </Switch> + <Switch x:Name="s1"> + <Switch.Triggers> + <MultiTrigger TargetType="Switch"> + <MultiTrigger.Conditions> + <BindingCondition Value="True" + Binding="{Binding Property, ConverterParameter={x:Type x:String}, Source={x:Reference PageRoot}, Converter={local:Bz34037Converter1}}" /> + </MultiTrigger.Conditions> + <Setter Property="Switch.IsToggled" Value="True" /> + </MultiTrigger> + </Switch.Triggers> + </Switch> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz34037.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz34037.xaml.cs new file mode 100644 index 00000000..ee300cb0 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz34037.xaml.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class Bz34037Converter0 : IValueConverter, IMarkupExtension + { + public static int Invoked { get; set; } + public static object Parameter { get; set; } + public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + Invoked++; + Parameter = parameter; + return true; + } + + public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException (); + } + + public object ProvideValue (IServiceProvider serviceProvider) + { + return new Bz34037Converter0 (); + } + } + + public class Bz34037Converter1 : IValueConverter, IMarkupExtension + { + public static int Invoked { get; set; } + public static object Parameter { get; set; } + public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + Invoked++; + Parameter = parameter; + return true; + } + + public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException (); + } + + public object ProvideValue (IServiceProvider serviceProvider) + { + return new Bz34037Converter1 (); + } + } + + public partial class Bz34037 : ContentPage + { + public Bz34037 () + { + InitializeComponent (); + } + + public string Property { + get { return "FooBar"; } + } + + public Bz34037 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [SetUp] + public void Setup () + { + Bz34037Converter0.Invoked = 0; + Bz34037Converter1.Invoked = 0; + } + + [TestCase(true)] + [TestCase(false)] + public void ConverterParameterOrderDoesNotMatters (bool useCompiledXaml) + { + var layout = new Bz34037 (useCompiledXaml); + Assert.AreEqual (2, Bz34037Converter0.Invoked); +// Assert.AreEqual (2, Bz34037Converter1.Invoked); + Assert.AreEqual (typeof(string), Bz34037Converter0.Parameter); +// Assert.AreEqual (typeof(string), Bz34037Converter1.Parameter); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz36422.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz36422.xaml new file mode 100644 index 00000000..4a467eab --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz36422.xaml @@ -0,0 +1,21 @@ +<?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.Bz36422"> + <local:Bz36422Control x:Name="control"> + <local:Bz36422Control.Views> + <x:Array Type="{x:Type ContentView}"> + <ContentView> + <Label Text="Page 1"/> + </ContentView> + <ContentView> + <Label Text="Page 2"/> + </ContentView> + <ContentView> + <Label Text="Page 3"/> + </ContentView> + </x:Array> + </local:Bz36422Control.Views> + </local:Bz36422Control> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz36422.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz36422.xaml.cs new file mode 100644 index 00000000..4728068f --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz36422.xaml.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class Bz36422Control : ContentView + { + public IList<ContentView> Views { get; set; } + } + + public partial class Bz36422 : ContentPage + { + public Bz36422 () + { + InitializeComponent (); + } + + public Bz36422 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void xArrayCanBeAssignedToIListT (bool useCompiledXaml) + { + var layout = new Bz36422 (useCompiledXaml); + Assert.AreEqual (3, layout.control.Views.Count); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz37306.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz37306.xaml new file mode 100644 index 00000000..bfd5b732 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz37306.xaml @@ -0,0 +1,12 @@ +<?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:sys="clr-namespace:System;assembly=mscorlib" + x:Class="Xamarin.Forms.Xaml.UnitTests.Bz37306"> + <ContentPage.Resources> + <ResourceDictionary> + <x:String x:Key="AppName">Mobile App</x:String> + <sys:String x:Key="ApplicationName">Mobile App</sys:String> + </ResourceDictionary> + </ContentPage.Resources> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz37306.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz37306.xaml.cs new file mode 100644 index 00000000..6e0d39e2 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz37306.xaml.cs @@ -0,0 +1,31 @@ +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz37306 : ContentPage + { + public Bz37306 () + { + InitializeComponent (); + } + + public Bz37306 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void xStringInResourcesDictionaries (bool useCompiledXaml) + { + var layout = new Bz37306 (useCompiledXaml); + Assert.AreEqual ("Mobile App", layout.Resources ["AppName"]); + Assert.AreEqual ("Mobile App", layout.Resources ["ApplicationName"]); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz37524.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz37524.xaml new file mode 100644 index 00000000..df2736a8 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz37524.xaml @@ -0,0 +1,22 @@ +<?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.Bz37524"> + <StackLayout> + <Entry x:Name="TheEntry" + Text="This simulates an error" + TextColor="Red"/> + <Button x:Name="TheButton" + Text="Should be disabled"> + <Button.Triggers> + <MultiTrigger TargetType="Button"> + <MultiTrigger.Conditions> + <BindingCondition Binding="{Binding Source={x:Reference TheEntry}, Path=TextColor}" + Value="Red" /> + </MultiTrigger.Conditions> + <Setter Property="IsEnabled" Value="False" /> + </MultiTrigger> + </Button.Triggers> + </Button> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz37524.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz37524.xaml.cs new file mode 100644 index 00000000..d979755d --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz37524.xaml.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Bz37524 : ContentPage + { + public Bz37524 () + { + InitializeComponent (); + } + + public Bz37524 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void MultiTriggerConditionNotApplied (bool useCompiledXaml) + { + var layout = new Bz37524 (useCompiledXaml); + Assert.AreEqual (false, layout.TheButton.IsEnabled); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/GrialIssue01.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/GrialIssue01.xaml new file mode 100644 index 00000000..ea92c61e --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/GrialIssue01.xaml @@ -0,0 +1,10 @@ +<?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.GrialIssue01"> + <ContentPage.Resources> + <ResourceDictionary> + <FileImageSource x:Key="image">path.png</FileImageSource> + </ResourceDictionary> + </ContentPage.Resources> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/GrialIssue01.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/GrialIssue01.xaml.cs new file mode 100644 index 00000000..7cf20f42 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/GrialIssue01.xaml.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class GrialIssue01 : ContentPage + { + public GrialIssue01 () + { + InitializeComponent (); + } + + public GrialIssue01 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void ImplicitCastIsUsedOnFileImageSource (bool useCompiledXaml) + { + var layout = new GrialIssue01 (useCompiledXaml); + var res = (FileImageSource)layout.Resources ["image"]; + + Assert.AreEqual ("path.png", res.File); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/GrialIssue02.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/GrialIssue02.xaml new file mode 100644 index 00000000..d623607b --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/GrialIssue02.xaml @@ -0,0 +1,18 @@ +<?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.GrialIssue02"> + <ContentPage.Resources> + <ResourceDictionary> + <local:GrialIssue02Converter x:Key="converter"> + <local:GrialIssue02Converter.TrueValue> + <FontAttributes>None</FontAttributes> + </local:GrialIssue02Converter.TrueValue> + <local:GrialIssue02Converter.FalseValue> + <FontAttributes>Bold</FontAttributes> + </local:GrialIssue02Converter.FalseValue> + </local:GrialIssue02Converter> + </ResourceDictionary> + </ContentPage.Resources> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/GrialIssue02.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/GrialIssue02.xaml.cs new file mode 100644 index 00000000..ca239af7 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/GrialIssue02.xaml.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using System.Globalization; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class GrialIssue02Converter : IValueConverter + { + public object FalseValue { + get; + set; + } + + public object TrueValue { + get; + set; + } + + public object Convert (object value, Type targetType, object parameter, CultureInfo culture) + { + if (!(value is bool)) { + return null; + } + bool flag = (bool)value; + return (!flag) ? FalseValue : TrueValue; + } + + public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException (); + } + } + + public partial class GrialIssue02 : ContentPage + { + public GrialIssue02 () + { + InitializeComponent (); + } + public GrialIssue02 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void BoxValueTypes (bool useCompiledXaml) + { + var layout = new GrialIssue02 (useCompiledXaml); + var res = (GrialIssue02Converter)layout.Resources ["converter"]; + + Assert.AreEqual (FontAttributes.None, res.TrueValue); + Assert.AreEqual (FontAttributes.Bold, res.FalseValue); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1199.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1199.xaml new file mode 100644 index 00000000..7d6abe90 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1199.xaml @@ -0,0 +1,10 @@ +<?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.Issue1199"> +<ContentPage.Resources> + <ResourceDictionary> + <Color x:Key="AlmostSilver">#FFCCCCCC</Color> + </ResourceDictionary> + </ContentPage.Resources> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1199.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1199.xaml.cs new file mode 100644 index 00000000..18ae8731 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1199.xaml.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue1199 : ContentPage + { + public Issue1199 () + { + InitializeComponent (); + } + + public Issue1199 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true)] + [TestCase(false)] + public void AllowCreationOfTypesFromString (bool useCompiledXaml) + { + var layout = new Issue1199 (useCompiledXaml); + var res = (Color)layout.Resources ["AlmostSilver"]; + + Assert.AreEqual (Color.FromHex ("#FFCCCCCC"), res); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1213.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1213.xaml new file mode 100644 index 00000000..ec149423 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1213.xaml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + x:Class="Xamarin.Forms.Xaml.UnitTests.Issue1213"> + <ContentPage Title="page 1"> + <Label Text="page 1" + VerticalOptions = "LayoutOptions.CenterAndExpand" + HorizontalOptions = "LayoutOptions.CenterAndExpand"/> + </ContentPage> + <ContentPage Title="page 2"> + <Label Text="page 2" + VerticalOptions = "LayoutOptions.CenterAndExpand" + HorizontalOptions = "LayoutOptions.CenterAndExpand"/> + </ContentPage> +</TabbedPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1213.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1213.xaml.cs new file mode 100644 index 00000000..d89203b7 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1213.xaml.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue1213 : TabbedPage + { + public Issue1213 () + { + InitializeComponent (); + } + + public Issue1213 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase(false)] + [TestCase(true)] + public void MultiPageAsContentPropertyAttribute (bool useCompiledXaml) + { + var page = new Issue1213 (useCompiledXaml); + Assert.AreEqual (2, page.Children.Count); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1250.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1250.xaml new file mode 100644 index 00000000..ad06901c --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1250.xaml @@ -0,0 +1,13 @@ +<?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;assembly=Xamarin.Forms.Xaml.UnitTests" + x:Class="Xamarin.Forms.Xaml.UnitTests.Issue1250"> + <StackLayout x:Name="stack"> + <Label Text="{Binding Header}" /> + <local:Issue1250AspectRatioContainer AspectRatio="0.5"> + <Image Source="{Binding Image}" Aspect="Fill" /> + </local:Issue1250AspectRatioContainer> + <Label Text="{Binding Footer}" /> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1250.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1250.xaml.cs new file mode 100644 index 00000000..8f4cdb7d --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1250.xaml.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class Issue1250AspectRatioContainer : ContentView + { + protected override SizeRequest OnSizeRequest(double widthConstraint, double heightConstraint) + { + return new SizeRequest(new Size(widthConstraint, widthConstraint * AspectRatio)); + } + + public double AspectRatio { get; set; } + } + + public partial class Issue1250 : ContentPage + { + public Issue1250 () + { + InitializeComponent (); + } + + public Issue1250 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void AddCustomElementInCollection (bool useCompiledXaml) + { + var page = new Issue1250 (useCompiledXaml); + var stack = page.stack; + + Assert.AreEqual (3, stack.Children.Count); + Assert.That (stack.Children [0], Is.TypeOf<Label> ()); + Assert.That (stack.Children [1], Is.TypeOf<Issue1250AspectRatioContainer> ()); + Assert.That (stack.Children [2], Is.TypeOf<Label> ()); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1306.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1306.xaml new file mode 100644 index 00000000..e77a2d95 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1306.xaml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ListView xmlns="http://xamarin.com/schemas/2014/forms" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + x:Class="Xamarin.Forms.Xaml.UnitTests.Issue1306" + GroupDisplayBinding="{Binding Key}" + GroupShortNameBinding="{Binding Key}"/>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1306.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1306.xaml.cs new file mode 100644 index 00000000..582ce102 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1306.xaml.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue1306 : ListView + { + public Issue1306 () + { + InitializeComponent (); + } + + public Issue1306 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void AssignBindingMarkupToBindingBase (bool useCompiledXaml) + { + var listView = new Issue1306 (useCompiledXaml); + + Assert.NotNull (listView.GroupDisplayBinding); + Assert.NotNull (listView.GroupShortNameBinding); + Assert.That (listView.GroupDisplayBinding, Is.TypeOf<Binding> ()); + Assert.That (listView.GroupShortNameBinding, Is.TypeOf<Binding> ()); + Assert.AreEqual ("Key", (listView.GroupDisplayBinding as Binding).Path); + Assert.AreEqual ("Key", (listView.GroupShortNameBinding as Binding).Path); + } + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1415.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1415.xaml new file mode 100644 index 00000000..148704ea --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1415.xaml @@ -0,0 +1,7 @@ +<?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.Issue1415" + xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"> + <Label x:Name="label" Text="{Binding Converter={x:Static local:ReverseConverter.Instance}, Mode=TwoWay}"/> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1415.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1415.xaml.cs new file mode 100644 index 00000000..b23fdb92 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1415.xaml.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue1415 : ContentPage + { + public Issue1415 () + { + InitializeComponent (); + } + + public Issue1415 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void NestedMarkupExtension (bool useCompiledXaml) + { + var page = new Issue1415 (useCompiledXaml); + var label = page.FindByName<Label> ("label"); + Assert.NotNull (label); + label.BindingContext = "foo"; + Assert.AreEqual ("oof", label.Text); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1438.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1438.xaml new file mode 100644 index 00000000..f31c52ab --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1438.xaml @@ -0,0 +1,15 @@ +<?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.Issue1438"> + <StackLayout> + <Label BindingContext="{x:Reference slider}" + x:Name="label" + Text="{Binding Value, StringFormat='Slider value is {0:F3}'}" + Font="Large" + HorizontalOptions="Center" + VerticalOptions="CenterAndExpand" /> + <Slider x:Name="slider" + VerticalOptions="CenterAndExpand" /> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1438.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1438.xaml.cs new file mode 100644 index 00000000..26ee3d0b --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1438.xaml.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; +using System.Diagnostics; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue1438 : ContentPage + { + public Issue1438 () + { + InitializeComponent (); + } + + public Issue1438 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void Setup () + { + Device.PlatformServices = new MockPlatformServices (); + } + + [TestCase (false)] + [TestCase (true)] + public void XNameForwardDeclaration (bool useCompiledXaml) + { + var page = new Issue1438 (useCompiledXaml); + + var slider = page.FindByName<Slider> ("slider"); + var label = page.FindByName<Label> ("label"); + Assert.AreSame (slider, label.BindingContext); + Assert.That (slider.Parent, Is.TypeOf<StackLayout> ()); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1493.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1493.cs new file mode 100644 index 00000000..41f00ab8 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1493.cs @@ -0,0 +1,26 @@ +using System; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class Issue1493 + { + [Test] + //mostly happens in european cultures + [SetCulture ("fr-FR")] + public void CultureInvariantNumberParsing () + { + var xaml = @"<?xml version=""1.0"" encoding=""utf-8"" ?> + <View + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + RelativeLayout.HeightConstraint=""{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.25}"" + RelativeLayout.WidthConstraint=""{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.6}""/>"; + View view = new View (); + view.LoadFromXaml (xaml); + Assert.DoesNotThrow (() => view.LoadFromXaml (xaml)); + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1497.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1497.cs new file mode 100644 index 00000000..3813f73a --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1497.cs @@ -0,0 +1,27 @@ +using System; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class Issue1497 + { + [Test] + public void BPCollectionsWithSingleElement () + { + var xaml = @"<?xml version=""1.0"" encoding=""utf-8"" ?> + <Grid + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""> + <Grid.ColumnDefinitions> + <ColumnDefinition Width=""*""/> + </Grid.ColumnDefinitions> + </Grid>"; + + var grid = new Grid ().LoadFromXaml (xaml); + Assert.AreEqual (1, grid.ColumnDefinitions.Count); + Assert.True (grid.ColumnDefinitions [0].Width.IsStar); + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1501.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1501.cs new file mode 100644 index 00000000..d4a5e761 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1501.cs @@ -0,0 +1,41 @@ +using System; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class BoxView1501 : BoxView + { + public bool Fired { get; set;} + + public void OnBoxViewTapped (object sender, EventArgs e) + { + Fired = true; + } + } + + [TestFixture] + public class Issue1501 + { + [Test] + public void ConnectEventsInGestureRecognizers () + { + var xaml = @" + <BoxView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + x:Class=""Xamarin.Forms.Xaml.UnitTests.BoxView1501"" > + <BoxView.GestureRecognizers> + <TapGestureRecognizer Tapped=""OnBoxViewTapped"" /> + </BoxView.GestureRecognizers> + </BoxView>"; + + BoxView1501 layout = null; + Assert.DoesNotThrow (() => {layout = new BoxView1501 ().LoadFromXaml (xaml);}); + + Assert.False (layout.Fired); + var tgr = layout.GestureRecognizers [0] as TapGestureRecognizer; + tgr.SendTapped (layout); + Assert.True (layout.Fired); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1545.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1545.cs new file mode 100644 index 00000000..00747db4 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1545.cs @@ -0,0 +1,174 @@ +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class Issue1545 + { + [Test] + public void BindingCanNotBeReused() + { + string xaml = @"<ContentPage xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + x:Class=""Xamarin.Forms.Controls.Issue1545""> + <ListView x:Name=""List"" ItemsSource=""{Binding}""> + <ListView.ItemTemplate> + <DataTemplate> + <TextCell Text=""{Binding}"" /> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> + </ContentPage>"; + + ContentPage page = new ContentPage().LoadFromXaml (xaml); + + var items = new[] { "Fu", "Bar" }; + page.BindingContext = items; + + ListView lv = page.FindByName<ListView> ("List"); + + TextCell cell = (TextCell)lv.TemplatedItems.GetOrCreateContent (0, items[0]); + Assert.That (cell.Text, Is.EqualTo ("Fu")); + + cell = (TextCell)lv.TemplatedItems.GetOrCreateContent (1, items[1]); + Assert.That (cell.Text, Is.EqualTo ("Bar")); + } + + [Test] + public void ElementsCanNotBeReused() + { + string xaml = @"<ContentPage xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + x:Class=""Xamarin.Forms.Controls.Issue1545""> + <ContentPage.Resources> + <ResourceDictionary> + <Color x:Key=""color"">#ff00aa</Color> + </ResourceDictionary> + </ContentPage.Resources> + + <ListView x:Name=""List"" ItemsSource=""{Binding}""> + <ListView.ItemTemplate> + <DataTemplate> + <ViewCell> + <StackLayout> + <Label Text=""{Binding}"" BackgroundColor=""{StaticResource color}""/> + </StackLayout> + </ViewCell> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> + </ContentPage>"; + + ContentPage page = new ContentPage().LoadFromXaml (xaml); + + var items = new[] { "Fu", "Bar" }; + page.BindingContext = items; + + ListView lv = page.FindByName<ListView> ("List"); + + ViewCell cell0 = (ViewCell)lv.TemplatedItems.GetOrCreateContent (0, items[0]); + + + Assert.That (((Label)((StackLayout)cell0.View).Children[0]).Text, Is.EqualTo ("Fu")); + + ViewCell cell1 = (ViewCell)lv.TemplatedItems.GetOrCreateContent (1, items[1]); + Assert.That (((Label)((StackLayout)cell1.View).Children[0]).Text, Is.EqualTo ("Bar")); + + Assert.AreNotSame (cell0, cell1); + Assert.AreNotSame (cell0.View, cell1.View); + Assert.AreNotSame (((StackLayout)cell0.View).Children [0], ((StackLayout)cell1.View).Children [0]); + Assert.AreEqual (Color.FromHex ("ff00aa"), ((StackLayout)cell1.View).Children [0].BackgroundColor); + } + + [Test] + public void ElementsFromCollectionsAreNotReused () + { + var xaml = @"<ListView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" + ItemsSource=""{Binding}""> + <ListView.ItemTemplate> + <DataTemplate> + <local:ViewCellWithCollection> + <local:ViewCellWithCollection.Children> + <local:ViewList> + <Label /> + <Label /> + </local:ViewList> + </local:ViewCellWithCollection.Children> + </local:ViewCellWithCollection> + </DataTemplate> + </ListView.ItemTemplate> + </ListView>"; + + var listview = new ListView (); + var items = new [] { "Foo", "Bar", "Baz" }; + listview.BindingContext = items; + listview.LoadFromXaml (xaml); + var cell0 = (ViewCellWithCollection)listview.TemplatedItems.GetOrCreateContent (0, items[0]); + var cell1 = (ViewCellWithCollection)listview.TemplatedItems.GetOrCreateContent (1, items[1]); + + Assert.AreNotSame (cell0, cell1); + Assert.AreNotSame (cell0.Children, cell1.Children); + Assert.AreNotSame (cell0.Children[0], cell1.Children[0]); + + } + + [Test] + public void ResourcesDeclaredInDataTemplatesAreNotShared () + { + var xaml = @"<ListView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + xmlns:sys=""clr-namespace:System;assembly=mscorlib"" + ItemsSource=""{Binding}""> + <ListView.ItemTemplate> + <DataTemplate> + <ViewCell> + <Label Text=""{Binding}""> + <Label.Resources> + <ResourceDictionary> + <sys:Object x:Key=""object""/> + </ResourceDictionary> + </Label.Resources> + </Label> + </ViewCell> + </DataTemplate> + </ListView.ItemTemplate> + </ListView>"; + + var listview = new ListView (); + var items = new [] { "Foo", "Bar", "Baz" }; + listview.BindingContext = items; + + listview.LoadFromXaml (xaml); + var cell0 = (ViewCell)listview.TemplatedItems.GetOrCreateContent (0, items[0]); + var cell1 = (ViewCell)listview.TemplatedItems.GetOrCreateContent (1, items[1]); + Assert.AreNotSame (cell0, cell1); + + var label0 = (Label)cell0.View; + var label1 = (Label)cell1.View; + Assert.AreNotSame (label0, label1); + Assert.AreEqual ("Foo", label0.Text); + Assert.AreEqual ("Bar", label1.Text); + + var res0 = label0.Resources; + var res1 = label1.Resources; + Assert.AreNotSame (res0, res1); + + var obj0 = res0 ["object"]; + var obj1 = res1 ["object"]; + + Assert.NotNull (obj0); + Assert.NotNull (obj1); + + Assert.AreNotSame (obj0, obj1); + } + } + + public class ViewCellWithCollection : ViewCell + { + public ViewList Children { get; set; } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1549.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1549.cs new file mode 100644 index 00000000..c1253040 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1549.cs @@ -0,0 +1,166 @@ +using System; +using NUnit.Framework; +using System.Collections.ObjectModel; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + + public class SeverityColorConverter : IValueConverter + { + + public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + count++; + return Color.Blue; + } + + public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException (); + } + + + public static int count=0; + } + + public class InvertBoolenConverter : IValueConverter + { + public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + count++; + if (value is bool) { + + return !(bool)value; + } + return value; + } + + public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException (); + } + public static int count=0; + } + + public class Item + { + public bool IsLocked { + get; + set; + } + } + + [TestFixture] + public class Issue1549 + { + [SetUp] + public void Setup () + { + SeverityColorConverter.count = 0; + InvertBoolenConverter.count = 0; + } + + [Test] + public void ConverterIsInvoked () + { + var xaml = @" +<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;assembly=Xamarin.Forms.Xaml.UnitTests""> + +<ContentPage.Resources> +<ResourceDictionary> +<local:SeverityColorConverter x:Key=""SeverityColorConverter"" /> +</ResourceDictionary> +</ContentPage.Resources> + <Label Text=""{Binding value, StringFormat='{0}'}"" + WidthRequest=""50"" + TextColor=""Black"" + x:Name=""label"" + BackgroundColor=""{Binding Severity, Converter={StaticResource SeverityColorConverter}}"" + XAlign=""Center"" YAlign=""Center""/> +</ContentPage>"; + + var layout = new ContentPage ().LoadFromXaml (xaml); + layout.BindingContext = new {Value = "Foo", Severity = "Bar"}; + var label = layout.FindByName<Label> ("label"); + Assert.AreEqual (Color.Blue, label.BackgroundColor); + Assert.AreEqual (1, SeverityColorConverter.count); + } + + [Test] + public void ResourcesInNonXFBaseClassesAreFound () + { + var xaml = @"<local:BaseView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" + Padding=""0,40,0,0""> + <local:BaseView.Resources> + <ResourceDictionary> + <local:InvertBoolenConverter x:Key=""cnvInvert""></local:InvertBoolenConverter> + </ResourceDictionary> + </local:BaseView.Resources> + <local:BaseView.Content> + <ListView x:Name=""lst"" VerticalOptions=""FillAndExpand"" + HorizontalOptions=""FillAndExpand"" + + ItemsSource=""{Binding Items}"" + + > + <ListView.ItemTemplate > + <DataTemplate> + <ViewCell > + <ViewCell.View> + <Grid VerticalOptions=""FillAndExpand"" HorizontalOptions=""FillAndExpand"" > + <Label IsVisible=""{Binding IsLocked}"" Text=""Show Is Locked"" /> + <Label IsVisible=""{Binding IsLocked, Converter={StaticResource cnvInvert}}"" Text=""Show Is Not locked"" /> + </Grid> + </ViewCell.View> + </ViewCell> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> + </local:BaseView.Content> +</local:BaseView>"; + var page = new Issue1549Page ().LoadFromXaml (xaml); + var lst = page.FindByName<ListView> ("lst"); + ObservableCollection<Item> items; + lst.BindingContext = new { + Items = items = new ObservableCollection<Item> { + new Item { IsLocked = true}, + new Item { IsLocked = false}, + new Item { IsLocked = true}, + new Item { IsLocked = true}, + }, + }; + + var cell0 = (ViewCell)lst.TemplatedItems.GetOrCreateContent (0, items [0]); + var cell1 = (ViewCell)lst.TemplatedItems.GetOrCreateContent (1, items [1]); + var cell2 = (ViewCell)lst.TemplatedItems.GetOrCreateContent (2, items [2]); + var cell3 = (ViewCell)lst.TemplatedItems.GetOrCreateContent (3, items [3]); + + var label00 = (cell0.View as Grid).Children [0] as Label; + var label01 = (cell0.View as Grid).Children [1] as Label; + + Assert.AreEqual ("Show Is Locked", label00.Text); + Assert.AreEqual ("Show Is Not locked", label01.Text); + + Assert.AreEqual (true, label00.IsVisible); + Assert.AreEqual (false, label01.IsVisible); + + Assert.AreEqual (4, InvertBoolenConverter.count); + + } + } + + public class BaseView : ContentPage + { + } + + public partial class Issue1549Page : BaseView + { + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1554.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1554.cs new file mode 100644 index 00000000..2e7bfa91 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1554.cs @@ -0,0 +1,53 @@ +using System; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class Issue1554 + { + [Test] + public void CollectionItemsInDataTemplate () + { + var xaml = @"<?xml version=""1.0"" encoding=""UTF-8""?> + <ListView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + ItemsSource=""{Binding}""> + <ListView.ItemTemplate> + <DataTemplate> + <ViewCell> + <ViewCell.View> + <StackLayout> + <Label Text=""{Binding}""></Label> + <Label Text=""{Binding}""></Label> + </StackLayout> + </ViewCell.View> + </ViewCell> + </DataTemplate> + </ListView.ItemTemplate> + </ListView>"; + var listview = new ListView (); + var items = new [] { "Foo", "Bar", "Baz" }; + listview.BindingContext = items; + + listview.LoadFromXaml (xaml); + + ViewCell cell0 = null; + Assert.DoesNotThrow (() => { + cell0 = (ViewCell)listview.TemplatedItems.GetOrCreateContent (0, items [0]); + }); + ViewCell cell1 = null; + Assert.DoesNotThrow (() => { + cell1 = (ViewCell)listview.TemplatedItems.GetOrCreateContent (1, items [1]); + }); + + Assert.AreNotSame (cell0, cell1); + Assert.AreNotSame (cell0.View, cell1.View); + Assert.AreNotSame (((StackLayout)cell0.View).Children [0], ((StackLayout)cell1.View).Children [0]); + Assert.AreNotSame (((StackLayout)cell0.View).Children [1], ((StackLayout)cell1.View).Children [1]); + + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1564.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1564.cs new file mode 100644 index 00000000..895eb900 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1564.cs @@ -0,0 +1,29 @@ +using System; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class Issue1564 + { + [Test] + public void ViewCellAsXamlRoot () + { + var xaml = @"<?xml version=""1.0"" encoding=""UTF-8""?> + <ViewCell + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + x:Class=""m.transport.VehicleCell""> + <ViewCell.View> + <StackLayout> + <Label Text=""This is my label""></Label> + </StackLayout> + </ViewCell.View> + </ViewCell>"; + var cell = new ViewCell ().LoadFromXaml (xaml); + Assert.NotNull (cell); + Assert.AreEqual ("This is my label", ((cell.View as StackLayout).Children [0] as Label).Text); + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1594.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1594.cs new file mode 100644 index 00000000..cd942319 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1594.cs @@ -0,0 +1,43 @@ +using System; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class Issue1594 + { + [Test] + public void OnPlatformForButtonHeight () + { + var xaml = @" + <Button + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + xmlns:sys=""clr-namespace:System;assembly=mscorlib"" + x:Name=""activateButton"" Text=""ACTIVATE NOW"" TextColor=""White"" BackgroundColor=""#00A0FF""> + <Button.HeightRequest> + <OnPlatform x:TypeArguments=""sys:Double"" + iOS=""33"" + Android=""44"" + WinPhone=""44"" /> + </Button.HeightRequest> + </Button>"; + + Device.OS = TargetPlatform.iOS; + var button = new Button ().LoadFromXaml (xaml); + Assert.AreEqual (33, button.HeightRequest); + + Device.OS = TargetPlatform.Android; + button = new Button ().LoadFromXaml (xaml); + Assert.AreEqual (44, button.HeightRequest); + + Device.OS = TargetPlatform.WinPhone; + button = new Button ().LoadFromXaml (xaml); + Assert.AreEqual (44, button.HeightRequest); + + + } + + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1637.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1637.cs new file mode 100644 index 00000000..f6083fb1 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1637.cs @@ -0,0 +1,25 @@ +using System; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class Issue1637 + { + [Test] + public void ImplicitCollectionWithSingleElement () + { + var xaml = @" + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height=""*"" /> + </Grid.RowDefinitions> + </Grid>"; + var grid = new Grid (); + Assert.DoesNotThrow(()=> grid.LoadFromXaml<Grid> (xaml)); + Assert.AreEqual (1, grid.RowDefinitions.Count); + Assert.IsTrue (grid.RowDefinitions [0].Height.IsStar); + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1641.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1641.cs new file mode 100644 index 00000000..3809c16d --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1641.cs @@ -0,0 +1,38 @@ +using System; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class Issue1641 + { + [Test] + public void StaticResourceInTableView () + { + var xaml = @" + <ContentPage + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""> + <ContentPage.Resources> + <ResourceDictionary> + <x:String x:Key=""caption"" >Hello there!</x:String> + </ResourceDictionary> + </ContentPage.Resources> + + <TableView> + <TableRoot Title=""x""> + <TableSection Title=""y""> + <TextCell Text=""{StaticResource caption}"" /> + </TableSection> + </TableRoot> + </TableView> + </ContentPage>"; + var page = new ContentPage ().LoadFromXaml (xaml); + var table = page.Content as TableView; + Assert.AreEqual ("Hello there!", page.Resources ["caption"] as string); + Assert.AreEqual ("Hello there!", (table.Root [0] [0] as TextCell).Text); + + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1794.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1794.cs new file mode 100644 index 00000000..d0b6eb96 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1794.cs @@ -0,0 +1,58 @@ +using System; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class Issue1794 + { + [Test] + public void FindNameInDT () + { + var xaml = @"<?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:XamarinFormsXamlSample;assembly=XamarinFormsXamlSample"" + xmlns:constants=""clr-namespace:XamarinFormsSample;assembly=XamarinFormsXamlSample"" + x:Class=""UxDemoAppXF.Layouts.Menu"" + Title=""Employee List""> + + <ListView x:Name=""listView"" + IsVisible=""true"" + ItemsSource=""{Binding MenuItems}"" + SelectedItem=""{Binding ListItemSelected}""> + + <ListView.ItemTemplate> + <DataTemplate> + <ViewCell> + <RelativeLayout> + <Label x:Name=""LinkText"" + Text=""{Binding Name}"" + RelativeLayout.XConstraint= + ""{ConstraintExpression Type=RelativeToParent, + Property=Width, + Factor=0.5}""/> + <Image x:Name=""LinkImage"" + Source=""{Binding ImageSource}"" + RelativeLayout.XConstraint= + ""{ConstraintExpression Type=RelativeToView, + Property=Width, + ElementName=LinkText, + Constant=5}""/> + + + </RelativeLayout> + </ViewCell> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> + </ContentPage>"; + var layout = new ContentPage ().LoadFromXaml (xaml); + var list = layout.FindByName<ListView> ("listView"); + var item0 = list.TemplatedItems.GetOrCreateContent (0, null); + var item1 = list.TemplatedItems.GetOrCreateContent (1, null); + Assert.Pass (); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2016.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2016.xaml new file mode 100644 index 00000000..012427cd --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2016.xaml @@ -0,0 +1,25 @@ +<?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.Issue2016"> + <StackLayout> + <Switch x:Name="a0" /> + <Switch x:Name="b0" /> + <Switch x:Name="s0"> + <Switch.Triggers> + <MultiTrigger TargetType="Switch"> + <MultiTrigger.Conditions> + <BindingCondition Binding="{Binding Source={x:Reference a0}, Path=IsToggled}" Value="True" /> + <BindingCondition Binding="{Binding Source={x:Reference b0}, Path=IsToggled}" Value="True" /> + </MultiTrigger.Conditions> + <Setter Property="Switch.IsToggled" Value="True" /> + </MultiTrigger> + </Switch.Triggers> + </Switch> + <Switch x:Name="t0"> + <Switch.Triggers> + <DataTrigger TargetType="Switch" Binding="{Binding Source={x:Reference a0}, Path=IsToggled}" Value="True"> + <Setter Property="Switch.IsToggled" Value="True" /> + </DataTrigger> + </Switch.Triggers> + </Switch> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2016.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2016.xaml.cs new file mode 100644 index 00000000..89c6964f --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2016.xaml.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue2016 : ContentPage + { + public Issue2016 () + { + InitializeComponent (); + } + + public Issue2016 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [SetUp] + public void Setup () + { + Device.PlatformServices = new MockPlatformServices (); + } + + [TestCase (false)] + [TestCase (true)] + public void TestSwitches (bool useCompiledXaml) + { + var page = new Issue2016 (useCompiledXaml); + Assert.AreEqual (false, page.a0.IsToggled); + Assert.AreEqual (false, page.b0.IsToggled); + Assert.AreEqual (false, page.s0.IsToggled); + Assert.AreEqual (false, page.t0.IsToggled); + + page.a0.IsToggled = true; + page.b0.IsToggled = true; + + Assert.AreEqual (true, page.s0.IsToggled); + Assert.AreEqual (true, page.t0.IsToggled); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2062.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2062.xaml new file mode 100644 index 00000000..e756d4a5 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2062.xaml @@ -0,0 +1,12 @@ +<?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.Issue2062"> + <StackLayout> + <Label x:Name="label1"> + <Label.Text>text explicitly set to Label.Text</Label.Text> + </Label> + <Label x:Name="label2">text implicitly set to Text property of Label</Label> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2062.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2062.xaml.cs new file mode 100644 index 00000000..ff756756 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2062.xaml.cs @@ -0,0 +1,32 @@ +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue2062 : ContentPage + { + public Issue2062 () + { + InitializeComponent (); + } + + public Issue2062 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void LabelWithoutExplicitPropertyElement (bool useCompiledXaml) + { + var layout = new Issue2062 (useCompiledXaml); + Assert.AreEqual ("text explicitly set to Label.Text", layout.label1.Text); + Assert.AreEqual ("text implicitly set to Text property of Label", layout.label2.Text); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2114.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2114.xaml new file mode 100644 index 00000000..8a6917dc --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2114.xaml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Application + xmlns="http://xamarin.com/schemas/2014/forms" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + x:Class="Xamarin.Forms.Xaml.UnitTests.Issue2114" + > + <Application.Resources> + <ResourceDictionary> + <!-- buttons --> + <Style x:Key="ButtonStyle" TargetType="Button"> + <Setter Property="BorderRadius" Value="0"/> + <Setter Property="HeightRequest" Value="42"/> + </Style> + <Style x:Key="NavButtonBlueStyle" BasedOn="{StaticResource ButtonStyle}" TargetType="Button"> + </Style> + <Style x:Key="NavButtonGrayStyle" BasedOn="{StaticResource ButtonStyle}" TargetType="Button"> + </Style> + </ResourceDictionary> + </Application.Resources> +</Application>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2114.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2114.xaml.cs new file mode 100644 index 00000000..66aeac54 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2114.xaml.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using Xamarin.Forms; + +using NUnit.Framework; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue2114 : Application + { + public Issue2114 () + { + InitializeComponent (); + } + + public Issue2114 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void SetUp () + { + Device.PlatformServices = new MockPlatformServices (); + + Current = null; + } + + [TestCase (false)] + [TestCase (true)] + public void StaticResourceOnApplication (bool useCompiledXaml) + { + Issue2114 app; + Assert.DoesNotThrow (() => app = new Issue2114 (useCompiledXaml)); + + Assert.True (Current.Resources.ContainsKey ("ButtonStyle")); + Assert.True (Current.Resources.ContainsKey ("NavButtonBlueStyle")); + Assert.True (Current.Resources.ContainsKey ("NavButtonGrayStyle")); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2125.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2125.xaml new file mode 100644 index 00000000..c2bc239c --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2125.xaml @@ -0,0 +1,7 @@ +<?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.Issue2125"> + <StackLayout> + <Label x:Name="label"/> + <Label x:Name="label"/> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2125.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2125.xaml.cs new file mode 100644 index 00000000..8c4dcf80 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2125.xaml.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue2125 : ContentPage + { + public Issue2125 () + { + InitializeComponent (); + } + + public Issue2125 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void DuplicatexName (bool useCompiledXaml) + { + Assert.Throws (new XamlParseExceptionConstraint (5, 10), () => new Issue2125 (useCompiledXaml)); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2152.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2152.xaml new file mode 100644 index 00000000..4614fafb --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2152.xaml @@ -0,0 +1,15 @@ +<?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.Issue2152"> + <ListView ItemsSource="{Binding MyItems}" x:Name="listview"> + <ListView.ItemTemplate> + <DataTemplate> + <ViewCell> + <StackLayout Orientation="Horizontal"> + <Label Text="{Binding Reference}"/> + <Button Clicked="OnButtonClicked" Text=">>>" IsVisible="{Binding ShowButton}" x:Name="btn" /> + </StackLayout> + </ViewCell> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2152.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2152.xaml.cs new file mode 100644 index 00000000..7062074a --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2152.xaml.cs @@ -0,0 +1,52 @@ +using System; + +using Xamarin.Forms; + +using NUnit.Framework; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue2152 : ContentPage + { + public Issue2152 () + { + InitializeComponent (); + } + + public Issue2152 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + int clickcount; + public void OnButtonClicked(object sender, EventArgs e) + { + clickcount++; + } + + [TestFixture] + public class Tests + { + [SetUp] + public void Setup () + { + Device.PlatformServices = new MockPlatformServices (); + } + + [TestCase (false)] + [TestCase (true)] + public void TestEventConnection (bool useCompiledXaml) + { + Issue2152 layout = null; + Assert.DoesNotThrow (() => layout = new Issue2152 (useCompiledXaml)); + Cell cell = null; + Assert.DoesNotThrow (() => cell = layout.listview.TemplatedItems.GetOrCreateContent (0, null)); + var button = cell.FindByName<Button> ("btn") as IButtonController; + Assert.AreEqual (0, layout.clickcount); + button.SendClicked (); + Assert.AreEqual (1, layout.clickcount); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2450.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2450.xaml new file mode 100644 index 00000000..385619e5 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2450.xaml @@ -0,0 +1,10 @@ +<?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.Issue2450"> + <StackLayout> + <Label x:Name="label0"/> + <Label x:Name="label0"/> + </StackLayout> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2450.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2450.xaml.cs new file mode 100644 index 00000000..0cf6f56c --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2450.xaml.cs @@ -0,0 +1,37 @@ +using Xamarin.Forms; + +using NUnit.Framework; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue2450 : ContentPage + { + public Issue2450 () + { + InitializeComponent (); + } + + public Issue2450 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void Setup () + { + Device.PlatformServices = new MockPlatformServices (); + } + + [TestCase (false)] + [TestCase (true)] + public void ThrowMeaningfulExceptionOnDuplicateXName (bool useCompiledXaml) + { + Assert.Throws (new XamlParseExceptionConstraint (8, 10, m => m == "An element with the name \"label0\" already exists in this NameScope"), () => new Issue2450 (useCompiledXaml)); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2489.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2489.xaml new file mode 100644 index 00000000..58629e6e --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2489.xaml @@ -0,0 +1,17 @@ +<?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;assembly=Xamarin.Forms.Xaml.UnitTests" + x:Class="Xamarin.Forms.Xaml.UnitTests.Issue2489"> + <local:WImage Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" HeightRequest="150" x:Name="wimage"> + <local:WImage.Source> + <UriImageSource Uri="{Binding ImageUrl}" /> + </local:WImage.Source> + <local:WImage.Triggers> + <DataTrigger TargetType="{x:Type local:WImage}" Binding="{Binding ImageUrl}" Value="{x:Null}" > + <Setter Property="IsVisible" Value="False" /> + </DataTrigger> + </local:WImage.Triggers> + </local:WImage> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2489.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2489.xaml.cs new file mode 100644 index 00000000..ad79298e --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2489.xaml.cs @@ -0,0 +1,53 @@ +using System; +using System.Linq; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue2489 : ContentPage + { + public Issue2489 () + { + InitializeComponent (); + } + + public Issue2489 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void SetUp () + { + Device.PlatformServices = new MockPlatformServices (); + } + + [TestCase (false)] + [TestCase (true)] + public void DataTriggerTargetType (bool useCompiledXaml) + { + var layout = new Issue2489 (useCompiledXaml); + Assert.NotNull (layout.wimage); + Assert.NotNull (layout.wimage.Triggers); + Assert.True (layout.wimage.Triggers.Any ()); + Assert.That (layout.wimage.Triggers [0], Is.TypeOf<DataTrigger> ()); + var trigger = (DataTrigger)layout.wimage.Triggers [0]; + Assert.AreEqual (typeof(WImage), trigger.TargetType); + } + } + } + + public class WImage: View + { + public ImageSource Source { get; set; } + public Aspect Aspect { get; set; } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2578.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2578.xaml new file mode 100644 index 00000000..cedfbc83 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2578.xaml @@ -0,0 +1,21 @@ +<?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.Issue2578"> + <ContentPage.Resources> + <ResourceDictionary> + <Style x:Key="labelStyle" TargetType="Label"> + <Style.Triggers> + <Trigger Property="Text" TargetType="Label" Value="Foo"> + <Setter Property="BackgroundColor" Value="Red" /> + </Trigger> + <Trigger Property="Font" TargetType="Label" Value="Small"> + <Setter Property="TextColor" Value="Olive" /> + </Trigger> + </Style.Triggers> + </Style> + </ResourceDictionary> + </ContentPage.Resources> + <Label x:Name="label" Font="Small" Style="{StaticResource labelStyle}" /> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2578.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2578.xaml.cs new file mode 100644 index 00000000..62e54cd7 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2578.xaml.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue2578 : ContentPage + { + public Issue2578 () + { + InitializeComponent (); + } + + public Issue2578 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void Setup () + { + Device.PlatformServices = new MockPlatformServices (); + } + + [TestCase (false)] + [TestCase (true)] + public void MultipleTriggers (bool useCompiledXaml) + { + Issue2578 layout = null; + Assert.DoesNotThrow (() => layout = new Issue2578 (useCompiledXaml)); + + Assert.AreEqual (null, layout.label.Text); + Assert.AreEqual (Color.Default, layout.label.BackgroundColor); + Assert.AreEqual (Color.Olive, layout.label.TextColor); + layout.label.Text = "Foo"; + Assert.AreEqual (Color.Red, layout.label.BackgroundColor); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2659.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2659.xaml new file mode 100644 index 00000000..6e292469 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2659.xaml @@ -0,0 +1,34 @@ +<?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.Issue2659"> + <ContentPage.Resources> + <ResourceDictionary> + <Style x:Key="buttonStyle" TargetType="Button"> + <Setter Property="HorizontalOptions" Value="Center" /> + <Setter Property="VerticalOptions" Value="CenterAndExpand" /> + <Setter Property="FontSize" Value="Large" /> + <Setter Property="TextColor" Value="Blue" /> + <Setter Property="FontAttributes" Value="Italic" /> + </Style> + </ResourceDictionary> + </ContentPage.Resources> + + <StackLayout x:Name="stackLayout"> + <Button Text="Set Style from Resource" + Clicked="OnSetStyleButtonClicked" + x:Name="button0"/> + + <Button Text="Set Style to null" + Clicked="OnUnsetStyleButtonClicked" + x:Name="button1"/> + + <Button Text="Set Local Properties" + Clicked="OnSetLocalButtonClicked" + x:Name="button2"/> + + <Button Text="Clear Local Properties" + Clicked="OnClearLocalButtonClicked" + x:Name="button3"/> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2659.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2659.xaml.cs new file mode 100644 index 00000000..8372c50d --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2659.xaml.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue2659 : ContentPage + { + public Issue2659 () + { + InitializeComponent (); + } + + public Issue2659 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + void OnSetStyleButtonClicked(object sender, EventArgs args) + { + Style style = (Style)Resources["buttonStyle"]; + SetButtonStyle(style); + } + + void OnUnsetStyleButtonClicked(object sender, EventArgs args) + { + SetButtonStyle (null); + } + + void OnSetLocalButtonClicked(object sender, EventArgs args) + { + EnumerateButtons ((Button button) => { + button.TextColor = Color.Red; + button.FontAttributes = FontAttributes.Bold; + }); + } + + void OnClearLocalButtonClicked(object sender, EventArgs args) + { + EnumerateButtons ((Button button) => { + button.ClearValue (Button.TextColorProperty); + button.ClearValue (Button.FontAttributesProperty); + }); + } + + void SetButtonStyle(Style style) + { + EnumerateButtons (button => { + button.Style = style; + }); + } + + void EnumerateButtons(Action<Button> action) + { + foreach (View view in stackLayout.Children) + action ((Button)view); + } + + [TestFixture] + public class Tests + { + [SetUp] + public void SetUp () + { + Device.PlatformServices = new MockPlatformServices (); + } + + void AssertStyleApplied (Button button) + { + Assert.AreEqual (LayoutOptions.Center, button.HorizontalOptions); + Assert.AreEqual (LayoutOptions.CenterAndExpand, button.VerticalOptions); + Assert.AreEqual (16, button.FontSize); + Assert.AreEqual (Color.Blue, button.TextColor); + Assert.AreEqual (FontAttributes.Italic, button.FontAttributes); + } + + void AssertStyleUnApplied (Button button) + { + Assert.AreEqual (View.HorizontalOptionsProperty.DefaultValue, button.HorizontalOptions); + Assert.AreEqual (View.VerticalOptionsProperty.DefaultValue, button.VerticalOptions); + Assert.AreEqual (10, button.FontSize); + Assert.AreEqual (Button.TextColorProperty.DefaultValue, button.TextColor); + Assert.AreEqual (Button.FontAttributesProperty.DefaultValue, button.FontAttributes); + } + + [TestCase (false)] + [TestCase (true)] + public void SetUnsetStyleFromResource (bool useCompiledXaml) + { + var layout = new Issue2659 (useCompiledXaml); + layout.EnumerateButtons (AssertStyleUnApplied); + + ((IButtonController)layout.button0).SendClicked (); + layout.EnumerateButtons (AssertStyleApplied); + + ((IButtonController)layout.button1).SendClicked (); + layout.EnumerateButtons (AssertStyleUnApplied); + } + + void AssertPropertiesApplied (Button button) + { + Assert.AreEqual (Color.Red, button.TextColor); + Assert.AreEqual (FontAttributes.Bold, button.FontAttributes); + } + + void AssertPropertiesUnApplied (Button button) + { + Assert.AreEqual (Button.TextColorProperty.DefaultValue, button.TextColor); + Assert.AreEqual (Button.FontAttributesProperty.DefaultValue, button.FontAttributes); + } + + [TestCase (false)] + [TestCase (true)] + public void SetUnsetLocalProperties (bool useCompiledXaml) + { + var layout = new Issue2659 (useCompiledXaml); + layout.EnumerateButtons (AssertPropertiesUnApplied); + + ((IButtonController)layout.button2).SendClicked (); + layout.EnumerateButtons (AssertPropertiesApplied); + + ((IButtonController)layout.button3).SendClicked (); + layout.EnumerateButtons (AssertPropertiesUnApplied); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2742.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2742.xaml new file mode 100644 index 00000000..d4dc6fc6 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2742.xaml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<local:Issue2742BasePage 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.Issue2742"> + <ContentPage.ToolbarItems> + <ToolbarItem Name="One"></ToolbarItem> + <ToolbarItem Name="Two"></ToolbarItem> + </ContentPage.ToolbarItems> + <ContentPage.Content> + <Label Text="test"></Label> + </ContentPage.Content> +</local:Issue2742BasePage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2742.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2742.xaml.cs new file mode 100644 index 00000000..ba69280d --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue2742.xaml.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class Issue2742BasePage : ContentPage + { + + } + + public partial class Issue2742 : Issue2742BasePage + { + public Issue2742 () + { + InitializeComponent (); + } + + public Issue2742 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void ToolBarItemsOnContentPageInheritors (bool useCompiledXaml) + { + var layout = new Issue2742 (useCompiledXaml); + Assert.That (layout.Content, Is.TypeOf<Label> ()); + Assert.AreEqual ("test", ((Label)layout.Content).Text); + + Assert.NotNull (layout.ToolbarItems); + Assert.AreEqual (2, layout.ToolbarItems.Count); + Assert.AreEqual ("One", layout.ToolbarItems [0].Name); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3076.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3076.xaml new file mode 100644 index 00000000..61e25f04 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3076.xaml @@ -0,0 +1,11 @@ +<?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" + xmlns:controls="clr-namespace:Xamarin.Forms.Controls;assembly=Xamarin.Forms.Controls" + x:Class="Xamarin.Forms.Xaml.UnitTests.Issue3076"> + <StackLayout> + <local:Issue3076Button VerticalContentAlignment="Start" x:Name="local"/> + <controls:Issue3076Button HorizontalContentAlignment="Start" x:Name="controls" /> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3076.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3076.xaml.cs new file mode 100644 index 00000000..e44a1349 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3076.xaml.cs @@ -0,0 +1,55 @@ +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class Issue3076Button : Button + { + public static readonly BindableProperty VerticalContentAlignmentProperty = + BindableProperty.Create ("VerticalContentAlignemnt", typeof(TextAlignment), typeof(Issue3076Button), TextAlignment.Center); + + public TextAlignment VerticalContentAlignment + { + get { return (TextAlignment)GetValue (VerticalContentAlignmentProperty); } + set { SetValue (VerticalContentAlignmentProperty, value); } + } + } + + public partial class Issue3076 : ContentPage + { + public Issue3076 () + { + InitializeComponent (); + } + + public Issue3076 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void CanUseBindableObjectDefinedInThisAssembly (bool useCompiledXaml) + { + var layout = new Issue3076 (useCompiledXaml); + + Assert.That (layout.local, Is.TypeOf<Issue3076Button> ()); + Assert.AreEqual (TextAlignment.Start, layout.local.VerticalContentAlignment); + } + + [TestCase (false)] + [TestCase (true)] + public void CanUseBindableObjectDefinedInOtherAssembly (bool useCompiledXaml) + { + var layout = new Issue3076 (useCompiledXaml); + + Assert.That (layout.controls, Is.TypeOf<Controls.Issue3076Button> ()); + Assert.AreEqual (TextAlignment.Start, layout.controls.HorizontalContentAlignment); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3090.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3090.xaml new file mode 100644 index 00000000..4a171913 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3090.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.Issue3090"> + <AbsoluteLayout > + <Label AbsoluteLayout.LayoutBounds="0, 0, 1, 1" /> + </AbsoluteLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3090.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3090.xaml.cs new file mode 100644 index 00000000..8fc37994 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3090.xaml.cs @@ -0,0 +1,30 @@ +using NUnit.Framework; + +using Xamarin.Forms; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue3090 : ContentPage + { + public Issue3090 () + { + InitializeComponent (); + } + + public Issue3090 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void NewDoesNotThrow (bool useCompiledXaml) + { + var p = new Issue3090 (useCompiledXaml); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3106.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3106.xaml new file mode 100644 index 00000000..fe48c730 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3106.xaml @@ -0,0 +1,35 @@ +<?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.Issue3106"> + <ContentPage.Content> + <TableView HasUnevenRows="true"> + <TableView.Root> + <TableSection Title="TextCell Disable"> + <TextCell Text="txtCellDisable1" Detail="test" IsEnabled="false" /> + <TextCell Text="txtCellDisable2" Height="25" IsEnabled="false" /> + </TableSection> + <TableSection Title="TextCell Enable"> + <TextCell Text="txtCellEnable1" Detail="test" IsEnabled="true" /> + <TextCell Text="txtCellEnable2" Height="25" IsEnabled="true" /> + </TableSection> + <TableSection Title="TextCell ContextActions Disable"> + <TextCell Text="txtCellDisableContextActions1" Detail="test" IsEnabled="false"> + <TextCell.ContextActions> + <MenuItem Command="{Binding MoreCommand}" Text="More" /> + <MenuItem Command="{Binding DeleteCommand}" Text="Delete" /> + </TextCell.ContextActions> + </TextCell> + </TableSection> + <TableSection Title="TextCell ContextActions Enable"> + <TextCell Text="txtCellEnabledContextActions1" Detail="test" IsEnabled="true"> + <TextCell.ContextActions> + <MenuItem Command="{Binding MoreCommand}" Text="More" /> + <MenuItem Command="{Binding DeleteCommand}" Text="Delete" IsDestructive="true" /> + </TextCell.ContextActions> + </TextCell> + </TableSection> + </TableView.Root> + </TableView> + </ContentPage.Content> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3106.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3106.xaml.cs new file mode 100644 index 00000000..f2e8a641 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue3106.xaml.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Issue3106 : ContentPage + { + public Issue3106 () + { + InitializeComponent (); + } + public Issue3106 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void NewDoesNotThrow (bool useCompiledXaml) + { + var p = new Issue3106 (useCompiledXaml); + } + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Pr3384.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Pr3384.xaml new file mode 100644 index 00000000..24d0842b --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Pr3384.xaml @@ -0,0 +1,7 @@ +<?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.Pr3384"> + <ListView x:Name="listView" + CachingStrategy="RecycleElement" /> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Pr3384.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Pr3384.xaml.cs new file mode 100644 index 00000000..ebf3fe18 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Pr3384.xaml.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Pr3384 : ContentPage + { + public Pr3384 () + { + InitializeComponent (); + } + + public Pr3384 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void SetUp () + { + Device.OS = TargetPlatform.iOS; + } + + [TestCase (false)] + [TestCase (true)] + public void RecyclingStrategyIsHandled (bool useCompiledXaml) + { + var p = new Pr3384 (useCompiledXaml); + Assert.AreEqual (ListViewCachingStrategy.RecycleElement, p.listView.CachingStrategy); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/TestCases.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/TestCases.cs new file mode 100644 index 00000000..ba3c2c2f --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/TestCases.cs @@ -0,0 +1,212 @@ +using System; +using System.Linq; +using NUnit.Framework; +using System.Collections.Generic; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class BasePage : ContentPage + { + + } + + [TestFixture] + public class TestCases + { + [SetUp] + public void Setup () + { + Device.PlatformServices = new MockPlatformServices (); + } + + [TearDown] + public void Teardown () + { + Device.PlatformServices = null; + } + + public static readonly BindableProperty InnerViewProperty = + BindableProperty.CreateAttached<TestCases, View> (bindable => GetInnerView (bindable), default(View)); + + public static View GetInnerView (BindableObject bindable) + { + return (View)bindable.GetValue (InnerViewProperty); + } + + public static void SetInnerView (BindableObject bindable, View value) + { + bindable.SetValue (InnerViewProperty, value); + } + + [Test] + public void TestCase001 () + { + var xaml = @"<?xml version=""1.0"" encoding=""UTF-8"" ?> + <ContentPage + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" + Title=""Home""> + <local:TestCases.InnerView> + <Label x:Name=""innerView""/> + </local:TestCases.InnerView> + <ContentPage.Content> + <Grid RowSpacing=""9"" ColumnSpacing=""6"" Padding=""6,9"" VerticalOptions=""Fill"" HorizontalOptions=""Fill"" BackgroundColor=""Red""> + <Grid.Children> + <Label x:Name=""label0""/> + <Label x:Name=""label1""/> + <Label x:Name=""label2""/> + <Label x:Name=""label3""/> + </Grid.Children> + </Grid> + </ContentPage.Content> + </ContentPage>"; + var contentPage = new ContentPage ().LoadFromXaml (xaml); + var label0 = contentPage.FindByName<Label> ("label0"); + var label1 = contentPage.FindByName<Label> ("label1"); + + Assert.NotNull (GetInnerView (contentPage)); +// Assert.AreEqual ("innerView", GetInnerView (contentPage).Name); + Assert.AreEqual (GetInnerView (contentPage), ((Forms.Internals.INameScope)contentPage).FindByName ("innerView")); + Assert.NotNull (label0); + Assert.NotNull (label1); + Assert.AreEqual (4, contentPage.Content.Descendants ().Count ()); + } + + + [Test] + public void TestCase002 () + { + var xaml = @"<?xml version=""1.0"" encoding=""UTF-8"" ?> + <local:BasePage + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" + x:Class=""Tramchester.App.Views.HomeView""> + <local:BasePage.Content> + <Label Text=""Hi There!"" /> + </local:BasePage.Content> + </local:BasePage>"; + var contentPage = new ContentPage ().LoadFromXaml (xaml); + Assert.That (contentPage.Content, Is.InstanceOf<Label> ()); + } + + [Test] + public void TestCase003 () + { + var xaml = @"<?xml version=""1.0"" encoding=""UTF-8"" ?> + <ContentPage + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + Title=""People""> + + <StackLayout Spacing=""0""> + <SearchBar x:Name=""searchBar""/> + <ListView ItemsSource=""{Binding Path=.}"" RowHeight=""42"" x:Name=""listview""> + <ListView.ItemTemplate> + <DataTemplate> + <ViewCell> + <ViewCell.View> + <StackLayout Orientation=""Horizontal"" HorizontalOptions=""FillAndExpand"" VerticalOptions=""CenterAndExpand"" BackgroundColor=""#fff4f4f4""> + <BoxView WidthRequest=""10""/> + <Grid WidthRequest=""42"" HeightRequest=""32"" VerticalOptions=""CenterAndExpand"" HorizontalOptions=""Start""> + <Image WidthRequest=""32"" HeightRequest=""32"" Aspect=""AspectFill"" HorizontalOptions=""FillAndExpand"" Source=""Images/icone_nopic_members_42.png""/> + <!--<Image WidthRequest=""32"" HeightRequest=""32"" Aspect=""AspectFill"" HorizontalOptions=""FillAndExpand""> + <Image.Source> + <UriImageSource Uri=""{Binding Picture}"" CacheValidity=""30""/> + </Image.Source> + </Image>--> + <Image Source=""Images/cropcircle.png"" HorizontalOptions=""FillAndExpand"" VerticalOptions=""FillAndExpand"" WidthRequest=""32"" HeightRequest=""32"" Aspect=""Fill""/> + </Grid> + <Label Text=""{Binding FirstName}"" VerticalOptions=""CenterAndExpand""/> + <Label Text=""{Binding LastName}"" Font=""HelveticaNeue-Bold, Medium"" VerticalOptions=""CenterAndExpand"" /> + </StackLayout> + </ViewCell.View> + </ViewCell> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> + </StackLayout> + </ContentPage>"; + var page = new ContentPage ().LoadFromXaml (xaml); + var model = new List<object> { + new {FirstName = "John", LastName="Lennon", Picture="http://www.johnlennon.com/wp-content/themes/jl/images/home-gallery/2.jpg"}, + new {FirstName = "Paul", LastName="McCartney", Picture="http://t0.gstatic.com/images?q=tbn:ANd9GcRjNUGJ00Mt85n2XDu8CZM0w1em0Wv4ZaemLuIVmLCMwPMOLUO1SQ"}, + new {FirstName = "George", LastName="Harisson", Picture="http://cdn.riffraf.net/wp-content/uploads/2013/02/george-harrison-living.jpg"}, + new {FirstName = "Ringo", LastName="Starr", Picture="http://www.biography.com/imported/images/Biography/Images/Profiles/S/Ringo-Starr-306872-1-402.jpg"}, + }; + page.BindingContext = model; + + var listview = page.FindByName<ListView> ("listview"); + Cell cell = null; + Assert.DoesNotThrow(() => { cell = listview.TemplatedItems[0]; }); + Assert.NotNull (cell); + Assert.That (cell, Is.TypeOf<ViewCell> ()); + Assert.AreSame (model [0], cell.BindingContext); + } + + [Test] + public void TestCase004 () + { + var xaml = @"<?xml version=""1.0"" encoding=""UTF-8"" ?> + <ContentPage + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> + <ContentPage.Content> + <ScrollView Orientation=""Horizontal""> + <ScrollView.Content> + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition /> + <ColumnDefinition /> + </Grid.ColumnDefinitions> + <Image Grid.Column=""0"" Grid.Row=""0"" Aspect=""AspectFill""> + <Image.Source> + <StreamImageSource Stream=""{Binding HeroPicture.Stream}"" /> + </Image.Source> + </Image> + </Grid> + </ScrollView.Content> + </ScrollView> + </ContentPage.Content> + </ContentPage>"; + + var page = new ContentPage (); + Assert.DoesNotThrow (()=> page.LoadFromXaml (xaml)); + } + + [Test] + public void Issue1415 () + { + var xaml = @"<?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;assembly=Xamarin.Forms.Xaml.UnitTests""> + <Label x:Name=""label"" Text=""{Binding Converter={x:Static local:ReverseConverter.Instance}, Mode=TwoWay}""/> + </ContentPage>"; + var page = new ContentPage ().LoadFromXaml (xaml); + var label = page.FindByName<Label> ("label"); + Assert.NotNull (label); + label.BindingContext = "foo"; + Assert.AreEqual ("oof", label.Text); + } + + [Test] + //only happens in european cultures + [SetCulture ("fr-FR")] + public void Issue1493 () + { + var xaml = @"<?xml version=""1.0"" encoding=""utf-8"" ?> + <View + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + RelativeLayout.HeightConstraint=""{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.25}"" + RelativeLayout.WidthConstraint=""{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.6}""/>"; + View view = new View (); + view.LoadFromXaml (xaml); + Assert.DoesNotThrow (() => view.LoadFromXaml (xaml)); + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported001.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported001.xaml new file mode 100644 index 00000000..a039f7f6 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported001.xaml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<TabbedPage 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.Unreported001"> + <NavigationPage Title="Test" x:Name="navpage"> + <x:Arguments> + <local:U001Page /> + </x:Arguments> + </NavigationPage> +</TabbedPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported001.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported001.xaml.cs new file mode 100644 index 00000000..d04ad467 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported001.xaml.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class U001Page : ContentPage + { + public U001Page () + { + ; + } + + } + + public partial class Unreported001 : TabbedPage + { + public Unreported001 () + { + InitializeComponent (); + } + + public Unreported001 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void DoesNotThrow (bool useCompiledXaml) + { + var p = new Unreported001 (useCompiledXaml); + Assert.That (p.navpage.CurrentPage, Is.TypeOf<U001Page> ()); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported002.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported002.xaml new file mode 100644 index 00000000..7785ae8c --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported002.xaml @@ -0,0 +1,7 @@ +<?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.Unreported002"> + <Label x:Name="label" + AbsoluteLayout.LayoutBounds="0.5,0.5,1,AutoSize" /> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported002.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported002.xaml.cs new file mode 100644 index 00000000..23f24044 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported002.xaml.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Unreported002 : ContentPage + { + public Unreported002 () + { + InitializeComponent (); + } + + public Unreported002 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void TypeConvertersOnAttachedBP (bool useCompiledXaml) + { + var p = new Unreported002 (useCompiledXaml); + Assert.AreEqual (new Rectangle (0.5, 0.5, 1, -1), AbsoluteLayout.GetLayoutBounds (p.label)); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported003.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported003.xaml new file mode 100644 index 00000000..b8db54b3 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported003.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" + xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps" + x:Class="Xamarin.Forms.Xaml.UnitTests.Unreported003" > + <maps:Map x:Name="map"> + <x:Arguments> + <maps:MapSpan> + <x:Arguments> + <!-- These coordinates land near Red Deer at a fairly high altitude (birds eye view). --> + <maps:Position> + <x:Arguments> + <!-- Latitude--> + <x:Double>52.325</x:Double> + <!-- Longitude--> + <x:Double>-113.9</x:Double> + </x:Arguments> + </maps:Position> + <!-- Elevation lat/long--> + <x:Double>.8</x:Double> + <x:Double>.8</x:Double> + </x:Arguments> + </maps:MapSpan> + </x:Arguments> + </maps:Map> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported003.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported003.xaml.cs new file mode 100644 index 00000000..ebe78bc4 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported003.xaml.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Unreported003 : ContentPage + { + public Unreported003 () + { + InitializeComponent (); + } + + public Unreported003 (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [TestCase(true), TestCase(false)] + public void AllowCtorArgsForValueTypes (bool useCompiledXaml) + { + var page = new Unreported003 (useCompiledXaml); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/LoaderTests.cs b/Xamarin.Forms.Xaml.UnitTests/LoaderTests.cs new file mode 100644 index 00000000..76817335 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/LoaderTests.cs @@ -0,0 +1,808 @@ +using NUnit.Framework; +using System.Linq; +using System; +using System.Collections.Generic; + +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [ContentProperty ("Content")] + public class CustomView : View + { + public string NotBindable { get; set; } + + public View Content { get; set; } + + public MockFlags MockFlags { get; set; } + } + + [ContentProperty ("Children")] + public class ViewWithChildrenContent : View + { + public ViewWithChildrenContent () + { + Children = DefaultChildren = new ViewList (); + } + public ViewList DefaultChildren; + public ViewList Children { get; set; } + } + + public class ViewList : List<View> + { + + } + + public class ReverseConverter : IValueConverter + { + public static ReverseConverter Instance = new ReverseConverter (); + + public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + var s = value as string; + if (s == null) + return value; + return new string (s.Reverse ().ToArray ()); + } + + public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + var s = value as string; + if (s == null) + return value; + return new string (s.Reverse ().ToArray ()); + } + } + + public class Catalog + { + public static readonly BindableProperty MessageProperty = + BindableProperty.CreateAttached<Catalog, string> (bindable => GetMessage (bindable), default(string), + propertyChanged: (bindable, oldvalue, newvalue) => { + var label = bindable as Label; + if (label != null) + label.SetValue (Label.TextProperty, new string (newvalue.Reverse ().ToArray ())); + }); + + public static string GetMessage (BindableObject bindable) + { + return (string)bindable.GetValue (MessageProperty); + } + + public static void SetMessage (BindableObject bindable, string value) + { + bindable.SetValue (MessageProperty, value); + } + } + + [Flags] + public enum MockFlags + { + Foo = 1<<0, + Bar = 1<<1, + Baz = 1<<2, + Qux = 1<<3, + } + + + [TestFixture] + public class LoaderTests : BaseTestFixture + { + [Test] + public void TestRootName () + { + var xaml = @" + <View + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + x:Class=""Xamarin.Forms.Xaml.UnitTests.CustomView"" + x:Name=""customView"" + />"; + + var view = new CustomView (); + view.LoadFromXaml (xaml); + + Assert.AreSame (view, ((Forms.Internals.INameScope)view).FindByName("customView")); + } + + [Test] + public void TestFindByXName () + { + var xaml = @" + <StackLayout + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> + <StackLayout.Children> + <Label x:Name=""label0"" Text=""Foo""/> + </StackLayout.Children> + </StackLayout>"; + + var stacklayout = new StackLayout (); + stacklayout.LoadFromXaml (xaml); + + var label = stacklayout.FindByName<Label> ("label0"); + Assert.NotNull (label); + Assert.AreEqual ("Foo", label.Text); + } + + [Test] + public void TestUnknownPropertyShouldThrow () + { + var xaml = @" + <Label + xmlns=""http://xamarin.com/schemas/2014/forms"" + Text=""Foo"" + UnknownProperty=""Bar"" + />"; + + var label = new Label (); + Assert.Throws (new XamlParseExceptionConstraint (5, 5), () => label.LoadFromXaml (xaml)); + } + + [Test] + public void TestSetValueToBindableProperty () + { + var xaml = @" + <Label + xmlns=""http://xamarin.com/schemas/2014/forms"" + Text=""Foo"" + />"; + + var label = new Label (); + + label.LoadFromXaml (xaml); + Assert.AreEqual ("Foo", label.Text); + + } + + [Test] + public void TestSetBindingToBindableProperty () + { + var xaml = @" + <Label + xmlns=""http://xamarin.com/schemas/2014/forms"" + Text=""{Binding Path=labeltext}"" + />"; + + var label = new Label (); + label.LoadFromXaml (xaml); + + Assert.AreEqual (Label.TextProperty.DefaultValue, label.Text); + + label.BindingContext = new {labeltext="Foo"}; + Assert.AreEqual ("Foo", label.Text); + } + + [Test] + public void TestBindingAsElement () + { + var xaml = @" + <Label + xmlns=""http://xamarin.com/schemas/2014/forms""> + <Label.Text> + <Binding Path=""labeltext""/> + </Label.Text> + </Label>"; + + var label = new Label (); + label.LoadFromXaml (xaml); + + Assert.AreEqual (Label.TextProperty.DefaultValue, label.Text); + + label.BindingContext = new {labeltext="Foo"}; + Assert.AreEqual ("Foo", label.Text); + + } + + [Test] + public void TestSetBindingToNonBindablePropertyShouldThrow () + { + var xaml = @" + <View + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + x:Class=""Xamarin.Forms.Xaml.UnitTests.CustomView"" + Name=""customView"" + NotBindable=""{Binding text}"" + />"; + + var view = new CustomView (); + Assert.Throws (new XamlParseExceptionConstraint (6, 5), () => view.LoadFromXaml (xaml)); + } + + [Test] + public void TestBindingPath () + { + var xaml = @" + <StackLayout + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> + <StackLayout.Children> + <Label x:Name=""label0"" Text=""{Binding text}""/> + <Label x:Name=""label1"" Text=""{Binding Path=text}""/> + </StackLayout.Children> + </StackLayout>"; + + var stacklayout = new StackLayout (); + stacklayout.LoadFromXaml (xaml); + + var label0 = stacklayout.FindByName<Label> ("label0"); + var label1 = stacklayout.FindByName<Label> ("label1"); + + Assert.AreEqual (Label.TextProperty.DefaultValue, label0.Text); + Assert.AreEqual (Label.TextProperty.DefaultValue, label1.Text); + + stacklayout.BindingContext = new {text = "Foo"}; + Assert.AreEqual ("Foo", label0.Text); + Assert.AreEqual ("Foo", label1.Text); + } + + + class ViewModel + { + public string Text { get; set; } + } + + [Test] + public void TestBindingModeAndConverter () + { + var xaml = @" + <ContentPage + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests""> + <ContentPage.Resources> + <ResourceDictionary> + <local:ReverseConverter x:Key=""reverseConverter""/> + </ResourceDictionary> + </ContentPage.Resources> + <ContentPage.Content> + <StackLayout Orientation=""Vertical""> + <StackLayout.Children> + <Label x:Name=""label0"" Text=""{Binding Text, Converter={StaticResource reverseConverter}}""/> + <Label x:Name=""label1"" Text=""{Binding Text, Mode=TwoWay}""/> + </StackLayout.Children> + </StackLayout> + </ContentPage.Content> + </ContentPage>"; + + var contentPage = new ContentPage (); + contentPage.LoadFromXaml (xaml); + contentPage.BindingContext = new ViewModel { Text = "foobar" }; + var label0 = contentPage.FindByName<Label> ("label0"); + var label1 = contentPage.FindByName<Label> ("label1"); + Assert.AreEqual ("raboof", label0.Text); + + label1.Text = "baz"; + Assert.AreEqual ("baz", ((ViewModel)(contentPage.BindingContext)).Text); + } + + [Test] + public void TestNonEmptyCollectionMembers () + { + var xaml = @" + <StackLayout + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> + <StackLayout.Children> + <Grid x:Name=""grid0""> + </Grid> + <Grid x:Name=""grid1""> + </Grid> + </StackLayout.Children> + </StackLayout>"; + + var stacklayout = new StackLayout (); + stacklayout.LoadFromXaml (xaml); + var grid0 = stacklayout.FindByName<Grid> ("grid0"); + var grid1 = stacklayout.FindByName<Grid> ("grid1"); + Assert.NotNull (grid0); + Assert.NotNull (grid1); + } + + [Test] + public void TestUnknownType () + { + var xaml = @" + <StackLayout + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> + <StackLayout.Children> + <CustomView /> + </StackLayout.Children> + </StackLayout>"; + + var stacklayout = new StackLayout (); + Assert.Throws (new XamlParseExceptionConstraint (6, 8), () => stacklayout.LoadFromXaml (xaml)); + } + + [Test] + public void TestResources () + { + var xaml = @" + <Label + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests""> + <Label.Resources> + <ResourceDictionary> + <local:ReverseConverter x:Key=""reverseConverter""/> + </ResourceDictionary> + </Label.Resources> + </Label>"; + + var label = new Label ().LoadFromXaml (xaml); + Assert.NotNull (label.Resources); + Assert.True (label.Resources.ContainsKey ("reverseConverter")); + Assert.True (label.Resources ["reverseConverter"] is ReverseConverter); + } + + [Test] + public void TestResourceDoesRequireKey () + { + var xaml = @" + <Label + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests""> + <Label.Resources> + <ResourceDictionary> + <local:ReverseConverter /> + </ResourceDictionary> + </Label.Resources> + </Label>"; + var label = new Label (); + Assert.Throws (new XamlParseExceptionConstraint (8, 9), () => label.LoadFromXaml (xaml)); + } + + [Test] + public void UseResourcesOutsideOfBinding () + { + var xaml = @" + <ContentView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> + <ContentView.Resources> + <ResourceDictionary> + <Label Text=""Foo"" x:Key=""bar""/> + </ResourceDictionary> + </ContentView.Resources> + <ContentView.Content> + <ContentView Content=""{StaticResource bar}""/> + </ContentView.Content> + </ContentView>"; + + var contentView = new ContentView ().LoadFromXaml (xaml); + Assert.AreEqual ("Foo", (((ContentView)(contentView.Content)).Content as Label).Text); + } + + [Test] + public void MissingStaticResourceShouldThrow () + { + var xaml = @"<Label Text=""{StaticResource foo}""/>"; + var label = new Label (); + Assert.Throws (new XamlParseExceptionConstraint (1, 8), () => label.LoadFromXaml (xaml)); + } + + public class CustView : Button + { + public bool fired = false; + public void onButtonClicked (object sender, EventArgs e) + { + fired = true; + } + + public void wrongSignature (bool a, string b) + { + } + } + + class MyApp : Application + { + public MyApp () + { + Resources = new ResourceDictionary { + {"foo", "FOO"}, + {"bar", "BAR"} + }; + } + } + + [Test] + public void StaticResourceLookForApplicationResources () + { + Device.PlatformServices = new MockPlatformServices (); + Application.Current = null; + + Application.Current = new MyApp (); + var xaml = @" + <ContentView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> + <ContentView.Resources> + <ResourceDictionary> + <x:String x:Key=""bar"">BAZ</x:String> + </ResourceDictionary> + </ContentView.Resources> + <StackLayout> + <Label x:Name=""label0"" Text=""{StaticResource foo}""/> + <Label x:Name=""label1"" Text=""{StaticResource bar}""/> + </StackLayout> + </ContentView>"; + var layout = new ContentView ().LoadFromXaml (xaml); + var label0 = layout.FindByName<Label> ("label0"); + var label1 = layout.FindByName<Label> ("label1"); + + //resource from App.Resources + Assert.AreEqual ("FOO", label0.Text); + + //local resources have precedence + Assert.AreEqual ("BAZ", label1.Text); + } + + [Test] + public void TestEvent () + { + var xaml = @" + <Button + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + x:Class=""Xamarin.Forms.Xaml.UnitTests.CustView"" Clicked=""onButtonClicked"" /> + </Button>"; + var view = new CustView (); + view.LoadFromXaml (xaml); + Assert.False (view.fired); + ((IButtonController) view).SendClicked (); + Assert.True (view.fired); + } + + [Test] + public void TestFailingEvent () + { + var xaml = @" + <View + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + x:Class=""Xamarin.Forms.Xaml.UnitTests.CustView"" Activated=""missingMethod"" /> + </View>"; + var view = new CustView (); + Assert.Throws (new XamlParseExceptionConstraint (5, 53), () => view.LoadFromXaml (xaml)); + } + + [Test] + public void TestConnectingEventOnMethodWithWrongSignature () + { + var xaml = @" + <View + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + x:Class=""Xamarin.Forms.Xaml.UnitTests.CustView"" Activated=""wrongSignature"" /> + </View>"; + var view = new CustView (); + + Assert.Throws (new XamlParseExceptionConstraint (5, 53), () => view.LoadFromXaml (xaml)); + } + + + public class CustEntry : Entry + { + public bool fired = false; + public void onValueChanged (object sender, TextChangedEventArgs e) + { + fired = true; + } + + } + + [Test] + public void TestEventWithCustomEventArgs () + { + var xaml = @" + <Entry + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + x:Class=""Xamarin.Forms.Xaml.UnitTests.CustEntry"" TextChanged=""onValueChanged"" /> + </Entry>"; + var view = new CustEntry ().LoadFromXaml (xaml); + } + + [Test] + public void TestEmptyTemplate () + { + var xaml = @" + <ContentPage + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> + <ContentPage.Resources> + <ResourceDictionary> + <DataTemplate x:Key=""datatemplate""/> + </ResourceDictionary> + </ContentPage.Resources> + </ContentPage>"; + var page = new ContentPage (); + page.LoadFromXaml (xaml); + var template = page.Resources["datatemplate"]as Forms.DataTemplate; + Assert.Throws<InvalidOperationException>(() => template.CreateContent()); + } + + [Test] + public void TestBoolValue () + { + var xaml = @" + <Image + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + IsOpaque=""true""/>"; + + var image = new Image (); + Assert.AreEqual (Image.IsOpaqueProperty.DefaultValue, image.IsOpaque); + image.LoadFromXaml (xaml); + Assert.AreEqual (true, image.IsOpaque); + } + + [Test] + public void TestAttachedBP () + { + var xaml = @" + <View + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + Grid.Column=""1""> + <Grid.Row>2</Grid.Row> + </View>"; + var view = new View ().LoadFromXaml (xaml); + Assert.AreEqual (1, Grid.GetColumn (view)); + Assert.AreEqual (2, Grid.GetRow (view)); + } + + [Test] + public void TestAttachedBPWithDifferentNS () + { + //If this looks very similar to Vernacular, well... it's on purpose :) + var xaml = @" + <Label + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" + local:Catalog.Message=""foobar""/>"; + var label = new Label ().LoadFromXaml (xaml); + Assert.AreEqual ("raboof", label.Text); + } + + [Test] + public void TestBindOnAttachedBP () + { + var xaml = @" + <Label + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" + local:Catalog.Message=""{Binding .}""/>"; + var label = new Label ().LoadFromXaml (xaml); + label.BindingContext = "foobar"; + Assert.AreEqual ("raboof", label.Text); + } + + [Test] + public void TestContentProperties () + { + var xaml = @" + <local:CustomView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" > + <Label x:Name=""contentview""/> + </local:CustomView>"; + CustomView customView = null; + Assert.DoesNotThrow(()=> customView = new CustomView ().LoadFromXaml (xaml)); + Assert.NotNull (customView.Content); + Assert.AreSame (customView.Content, ((Forms.Internals.INameScope)customView).FindByName("contentview")); + } + + [Test] + public void TestCollectionContentProperties () + { + var xaml = @" + <StackLayout> + <Label Text=""Foo""/> + <Label Text=""Bar""/> + </StackLayout>"; + var layout = new StackLayout ().LoadFromXaml (xaml); + Assert.AreEqual (2, layout.Children.Count); + Assert.AreEqual ("Foo", ((Label)(layout.Children [0])).Text); + Assert.AreEqual ("Bar", ((Label)(layout.Children [1])).Text); + } + + [Test] + public void TestCollectionContentPropertiesWithSingleElement () + { + var xaml = @" + <StackLayout> + <Label Text=""Foo""/> + </StackLayout>"; + var layout = new StackLayout ().LoadFromXaml (xaml); + Assert.AreEqual (1, layout.Children.Count); + Assert.AreEqual ("Foo", ((Label)(layout.Children [0])).Text); + } + + [Test] + public void TestPropertiesWithContentProperties () + { + var xaml = @" + <ContentPage + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""> + <Grid.Row>1</Grid.Row> + <Label Text=""foo""></Label> + </ContentPage>"; + var contentPage = new ContentPage ().LoadFromXaml (xaml); + Assert.AreEqual (1, Grid.GetRow (contentPage)); + Assert.NotNull (contentPage.Content); + } + + [Test] + public void LoadFromXamlResource () + { + ContentView view = null; + Assert.DoesNotThrow (() => view = new CustomXamlView ()); + Assert.NotNull (view); + Assert.That (view.Content, Is.TypeOf<Label> ()); + Assert.AreEqual ("foobar", ((Label)view.Content).Text); + } + + [Test] + public void ThrowOnMissingXamlResource () + { + var view = new CustomView (); + Assert.Throws (new XamlParseExceptionConstraint (), () => view.LoadFromXaml (typeof(CustomView))); + } + + [Test] + public void CreateNewChildrenCollection () + { + var xaml = @" + <local:ViewWithChildrenContent + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" > + <local:ViewWithChildrenContent.Children> + <local:ViewList> + <Label x:Name=""child0""/> + <Label x:Name=""child1""/> + </local:ViewList> + </local:ViewWithChildrenContent.Children> + </local:ViewWithChildrenContent>"; + ViewWithChildrenContent layout = null; + Assert.DoesNotThrow (() => layout = new ViewWithChildrenContent ().LoadFromXaml (xaml)); + Assert.IsNotNull (layout); + Assert.AreNotSame (layout.DefaultChildren, layout.Children); + Assert.Contains (((Forms.Internals.INameScope)layout).FindByName ("child0"), layout.Children); + Assert.Contains (((Forms.Internals.INameScope)layout).FindByName ("child1"), layout.Children); + } + + [Test] + public void AddChildrenToCollectionContentProperty () + { + var xaml = @" + <local:ViewWithChildrenContent + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" > + <Label x:Name=""child0""/> + <Label x:Name=""child1""/> + </local:ViewWithChildrenContent>"; + ViewWithChildrenContent layout = null; + Assert.DoesNotThrow (() => layout = new ViewWithChildrenContent ().LoadFromXaml (xaml)); + Assert.IsNotNull (layout); + Assert.AreSame (layout.DefaultChildren, layout.Children); + Assert.Contains (((Forms.Internals.INameScope)layout).FindByName ("child0"), layout.Children); + Assert.Contains (((Forms.Internals.INameScope)layout).FindByName ("child1"), layout.Children); + } + + [Test] + public void AddChildrenToExistingCollection () + { + var xaml = @" + <local:ViewWithChildrenContent + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" > + <local:ViewWithChildrenContent.Children> + <Label x:Name=""child0""/> + <Label x:Name=""child1""/> + </local:ViewWithChildrenContent.Children> + </local:ViewWithChildrenContent>"; + ViewWithChildrenContent layout = null; + Assert.DoesNotThrow (() => layout = new ViewWithChildrenContent ().LoadFromXaml (xaml)); + Assert.IsNotNull (layout); + Assert.AreSame (layout.DefaultChildren, layout.Children); + Assert.Contains (((Forms.Internals.INameScope)layout).FindByName ("child0"), layout.Children); + Assert.Contains (((Forms.Internals.INameScope)layout).FindByName ("child1"), layout.Children); + + } + + [Test] + public void AddSingleChildToCollectionContentProperty () + { + var xaml = @" + <local:ViewWithChildrenContent + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" > + <Label x:Name=""child0""/> + </local:ViewWithChildrenContent>"; + ViewWithChildrenContent layout = null; + Assert.DoesNotThrow (() => layout = new ViewWithChildrenContent ().LoadFromXaml (xaml)); + Assert.IsNotNull (layout); + Assert.AreSame (layout.DefaultChildren, layout.Children); + Assert.Contains (((Forms.Internals.INameScope)layout).FindByName ("child0"), layout.Children); + } + + [Test] + public void FindResourceByName () + { + var xaml = @" + <ContentPage + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + x:Class=""Resources""> + <ContentPage.Resources> + <ResourceDictionary> + <Button x:Key=""buttonKey"" x:Name=""buttonName""/> + </ResourceDictionary> + </ContentPage.Resources> + <Label x:Name=""label""/> + </ContentPage>"; + + var layout = new ContentPage ().LoadFromXaml (xaml); + Assert.True (layout.Resources.ContainsKey ("buttonKey")); + var resource = layout.FindByName<Button> ("buttonName"); + Assert.NotNull (resource); + Assert.That (resource, Is.TypeOf<Button> ()); + } + + [Test] + public void ParseEnum () + { + var xaml = @" + <local:CustomView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" + MockFlags=""Bar"" + />"; + var view = new CustomView ().LoadFromXaml (xaml); + Assert.AreEqual (MockFlags.Bar, view.MockFlags); + + } + + [Test] + public void ParseFlags () + { + var xaml = @" + <local:CustomView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" + MockFlags=""Baz,Bar"" + />"; + var view = new CustomView ().LoadFromXaml (xaml); + Assert.AreEqual (MockFlags.Bar | MockFlags.Baz, view.MockFlags); + } + + [Test] + public void StyleWithoutTargetTypeThrows () + { + var xaml = @" + <Label> + <Label.Style> + <Style> + <Setter Property=""Text"" Value=""Foo"" /> + </Style> + </Label.Style> + </Label>"; + var label = new Label (); + Assert.Throws (new XamlParseExceptionConstraint (4, 8), () => label.LoadFromXaml (xaml)); + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/MarkupExpressionParserTests.cs b/Xamarin.Forms.Xaml.UnitTests/MarkupExpressionParserTests.cs new file mode 100644 index 00000000..63493030 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/MarkupExpressionParserTests.cs @@ -0,0 +1,326 @@ +using System; +using NUnit.Framework; +using System.Xml; +using System.Collections.Generic; + +using Xamarin.Forms.Core.UnitTests; +using System.Reflection; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class MarkupExpressionParserTests : BaseTestFixture + { + IXamlTypeResolver typeResolver; + + class MockElementNode : IElementNode, IValueNode, IXmlLineInfo + { + public bool HasLineInfo () { return false; } + + public int LineNumber { + get { return -1; } + } + + public int LinePosition { + get { return -1; } + } + + + public IXmlNamespaceResolver NamespaceResolver { + get { + throw new NotImplementedException (); + } + } + + public object Value {get;set;} + public Dictionary<XmlName, INode> Properties { get; set; } + + public List<XmlName> SkipProperties { get; set; } + + public Forms.Internals.INameScope Namescope { + get { + throw new NotImplementedException (); + } + } + + public XmlType XmlType { + get; + set; + } + + public string NamespaceURI { + get { + throw new NotImplementedException (); + } + } + + public INode Parent { + get { + throw new NotImplementedException (); + } + set { throw new NotImplementedException (); } + } + + public List<INode> CollectionItems { get; set; } + + public void Accept (IXamlNodeVisitor visitor, INode parentNode) + { + throw new NotImplementedException (); + } + + public List<string> IgnorablePrefixes { get; set; } + } + + [SetUp] + public override void Setup () + { + base.Setup (); + var nsManager = new XmlNamespaceManager (new NameTable ()); + nsManager.AddNamespace ("local", "clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"); + nsManager.AddNamespace ("x", "http://schemas.microsoft.com/winfx/2009/xaml"); + typeResolver = new Internals.XamlTypeResolver (nsManager, XamlParser.GetElementType, Assembly.GetCallingAssembly ()); + } + + [Test] + public void BindingOnSelf () + { + var bindingString = "{Binding}"; + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }); + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual (Binding.SelfPath, ((Binding)binding).Path); + } + + [Test] + public void BindingWithImplicitPath () + { + var bindingString = "{Binding Foo}"; + + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }); + + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual ("Foo", ((Binding)binding).Path); + } + + [Test] + public void BindingWithPath () + { + var bindingString = "{Binding Path=Foo}"; + + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }); + + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual ("Foo", ((Binding)binding).Path); + } + + [Test] + public void BindingWithComposedPath () + { + var bindingString = "{Binding Path=Foo.Bar}"; + + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }); + + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual ("Foo.Bar", ((Binding)binding).Path); + } + + [Test] + public void BindingWithImplicitComposedPath () + { + var bindingString = "{Binding Path=Foo.Bar}"; + + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }); + + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual ("Foo.Bar", ((Binding)binding).Path); + } + + class MockValueProvider : IProvideParentValues, IProvideValueTarget + { + public MockValueProvider (string key, object resource) + { + var rd = new ResourceDictionary { + {key, resource} + }; + + ve = new VisualElement { + Resources = rd, + }; + } + + + VisualElement ve; + public IEnumerable<object> ParentObjects { + get { + yield return ve; + } + } + + public object TargetObject { + get { + throw new NotImplementedException (); + } + } + + public object TargetProperty { + get { + throw new NotImplementedException (); + } + } + } + + [Test] + public void BindingWithImplicitPathAndConverter () + { + var bindingString = "{Binding Foo, Converter={StaticResource Bar}}"; + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + IProvideValueTarget = new MockValueProvider ("Bar", new ReverseConverter()), + }); + + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual ("Foo", ((Binding)binding).Path); + Assert.NotNull (((Binding)binding).Converter); + Assert.That (((Binding)binding).Converter, Is.InstanceOf<ReverseConverter> ()); + } + + [Test] + public void BindingWithPathAndConverter () + { + var bindingString = "{Binding Path=Foo, Converter={StaticResource Bar}}"; + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + IProvideValueTarget = new MockValueProvider ("Bar", new ReverseConverter()), + }); + + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual ("Foo", ((Binding)binding).Path); + Assert.NotNull (((Binding)binding).Converter); + Assert.That (((Binding)binding).Converter, Is.InstanceOf<ReverseConverter> ()); + } + + + [Test] + public void TestBindingMode () + { + var bindingString = "{Binding Foo, Mode=TwoWay}"; + + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }); + + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual ("Foo", ((Binding)binding).Path); + Assert.AreEqual (BindingMode.TwoWay, ((Binding)binding).Mode); + } + + [Test] + public void BindingStringFormat () + { + var bindingString = "{Binding Foo, StringFormat=Bar}"; + + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }); + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual ("Foo", ((Binding)binding).Path); + Assert.AreEqual ("Bar", ((Binding)binding).StringFormat); + } + + [Test] + public void BindingStringFormatWithEscapes () + { + var bindingString = "{Binding Foo, StringFormat='{}Hello {0}'}"; + + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }); + + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual ("Foo", ((Binding)binding).Path); + Assert.AreEqual ("Hello {0}", ((Binding)binding).StringFormat); + } + + [Test] + public void BindingStringFormatWithoutEscaping () + { + var bindingString = "{Binding Foo, StringFormat='{0,20}'}"; + + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }); + + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual ("Foo", ((Binding)binding).Path); + Assert.AreEqual ("{0,20}", ((Binding)binding).StringFormat); + } + + [Test] + public void BindingStringFormatNumeric () + { + var bindingString = "{Binding Foo, StringFormat=P2}"; + + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }); + + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual ("Foo", ((Binding)binding).Path); + Assert.AreEqual ("P2", ((Binding)binding).StringFormat); + } + + [Test] + public void BindingConverterParameter () + { + var bindingString = "{Binding Foo, ConverterParameter='Bar'}"; + + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }); + + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual ("Foo", ((Binding)binding).Path); + Assert.AreEqual ("Bar", ((Binding)binding).ConverterParameter); + } + + [Test] + public void BindingsCompleteString () + { + var bindingString = "{Binding Path=Foo.Bar, StringFormat='{}Qux, {0}', Converter={StaticResource Baz}, Mode=OneWayToSource}"; + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + IProvideValueTarget = new MockValueProvider ("Baz", new ReverseConverter()), + }); + + Assert.That (binding, Is.InstanceOf<Binding> ()); + Assert.AreEqual ("Foo.Bar", ((Binding)binding).Path); + Assert.NotNull (((Binding)binding).Converter); + Assert.That (((Binding)binding).Converter, Is.InstanceOf<ReverseConverter> ()); + Assert.AreEqual (BindingMode.OneWayToSource, ((Binding)binding).Mode); + Assert.AreEqual ("Qux, {0}", ((Binding)binding).StringFormat); + } + + [Test] + public void BindingWithStaticConverter () + { + var bindingString = "{Binding Converter={x:Static local:ReverseConverter.Instance}}"; + + var binding = (new MarkupExtensionParser ()).ParseExpression (ref bindingString, new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }) as Binding; + + Assert.NotNull (binding); + Assert.AreEqual(".", binding.Path); + Assert.That (binding.Converter, Is.TypeOf<ReverseConverter> ()); + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/MarkupExtensionTests.cs b/Xamarin.Forms.Xaml.UnitTests/MarkupExtensionTests.cs new file mode 100644 index 00000000..ebc32f4a --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/MarkupExtensionTests.cs @@ -0,0 +1,211 @@ +using System; +using NUnit.Framework; +using System.Xml; + +using Xamarin.Forms.Core.UnitTests; +using System.Reflection; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class FooMarkupExtension : IMarkupExtension + { + public object ProvideValue (IServiceProvider serviceProvider) + { + return "Foo"; + } + } + + public class AppendMarkupExtension : IMarkupExtension + { + public object Value0 { get; set; } + public object Value1 { get; set; } + + public object ProvideValue (IServiceProvider serviceProvider) + { + return Value0.ToString () + Value1.ToString (); + } + } + + public class AccessServiceProviderExtension : IMarkupExtension + { + public object ProvideValue (IServiceProvider serviceProvider) + { + var result = ""; + if (serviceProvider != null) { + var targetValueProvider = serviceProvider.GetService (typeof(IProvideValueTarget)); + result += targetValueProvider != null; + var xamlType = serviceProvider.GetService (typeof(IXamlTypeResolver)); + result += xamlType != null; + var rootObject = serviceProvider.GetService (typeof(IRootObjectProvider)); + result += rootObject != null; + } + return result; + } + } + + public class ColorMarkup : IMarkupExtension + { + public int R { get; set; } + public int G { get; set; } + public int B { get; set; } + + public ColorMarkup () + { + } + + public object ProvideValue (IServiceProvider serviceProvider) + { + return Color.FromRgb (R, G, B); + } + } + + public class FuuExtension : IMarkupExtension + { + public object ProvideValue (IServiceProvider serviceProvider) + { + return "FuuExtension"; + } + } + + public class Fuu : IMarkupExtension + { + public object ProvideValue (IServiceProvider serviceProvider) + { + return "Fuu"; + } + } + + public class BaaExtension : IMarkupExtension + { + public object ProvideValue (IServiceProvider serviceProvider) + { + return "BaaExtension"; + } + } + + [TestFixture] + public class MarkupExtensionTests : BaseTestFixture + { + IXamlTypeResolver typeResolver; + + [SetUp] + public override void Setup () + { + base.Setup (); + var nsManager = new XmlNamespaceManager (new NameTable ()); + nsManager.AddNamespace ("local", "clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"); + nsManager.AddNamespace ("x", "http://schemas.microsoft.com/winfx/2006/xaml"); + + typeResolver = new Internals.XamlTypeResolver (nsManager, XamlParser.GetElementType, Assembly.GetCallingAssembly ()); + } + + [Test] + public void TestSimpleExtension () + { + var markupString = "{local:FooMarkupExtension}"; + var serviceProvider = new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }; + var result = (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider); + + Assert.That (result, Is.InstanceOf<string> ()); + Assert.AreEqual ("Foo", result); + } + + [Test] + public void TestExtensionWithParameters () + { + var markupString = "{local:AppendMarkupExtension Value0=Foo, Value1=Bar}"; + var serviceProvider = new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }; + var result = (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider); + + Assert.That (result, Is.InstanceOf<string> ()); + Assert.AreEqual ("FooBar", result); + } + + [Test] + public void TestServiceProvider () + { + var markupString = "{local:AccessServiceProviderExtension}"; + var serviceProvider = new Internals.XamlServiceProvider (null, null) { + IProvideValueTarget = new Internals.XamlValueTargetProvider (null, null, null, null), + IXamlTypeResolver = typeResolver, + IRootObjectProvider = new Internals.XamlRootObjectProvider(null), + }; + + var result = (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider); + + Assert.That (result, Is.InstanceOf<string> ()); + Assert.AreEqual ("TrueTrueTrue", result); + } + + [Test] + public void TestInXaml () + { + var xaml = @" + <Label + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" + Text=""{local:AppendMarkupExtension Value0=Foo, Value1=Bar}"" + />"; + + var label = new Label (); + label.LoadFromXaml (xaml); + Assert.AreEqual ("FooBar", label.Text.ToString ()); + } + + [Test] + public void TestDocumentationCode () + { + var xaml =@" + <Label + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + xmlns:local=""clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"" + TextColor=""{local:ColorMarkup R=100, G=80, B=60}""/>"; + + var label = new Label ().LoadFromXaml (xaml); + Assert.AreEqual (Color.FromRgb (100, 80, 60), label.TextColor); + } + + [Test] + public void TestLookupWithSuffix () + { + var markupString = "{local:Baa}"; + var serviceProvider = new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }; + var result = (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider); + + Assert.That (result, Is.InstanceOf<string> ()); + Assert.AreEqual ("BaaExtension", result); + } + + [Test] + public void TestLookupOrder () + { + //The order of lookup is to look for the Extension-suffixed class name first and then look for the class name without the Extension suffix. + var markupString = "{local:Fuu}"; + var serviceProvider = new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }; + var result = (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider); + + Assert.That (result, Is.InstanceOf<string> ()); + Assert.AreEqual ("FuuExtension", result); + } + + [Test] + public void ThrowOnMarkupExtensionNotFound () + { + var markupString = "{local:Missing}"; + var serviceProvider = new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }; + Assert.Throws<XamlParseException> (()=> (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider)); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/McIgnorable.xaml b/Xamarin.Forms.Xaml.UnitTests/McIgnorable.xaml new file mode 100644 index 00000000..7cbd4aa5 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/McIgnorable.xaml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" + xmlns:d="ignoreme" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d" + x:Class="Xamarin.Forms.Xaml.UnitTests.McIgnorable" + d:DesignWidth="320" + d:DesignHeight="800"> + <ContentPage.BindingContext> + <d:FooBar /> + </ContentPage.BindingContext> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/McIgnorable.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/McIgnorable.xaml.cs new file mode 100644 index 00000000..f1c4aa6f --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/McIgnorable.xaml.cs @@ -0,0 +1,29 @@ +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class McIgnorable : ContentPage + { + public McIgnorable () + { + InitializeComponent (); + } + + public McIgnorable (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void DoesNotThrow (bool useCompiledXaml) + { + var layout = new McIgnorable (useCompiledXaml); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/NameScopeTests.cs b/Xamarin.Forms.Xaml.UnitTests/NameScopeTests.cs new file mode 100644 index 00000000..b622da27 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/NameScopeTests.cs @@ -0,0 +1,110 @@ +using NUnit.Framework; + +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + + [TestFixture] + public class NameScopeTests : BaseTestFixture + { + [Test] + public void TopLevelObjectsHaveANameScope () + { + var xaml = @" + <View + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" />"; + + var view = new CustomView ().LoadFromXaml (xaml); + + Assert.IsNotNull (Forms.Internals.NameScope.GetNameScope (view)); + Assert.That (Forms.Internals.NameScope.GetNameScope (view), Is.TypeOf<Forms.Internals.NameScope> ()); + } + + [Test] + public void NameScopeAreSharedWithChildren () + { + var xaml = @" + <StackLayout + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" > + <Label /> + <Label /> + </StackLayout>"; + + var layout = new StackLayout ().LoadFromXaml (xaml); + + Assert.IsNotNull (Forms.Internals.NameScope.GetNameScope (layout)); + Assert.That (Forms.Internals.NameScope.GetNameScope (layout), Is.TypeOf<Forms.Internals.NameScope> ()); + + foreach (var child in layout.Children) { + Assert.IsNotNull (Forms.Internals.NameScope.GetNameScope (child)); + Assert.That (Forms.Internals.NameScope.GetNameScope (child), Is.TypeOf<Forms.Internals.NameScope> ()); + Assert.AreSame (Forms.Internals.NameScope.GetNameScope (layout), Forms.Internals.NameScope.GetNameScope (child)); + } + } + + [Test] + public void DataTemplateChildrenDoesNotParticipateToParentNameScope () + { + var xaml = @" + <ListView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + x:Name=""listview""> + <ListView.ItemTemplate> + <DataTemplate> + <TextCell Text=""{Binding name}"" x:Name=""textcell""/> + </DataTemplate> + </ListView.ItemTemplate> + </ListView>"; + + var listview = new ListView (); + listview.LoadFromXaml (xaml); + + Assert.AreSame (listview, ((Forms.Internals.INameScope)listview).FindByName ("listview")); + Assert.IsNull (((Forms.Internals.INameScope)listview).FindByName ("textcell")); + } + + [Test] + public void ElementsCreatedFromDataTemplateHaveTheirOwnNameScope () + { + var xaml = @" + <ListView + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + x:Name=""listview""> + <ListView.ItemTemplate> + <DataTemplate> + <TextCell Text=""{Binding name}"" x:Name=""textcell""/> + </DataTemplate> + </ListView.ItemTemplate> + </ListView>"; + + var listview = new ListView (); + listview.LoadFromXaml (xaml); + Assert.IsNotNull (Forms.Internals.NameScope.GetNameScope (listview)); + Assert.That (Forms.Internals.NameScope.GetNameScope (listview), Is.TypeOf<Forms.Internals.NameScope> ()); + + var cell0 = listview.ItemTemplate.CreateContent () as Element; + var cell1 = listview.ItemTemplate.CreateContent () as Element; + + Assert.IsNotNull (Forms.Internals.NameScope.GetNameScope (cell0)); + Assert.That (Forms.Internals.NameScope.GetNameScope (cell0), Is.TypeOf<Forms.Internals.NameScope> ()); + Assert.IsNotNull (Forms.Internals.NameScope.GetNameScope (cell1)); + Assert.That (Forms.Internals.NameScope.GetNameScope (cell1), Is.TypeOf<Forms.Internals.NameScope> ()); + + Assert.AreNotSame (Forms.Internals.NameScope.GetNameScope (listview), Forms.Internals.NameScope.GetNameScope (cell0)); + Assert.AreNotSame (Forms.Internals.NameScope.GetNameScope (listview), Forms.Internals.NameScope.GetNameScope (cell1)); + Assert.AreNotSame (Forms.Internals.NameScope.GetNameScope (cell0), Forms.Internals.NameScope.GetNameScope (cell1)); + + Assert.IsNull (((Forms.Internals.INameScope)listview).FindByName ("textcell")); + Assert.NotNull (((Forms.Internals.INameScope)cell0).FindByName ("textcell")); + Assert.NotNull (((Forms.Internals.INameScope)cell1).FindByName ("textcell")); + + Assert.AreNotSame (((Forms.Internals.INameScope)cell0).FindByName ("textcell"), ((Forms.Internals.INameScope)cell1).FindByName ("textcell")); + + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/NullExtensionTests.cs b/Xamarin.Forms.Xaml.UnitTests/NullExtensionTests.cs new file mode 100644 index 00000000..1831cdce --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/NullExtensionTests.cs @@ -0,0 +1,21 @@ +using System; +using NUnit.Framework; + +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class NullExtensionTests : BaseTestFixture + { + [Test] + public void TestxNull () + { + var markupString = "{x:Null}"; + var serviceProvider = new Internals.XamlServiceProvider (null, null); + var result = (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider); + + Assert.IsNull (result); + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml new file mode 100644 index 00000000..bf44299b --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml @@ -0,0 +1,27 @@ +<?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.OnPlatform"> + <StackLayout> + <Label x:Name="label0"> + <Label.IsVisible> + <OnPlatform x:TypeArguments="x:Boolean"> + <OnPlatform.iOS>true</OnPlatform.iOS> + <OnPlatform.Android>false</OnPlatform.Android> + </OnPlatform> + </Label.IsVisible> + <Label.WidthRequest> + <OnPlatform x:TypeArguments="x:Double"> + <OnPlatform.iOS>20</OnPlatform.iOS> + <OnPlatform.Android>30</OnPlatform.Android> + </OnPlatform> + </Label.WidthRequest> + <Label.Text> + <OnPlatform x:TypeArguments="x:String"> + <OnPlatform.iOS>Foo</OnPlatform.iOS> + <OnPlatform.Android>Bar</OnPlatform.Android> + </OnPlatform> + </Label.Text> + </Label> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs new file mode 100644 index 00000000..2c2c6482 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class OnPlatform : ContentPage + { + public OnPlatform () + { + InitializeComponent (); + } + + public OnPlatform (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void BoolToVisibility (bool useCompiledXaml) + { + Device.OS = TargetPlatform.iOS; + var layout = new OnPlatform (useCompiledXaml); + Assert.AreEqual (true, layout.label0.IsVisible); + + Device.OS = TargetPlatform.Android; + layout = new OnPlatform (useCompiledXaml); + Assert.AreEqual (false, layout.label0.IsVisible); + } + } + + public void T () + { + var onplat = new OnPlatform<bool> (); + var label = new Label (); + label.IsVisible = onplat; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/OnPlatformTests.cs b/Xamarin.Forms.Xaml.UnitTests/OnPlatformTests.cs new file mode 100644 index 00000000..fc7283ad --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/OnPlatformTests.cs @@ -0,0 +1,118 @@ +using NUnit.Framework; +using System; + +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class OnPlatformTests : BaseTestFixture + { + [Test] + public void ApplyToProperty () + { + var xaml = @" + <ContentPage + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + xmlns:scg=""clr-namespace:System.Collections.Generic;assembly=mscorlib""> + <OnPlatform x:TypeArguments=""View""> + <OnPlatform.iOS><Button Text=""iOS""/></OnPlatform.iOS> + <OnPlatform.Android><Button Text=""Android""/></OnPlatform.Android> + <OnPlatform.WinPhone><Button Text=""WinPhone""/></OnPlatform.WinPhone> + </OnPlatform> + </ContentPage>"; + var layout = new ContentPage ().LoadFromXaml (xaml); + Assert.NotNull (layout.Content); + } + + [Test] + public void UseTypeConverters () + { + var xaml = @" + <ContentPage xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + Title=""Grid Demo Page""> + <ContentPage.Padding> + <OnPlatform x:TypeArguments=""Thickness""> + <OnPlatform.iOS> + 0, 20, 0, 0 + </OnPlatform.iOS> + <OnPlatform.Android> + 0, 0, 10, 0 + </OnPlatform.Android> + <OnPlatform.WinPhone> + 0, 20, 0, 20 + </OnPlatform.WinPhone> + </OnPlatform> + </ContentPage.Padding> + </ContentPage>"; + + ContentPage layout; + + Device.OS = TargetPlatform.iOS; + layout = new ContentPage ().LoadFromXaml (xaml); + Assert.AreEqual (new Thickness (0, 20, 0, 0), layout.Padding); + + Device.OS = TargetPlatform.Android; + layout = new ContentPage ().LoadFromXaml (xaml); + Assert.AreEqual (new Thickness (0, 0, 10, 0), layout.Padding); + + Device.OS = TargetPlatform.WinPhone; + layout = new ContentPage ().LoadFromXaml (xaml); + Assert.AreEqual (new Thickness (0, 20, 0, 20), layout.Padding); + } + + [Test] + //Issue 1480 + public void TypeConverterAndDerivedTypes () + { + var xaml = @" + <Image xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""> + <Image.Source> + <OnPlatform x:TypeArguments=""ImageSource""> + <OnPlatform.iOS>icon_twitter.png</OnPlatform.iOS> + <OnPlatform.Android>icon_twitter.png</OnPlatform.Android> + <OnPlatform.WinPhone>Images/icon_twitter.png</OnPlatform.WinPhone> + </OnPlatform> + </Image.Source> + </Image>"; + + Image image; + + Device.OS = TargetPlatform.iOS; + image = new Image ().LoadFromXaml (xaml); + Assert.AreEqual ("icon_twitter.png", (image.Source as FileImageSource).File); + } + } + + [TestFixture] + public class OnIdiomTests : BaseTestFixture + { + [Test] + public void StackLayoutOrientation () + { + var xaml = @" + <StackLayout + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml""> + <StackLayout.Orientation> + <OnIdiom x:TypeArguments=""StackOrientation""> + <OnIdiom.Phone>Vertical</OnIdiom.Phone> + <OnIdiom.Tablet>Horizontal</OnIdiom.Tablet> + </OnIdiom> + </StackLayout.Orientation> + <Label Text=""child0""/> + <Label Text=""child1""/> + </StackLayout>"; + Device.Idiom = TargetIdiom.Phone; + var layout = new StackLayout ().LoadFromXaml (xaml); + Assert.AreEqual (StackOrientation.Vertical, layout.Orientation); + + Device.Idiom = TargetIdiom.Tablet; + layout = new StackLayout ().LoadFromXaml (xaml); + Assert.AreEqual (StackOrientation.Horizontal, layout.Orientation); + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/Properties/AssemblyInfo.cs b/Xamarin.Forms.Xaml.UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..894b3ecd --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Properties/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using Xamarin.Forms.Xaml; + +[assembly:XamlCompilationAttribute (XamlCompilationOptions.Compile)]
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Speed/SimpleContentPage.xaml b/Xamarin.Forms.Xaml.UnitTests/Speed/SimpleContentPage.xaml new file mode 100644 index 00000000..688d998e --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Speed/SimpleContentPage.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.SimpleContentPage"> + <Label Text="Hello, Xamarin.Forms!" + VerticalOptions="CenterAndExpand" + HorizontalOptions="CenterAndExpand" /> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/Speed/SimpleContentPage.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Speed/SimpleContentPage.xaml.cs new file mode 100644 index 00000000..bdf291e7 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Speed/SimpleContentPage.xaml.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; + +using NUnit.Framework; +using System.Diagnostics; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class SimpleContentPageCode : ContentPage + { + public SimpleContentPageCode () + { + Content = new Label { + Text="Hello, Xamarin.Forms!", + VerticalOptions=LayoutOptions.CenterAndExpand, + HorizontalOptions=LayoutOptions.CenterAndExpand + }; + } + + public SimpleContentPageCode (bool useCompiledXaml) : this () + { + } + } + public partial class SimpleContentPage : ContentPage + { + public SimpleContentPage () + { + InitializeComponent (); + } + + public SimpleContentPage (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void Setup () + { + Device.PlatformServices = new MockPlatformServices (); + } + + [Test] + [Ignore] + public void XamlCIs20TimesFasterThanXaml () + { + var swXamlC = new Stopwatch (); + var swXaml = new Stopwatch (); + + swXamlC.Start (); + for (var i = 0; i < 1000; i++) + new SimpleContentPage (true); + swXamlC.Stop (); + + swXaml.Start (); + for (var i = 0; i < 1000; i++) + new SimpleContentPage (false); + swXaml.Stop (); + + Assert.Less (swXamlC.ElapsedMilliseconds * 20, swXaml.ElapsedMilliseconds); + } + + [Test] + [Ignore] + public void XamlCIsNotMuchSlowerThanCode () + { + var swXamlC = new Stopwatch (); + var swCode = new Stopwatch (); + + swXamlC.Start (); + for (var i = 0; i < 1000; i++) + new SimpleContentPage (true); + swXamlC.Stop (); + + swCode.Start (); + for (var i = 0; i < 1000; i++) + new SimpleContentPageCode (false); + swCode.Stop (); + + Assert.LessOrEqual (swXamlC.ElapsedMilliseconds*.2, swCode.ElapsedMilliseconds); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/StaticExtensionTests.cs b/Xamarin.Forms.Xaml.UnitTests/StaticExtensionTests.cs new file mode 100644 index 00000000..86e02fe7 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/StaticExtensionTests.cs @@ -0,0 +1,72 @@ +using System; +using NUnit.Framework; +using System.Xml; + +using Xamarin.Forms.Core.UnitTests; +using System.Reflection; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class StaticExtensionTests : BaseTestFixture + { + IXamlTypeResolver typeResolver; + + [SetUp] + public override void Setup () + { + base.Setup (); + var nsManager = new XmlNamespaceManager (new NameTable ()); + nsManager.AddNamespace ("local", "clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"); + nsManager.AddNamespace ("x", "http://schemas.microsoft.com/winfx/2006/xaml"); + + typeResolver = new Internals.XamlTypeResolver (nsManager, XamlParser.GetElementType, Assembly.GetCallingAssembly ()); + } + + [Test] + public void TestxStatic () + { + //{x:Static Member=prefix:typeName.staticMemberName} + //{x:Static prefix:typeName.staticMemberName} + + //The code entity that is referenced must be one of the following: + // - A constant + // - A static property + // - A field + // - An enumeration value + // All other cases should throw + + var serviceProvider = new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }; + + //Static property + var markupString = @"{x:Static Member=""local:MockxStatic.MockStaticProperty""}"; + Assert.AreEqual ("Property", (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider)); + + //constant + markupString = @"{x:Static Member=""local:MockxStatic.MockConstant""}"; + Assert.AreEqual ("Constant", (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider)); + + //field + markupString = @"{x:Static Member=""local:MockxStatic.MockField""}"; + Assert.AreEqual ("Field", (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider)); + + //enum + markupString = @"{x:Static Member=""local:MockEnum.Second""}"; + Assert.AreEqual (MockEnum.Second, (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider)); + + //throw on InstanceProperty + markupString = @"{x:Static Member=""local:MockxStatic.InstanceProperty""}"; + Assert.Throws<XamlParseException> (()=> (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider)); + + //quotes are optional + markupString = @"{x:Static Member=local:MockxStatic.MockStaticProperty}"; + Assert.AreEqual ("Property", (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider)); + + //Member is optional + markupString = @"{x:Static local:MockxStatic.MockStaticProperty}"; + Assert.AreEqual ("Property", (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider)); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/StringLiterals.xaml b/Xamarin.Forms.Xaml.UnitTests/StringLiterals.xaml new file mode 100644 index 00000000..cd40b053 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/StringLiterals.xaml @@ -0,0 +1,15 @@ +<?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.StringLiterals"> + <Label x:Name="label0" Text="{}Foo" /> + <Label x:Name="label1" Text="{}{Foo}" /> + <Label x:Name="label2"> + {}Foo + </Label> + <Label x:Name="label3"> + <Label.Text> + {}Foo + </Label.Text> + </Label> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/StringLiterals.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/StringLiterals.xaml.cs new file mode 100644 index 00000000..256ee5f9 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/StringLiterals.xaml.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class StringLiterals : ContentPage + { + public StringLiterals () + { + InitializeComponent (); + } + + public StringLiterals (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase(false)] + [TestCase(true)] + public void EscapedStringsAreTreatedAsLiterals (bool useCompiledXaml) + { + var layout = new StringLiterals (useCompiledXaml); + Assert.AreEqual ("Foo", layout.label0.Text); + Assert.AreEqual ("{Foo}", layout.label1.Text); + Assert.AreEqual ("Foo", layout.label2.Text); + Assert.AreEqual ("Foo", layout.label3.Text); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/StyleTests.xaml b/Xamarin.Forms.Xaml.UnitTests/StyleTests.xaml new file mode 100644 index 00000000..8b875510 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/StyleTests.xaml @@ -0,0 +1,36 @@ +<?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.StyleTests"> + <ContentPage.Resources> + <ResourceDictionary> + <Style TargetType="Label"> + <Setter Property="Label.TextColor" Value="Red"/> + </Style> + <Style x:Key="styleKey0" x:Name="style0" TargetType="Label"> + <Setter Property="Label.Text" Value="FooBar"/> + <Setter Property="Label.BackgroundColor" Value="Pink"/> + </Style> + <Style x:Key="styleKey1" x:Name="style1" TargetType="Label"> + <Setter Property="Label.Height" Value="42"/> + <Setter Property="Label.BackgroundColor" Value="Pink"/> + <Setter Property="Image.Source" Value="foo.png"/> + </Style> + <Style TargetType="Label" x:Key="style0" x:Name="style2"> + <Setter Property="Text" Value="foo"/> + <Setter Property="BackgroundColor" Value="Red"/> + </Style> + <Style x:Key="labelStyle" TargetType="Label" + BaseResourceKey="TitleStyle"> + <Setter Property="TextColor" Value="Red" /> + </Style> + </ResourceDictionary> + </ContentPage.Resources> + <StackLayout> + <Label x:Name="label0" Style="{StaticResource styleKey0}"/> + <Label x:Name="label1" /> + <Label x:Name="labelWithStyleDerivedFromDynamic_StaticResource" Style="{StaticResource labelStyle}"/> + <Label x:Name="labelWithStyleDerivedFromDynamic_DynamicResource" Style="{DynamicResource labelStyle}"/> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/StyleTests.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/StyleTests.xaml.cs new file mode 100644 index 00000000..7041ff77 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/StyleTests.xaml.cs @@ -0,0 +1,117 @@ +using System.Linq; + +using NUnit.Framework; + +using Xamarin.Forms; +using Xamarin.Forms.Xaml.UnitTests; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class StyleTests : ContentPage + { + public StyleTests () + { + InitializeComponent (); + } + + public StyleTests (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void SetUp () + { + Device.PlatformServices = new MockPlatformServices (); + Application.Current = new MockApplication (); + } + + [TestCase (false)] + [TestCase (true)] + public void TestStyle (bool useCompiledXaml) + { + var layout = new StyleTests (useCompiledXaml); + Assert.That (layout.style0, Is.InstanceOf<Style> ()); + Assert.AreSame (layout.style0, layout.label0.Style); + Assert.AreEqual ("FooBar", layout.label0.Text); + } + + [TestCase (false)] + [TestCase (true)] + public void TestConversionOnSetters (bool useCompiledXaml) + { + var layout = new StyleTests (useCompiledXaml); + Style style = layout.style1; + Setter setter; + + //Test built-in conversions + setter = style.Setters.Single (s => s.Property == HeightProperty); + Assert.That (setter.Value, Is.TypeOf<double> ()); + Assert.AreEqual (42d, (double)setter.Value); + + //Test TypeConverters + setter = style.Setters.Single (s => s.Property == BackgroundColorProperty); + Assert.That (setter.Value, Is.TypeOf<Color> ()); + Assert.AreEqual (Color.Pink, (Color)setter.Value); + + //Test implicit cast operator + setter = style.Setters.Single (s => s.Property == Image.SourceProperty); + Assert.That (setter.Value, Is.TypeOf<FileImageSource> ()); + Assert.AreEqual ("foo.png", ((FileImageSource)setter.Value).File); + } + + [TestCase (false)] + [TestCase (true)] + public void ImplicitStyleAreApplied (bool useCompiledXaml) + { + var layout = new StyleTests (useCompiledXaml); + Assert.AreEqual (Color.Red, layout.label1.TextColor); + } + + [TestCase (false)] + [TestCase (true)] + public void PropertyDoesNotNeedTypes (bool useCompiledXaml) + { + var layout = new StyleTests (useCompiledXaml); + Style style2 = layout.style2; + var s0 = style2.Setters [0]; + var s1 = style2.Setters [1]; + Assert.AreEqual (Label.TextProperty, s0.Property); + Assert.AreEqual (BackgroundColorProperty, s1.Property); + Assert.AreEqual (Color.Red, s1.Value); + } + + [TestCase (false)] + [TestCase (true)] + //issue #2406 + public void StylesDerivedFromDynamicStylesThroughStaticResource (bool useCompiledXaml) + { + var layout = new StyleTests (useCompiledXaml); + Application.Current.MainPage = layout; + + var label = layout.labelWithStyleDerivedFromDynamic_StaticResource; + + Assert.AreEqual (50, label.FontSize); + Assert.AreEqual (Color.Red, label.TextColor); + } + + [TestCase (false)] + [TestCase (true)] + //issue #2406 + public void StylesDerivedFromDynamicStylesThroughDynamicResource (bool useCompiledXaml) + { + var layout = new StyleTests (useCompiledXaml); + Application.Current.MainPage = layout; + + var label = layout.labelWithStyleDerivedFromDynamic_DynamicResource; + + Assert.AreEqual (50, label.FontSize); + Assert.AreEqual (Color.Red, label.TextColor); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml b/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml new file mode 100644 index 00000000..8d78ba93 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml @@ -0,0 +1,12 @@ +<?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.TriggerTests"> + <ContentPage.Content> + <Entry x:Name="entry"> + <Entry.Triggers> + <Trigger Property="IsPassword" Value="true" TargetType="Entry"> + <Setter Property="Scale" Value="1.2" /> + </Trigger> + </Entry.Triggers> + </Entry> + </ContentPage.Content> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml.cs new file mode 100644 index 00000000..5fe61bee --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/TriggerTests.xaml.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using Xamarin.Forms; +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class TriggerTests : ContentPage + { + public TriggerTests () + { + InitializeComponent (); + } + + public TriggerTests (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void ValueIsConverted (bool useCompiledXaml) + { + var layout = new TriggerTests (useCompiledXaml); + Entry entry = layout.entry; + Assert.NotNull (entry); + + var triggers = entry.Triggers; + Assert.IsNotEmpty (triggers); + var pwTrigger = triggers [0] as Trigger; + Assert.AreEqual (Entry.IsPasswordProperty, pwTrigger.Property); + Assert.AreEqual (true, pwTrigger.Value); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/TypeConverterTests.xaml b/Xamarin.Forms.Xaml.UnitTests/TypeConverterTests.xaml new file mode 100644 index 00000000..10cae044 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/TypeConverterTests.xaml @@ -0,0 +1,12 @@ +<?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.TypeConverterTests"> + <StackLayout> + <Image> + <Image.Source> + <UriImageSource Uri="https://xamarin.com/content/images/pages/branding/assets/xamagon.png" x:Name="imageSource"/> + </Image.Source> + </Image> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/TypeConverterTests.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/TypeConverterTests.xaml.cs new file mode 100644 index 00000000..5125ce74 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/TypeConverterTests.xaml.cs @@ -0,0 +1,39 @@ +using Xamarin.Forms; +using NUnit.Framework; +using System; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class TypeConverterTests : ContentPage + { + public TypeConverterTests () + { + InitializeComponent (); + } + + public TypeConverterTests (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void Setup () + { + Device.PlatformServices = new MockPlatformServices (); + } + + [TestCase (false)] + [TestCase (true)] + public void UriAreConverted (bool useCompiledXaml) + { + var layout = new TypeConverterTests (useCompiledXaml); + Assert.That (layout.imageSource.Uri, Is.TypeOf<Uri> ()); + Assert.AreEqual ("https://xamarin.com/content/images/pages/branding/assets/xamagon.png", layout.imageSource.Uri.ToString ()); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/TypeConverterTestsLegacy.cs b/Xamarin.Forms.Xaml.UnitTests/TypeConverterTestsLegacy.cs new file mode 100644 index 00000000..c9f3a382 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/TypeConverterTestsLegacy.cs @@ -0,0 +1,258 @@ +using System; +using NUnit.Framework; +using System.Xml; +using System.Globalization; + +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class FooConverter : TypeConverter + { + public override object ConvertFromInvariantString (string value) + { + return new Foo { Value = value }; + } + } + + public class BarConverter : TypeConverter + { + public override object ConvertFromInvariantString (string value) + { + return new Bar { Value = (string)value }; + } + } + + public class QuxConverter : TypeConverter + { + public override object ConvertFromInvariantString (string value) + { + return new Qux { Value = (string)value }; + } + } + + public class FooBarConverter : TypeConverter + { + public override object ConvertFromInvariantString (string value) + { + return new FooBar { Value = (string)value }; + } + } + + public class Foo { + public string Value { get; set; } + } + public class Bar { + public string Value { get; set; } + } + public class Baz { + public string Value { get; set; } + } + public class Qux { + public string Value { get; set; } + } + + [TypeConverter (typeof(FooBarConverter))] + public class FooBar { + public string Value { get; set; } + } + + public class Bindable : BindableObject + { + [TypeConverter (typeof(FooConverter))] + public Foo Foo { get; set; } + + public static readonly BindableProperty BarProperty = + BindableProperty.Create<Bindable, Bar> (w => w.Bar, default(Bar)); + + [TypeConverter (typeof(BarConverter))] + public Bar Bar { + get { return (Bar)GetValue (BarProperty); } + set { SetValue (BarProperty, value); } + } + + public Baz Baz { get; set; } + + public static readonly BindableProperty QuxProperty = + BindableProperty.CreateAttached<Bindable, Qux> (bindable => GetQux (bindable), default(Qux)); + + [TypeConverter (typeof(QuxConverter))] + public static Qux GetQux (BindableObject bindable) + { + return (Qux)bindable.GetValue (QuxProperty); + } + + public static void SetQux (BindableObject bindable, Qux value) + { + bindable.SetValue (QuxProperty, value); + } + + public FooBar FooBar { get; set; } + } + + internal class MockNameSpaceResolver : IXmlNamespaceResolver + { + public System.Collections.Generic.IDictionary<string, string> GetNamespacesInScope (XmlNamespaceScope scope) + { + throw new NotImplementedException (); + } + + public string LookupNamespace (string prefix) + { + return ""; + } + + public string LookupPrefix (string namespaceName) + { + return ""; + } + } + + [TestFixture] + public class TypeConverterTestsLegacy : BaseTestFixture + { + [Test] + public void TestSetPropertyWithoutConverter () + { + var baz = new Baz (); + var node = new ValueNode (baz, new MockNameSpaceResolver()); + var bindable = new Bindable (); + + Assert.IsNull (bindable.Baz); + var rootNode = new XamlLoader.RuntimeRootNode (new XmlType("clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests","Bindable",null), bindable) { + Properties = { + { new XmlName (null, "Baz"), node }, + } + }; + var context = new HydratationContext { RootElement = new Label () }; + rootNode.Accept (new CreateValuesVisitor(context), null); + node.Accept (new ApplyPropertiesVisitor (context), rootNode); + Assert.AreEqual (baz, bindable.Baz); + + } + + [Test] + public void TestFailOnMissingOrWrongConverter () + { + var node = new ValueNode ("baz", new MockNameSpaceResolver()); + var bindable = new Bindable (); + + Assert.IsNull (bindable.Baz); + var rootNode = new XamlLoader.RuntimeRootNode (new XmlType("clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests","Bindable",null), bindable) { + Properties = { + { new XmlName (null, "Baz"), node }, + } + }; + var context = new HydratationContext { RootElement = new Label () }; + rootNode.Accept (new CreateValuesVisitor (context), null); + Assert.Throws<XamlParseException>(()=> node.Accept (new ApplyPropertiesVisitor (context), rootNode)); + } + + [Test] + public void TestConvertNonBindableProperty () + { + var node = new ValueNode ("foo", new MockNameSpaceResolver()); + var bindable = new Bindable (); + + Assert.IsNull (bindable.Foo); + var rootNode = new XamlLoader.RuntimeRootNode (new XmlType("clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests","Bindable",null), bindable) { + Properties = { + { new XmlName (null, "Foo"), node }, + } + }; + + var context = new HydratationContext { RootElement = new Label () }; + rootNode.Accept (new CreateValuesVisitor(context), null); + node.Accept (new ApplyPropertiesVisitor (context), rootNode); + Assert.IsNotNull (bindable.Foo); + Assert.That (bindable.Foo, Is.TypeOf<Foo> ()); + Assert.AreEqual ("foo", bindable.Foo.Value); + } + + [Test] + public void TestConvertBindableProperty () + { + var node = new ValueNode ("bar", new MockNameSpaceResolver()); + var bindable = new Bindable (); + + Assert.IsNull (bindable.Bar); + var rootNode = new XamlLoader.RuntimeRootNode (new XmlType("clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests","Bindable",null), bindable) { + Properties = { + { new XmlName (null, "Bar"), node }, + } + }; + var context = new HydratationContext { RootElement = new Label () }; + rootNode.Accept (new CreateValuesVisitor(context), null); + node.Accept (new ApplyPropertiesVisitor (context), rootNode); + Assert.IsNotNull (bindable.Bar); + Assert.That (bindable.Bar, Is.TypeOf<Bar> ()); + Assert.AreEqual ("bar", bindable.Bar.Value); + } + + [Test] + public void TestConvertAttachedBindableProperty () + { + var node = new ValueNode ("qux", new MockNameSpaceResolver()); + var bindable = new Bindable (); + + Assert.IsNull (Bindable.GetQux (bindable)); + var rootNode = new XamlLoader.RuntimeRootNode (new XmlType("clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests","Bindable",null), bindable) { + Properties = { + { new XmlName ("clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests", "Bindable.Qux"), node }, + } + }; + var context = new HydratationContext { RootElement = new Label () }; + rootNode.Accept (new CreateValuesVisitor (context), null); + node.Accept (new ApplyPropertiesVisitor (context), rootNode); + Assert.IsNotNull (Bindable.GetQux (bindable)); + Assert.That (Bindable.GetQux (bindable), Is.TypeOf<Qux> ()); + Assert.AreEqual ("qux", Bindable.GetQux (bindable).Value); + } + + [Test] + public void TestConvertWithAttributeOnType () + { + var node = new ValueNode ("foobar", new MockNameSpaceResolver()); + var bindable = new Bindable (); + + Assert.IsNull (bindable.FooBar); + var rootNode = new XamlLoader.RuntimeRootNode (new XmlType("clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests","Bindable",null), bindable) { + Properties = { + { new XmlName (null, "FooBar"), node }, + } + }; + var context = new HydratationContext { RootElement = new Label () }; + rootNode.Accept (new CreateValuesVisitor (context), null); + node.Accept (new ApplyPropertiesVisitor (context), rootNode); + + Assert.IsNotNull (bindable.FooBar); + Assert.That (bindable.FooBar, Is.TypeOf<FooBar> ()); + Assert.AreEqual ("foobar", bindable.FooBar.Value); + } + + #if !WINDOWS_PHONE + [Test] + [SetCulture ("fr-FR")] + public void TestCultureOnThicknessFR () + { + TestCultureOnThickness (); + } + #endif + + [Test] + #if !WINDOWS_PHONE + [SetCulture ("en-GB")] + #endif + public void TestCultureOnThicknessEN () + { + TestCultureOnThickness (); + } + + public void TestCultureOnThickness () + { + var xaml = @"<Page Padding=""1.1, 2""/>"; + var page = new Page ().LoadFromXaml (xaml); + Assert.AreEqual (new Thickness (1.1, 2), page.Padding); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/TypeExtensionTests.cs b/Xamarin.Forms.Xaml.UnitTests/TypeExtensionTests.cs new file mode 100644 index 00000000..49c4bb49 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/TypeExtensionTests.cs @@ -0,0 +1,54 @@ +using System; +using NUnit.Framework; +using System.Xml; + +using Xamarin.Forms.Core.UnitTests; +using System.Reflection; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + + [TestFixture] + public class TypeExtensionTests : BaseTestFixture + { + IXamlTypeResolver typeResolver; + Internals.XamlServiceProvider serviceProvider; + + [SetUp] + public override void Setup () + { + base.Setup (); + var nsManager = new XmlNamespaceManager (new NameTable ()); + nsManager.AddNamespace ("local", "clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"); + nsManager.AddNamespace ("sys", "clr-namespace:System;assembly=mscorlib"); + nsManager.AddNamespace ("x", "http://schemas.microsoft.com/winfx/2006/xaml"); + + typeResolver = new Internals.XamlTypeResolver (nsManager, XamlParser.GetElementType, Assembly.GetCallingAssembly ()); + + serviceProvider = new Internals.XamlServiceProvider (null, null) { + IXamlTypeResolver = typeResolver, + }; + } + + [Test] + public void TestxType () + { + var markupString = @"{x:Type sys:String}"; + Assert.AreEqual (typeof(string), (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider)); + } + + [Test] + public void TestWithoutPrefix () + { + var markupString = @"{x:Type Grid}"; + Assert.AreEqual (typeof(Grid), (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider)); + } + + [Test] + public void TestWithExplicitTypeName () + { + var markupString = @"{x:Type TypeName=sys:String}"; + Assert.AreEqual (typeof(string), (new MarkupExtensionParser ()).ParseExpression (ref markupString, serviceProvider)); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/TypeLoader.xaml b/Xamarin.Forms.Xaml.UnitTests/TypeLoader.xaml new file mode 100644 index 00000000..d99f03e8 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/TypeLoader.xaml @@ -0,0 +1,11 @@ +<?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;assembly=Xamarin.Forms.Xaml.UnitTests" + xmlns:this="clr-namespace:Xamarin.Forms.Xaml.UnitTests" + x:Class="Xamarin.Forms.Xaml.UnitTests.TypeLoader"> + <StackLayout> + <local:CustomView x:Name="customview0" /> + <this:CustomView x:Name="customview1" /> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/TypeLoader.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/TypeLoader.xaml.cs new file mode 100644 index 00000000..62b4cb4c --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/TypeLoader.xaml.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class TypeLoader : ContentPage + { + public TypeLoader () + { + InitializeComponent (); + } + + public TypeLoader (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [SetUp] + public void SetUp () + { + Device.PlatformServices = new MockPlatformServices (); + Application.Current = new MockApplication (); + } + + [TestCase (false)] + [TestCase (true)] + public void LoadTypeFromXmlns (bool useCompiledXaml) + { + TypeLoader layout = null; + Assert.DoesNotThrow (() => layout = new TypeLoader (useCompiledXaml)); + Assert.NotNull (layout.customview0); + Assert.That (layout.customview0, Is.TypeOf<CustomView> ()); + } + + [TestCase (false)] + [TestCase (true)] + public void LoadTypeFromXmlnsWithoutAssembly (bool useCompiledXaml) + { + TypeLoader layout = null; + Assert.DoesNotThrow (() => layout = new TypeLoader (useCompiledXaml)); + Assert.NotNull (layout.customview1); + Assert.That (layout.customview1, Is.TypeOf<CustomView> ()); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Validation/SetterOnNonBP.xaml b/Xamarin.Forms.Xaml.UnitTests/Validation/SetterOnNonBP.xaml new file mode 100644 index 00000000..87252208 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Validation/SetterOnNonBP.xaml @@ -0,0 +1,14 @@ +<?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.SetterOnNonBP" + xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"> + <local:FakeVisualElement> + <local:FakeVisualElement.Style> + <Style TargetType="local:FakeVisualElement"> + <Setter Property="NonBindable" Value="Should Fail"/> + </Style> + </local:FakeVisualElement.Style> + </local:FakeVisualElement> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Validation/SetterOnNonBP.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Validation/SetterOnNonBP.xaml.cs new file mode 100644 index 00000000..f6d8ffea --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Validation/SetterOnNonBP.xaml.cs @@ -0,0 +1,34 @@ +using NUnit.Framework; + +using Xamarin.Forms; +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class FakeVisualElement : VisualElement + { + public string NonBindable { get; set; } + } + + public partial class SetterOnNonBP : ContentPage + { + public SetterOnNonBP () + { + InitializeComponent (); + } + + public SetterOnNonBP (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class SetterOnNonBPTests + { + [TestCase (false)] + [TestCase (true)] + public void ShouldThrow (bool useCompiledXaml) + { + Assert.Throws (new XamlParseExceptionConstraint (10, 13), () => new SetterOnNonBP (useCompiledXaml)); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Validation/StaticExtensionException.xaml b/Xamarin.Forms.Xaml.UnitTests/Validation/StaticExtensionException.xaml new file mode 100644 index 00000000..b8dc5b5d --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Validation/StaticExtensionException.xaml @@ -0,0 +1,10 @@ +<?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.StaticExtensionException"> + <ContentPage.Resources> + <ResourceDictionary> + <Style TargetType="Label" x:Key="foo"> + <Setter Property="TextColor" Value="{x:Static local:Colors.ButtonText}"/> + </Style> + </ResourceDictionary> + </ContentPage.Resources> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Validation/StaticExtensionException.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Validation/StaticExtensionException.xaml.cs new file mode 100644 index 00000000..d7476b74 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Validation/StaticExtensionException.xaml.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class StaticExtensionException : ContentPage + { + public StaticExtensionException () + { + InitializeComponent (); + } + + public StaticExtensionException (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Issue2115 + { + [TestCase (false)] + [TestCase (true)] + public void xStaticThrowsMeaningfullException (bool useCompiledXaml) + { + Assert.Throws (new XamlParseExceptionConstraint (6, 34), () => new StaticExtensionException (useCompiledXaml)); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Validation/TypeMismatch.xaml b/Xamarin.Forms.Xaml.UnitTests/Validation/TypeMismatch.xaml new file mode 100644 index 00000000..6b994bba --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Validation/TypeMismatch.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" + x:Class="Xamarin.Forms.Xaml.UnitTests.TypeMismatch"> + <StackLayout> + <ContentView Content="foobar"/> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Validation/TypeMismatch.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Validation/TypeMismatch.xaml.cs new file mode 100644 index 00000000..43a4459c --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Validation/TypeMismatch.xaml.cs @@ -0,0 +1,32 @@ +using System; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class TypeMismatch : ContentPage + { + public TypeMismatch () + { + InitializeComponent (); + } + + public TypeMismatch (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] +// [TestCase (true)] + public void ThrowsOnMismatchingType (bool useCompiledXaml) + { + Assert.Throws (new XamlParseExceptionConstraint (7, 16, m => m.StartsWith ("Cannot assign property", StringComparison.Ordinal)), () => new TypeMismatch (useCompiledXaml)); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/ViewExtensionsTest.cs b/Xamarin.Forms.Xaml.UnitTests/ViewExtensionsTest.cs new file mode 100644 index 00000000..57c6e353 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/ViewExtensionsTest.cs @@ -0,0 +1,59 @@ +using NUnit.Framework; +using System; + +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class ViewExtensionsTest : BaseTestFixture + { + [Test] + public void TestGetResource () + { + var resource = new object (); + var view = new View { + Resources = new ResourceDictionary { + { "foo", resource } + }, + }; + var found = view.Resources ["foo"]; + Assert.AreSame (resource, found); + } + + [Test] + public void TestResourceNotFound () + { + var view = new View (); + var resource = view.Resources!= null ? view.Resources ["foo"] : null; + Assert.Null (resource); + } + + [Test] + public void TestGetResourceInParents () + { + var resource = new object (); + var nestedView = new View (); + var stack = new StackLayout { + Children = { + new StackLayout { + Children = { + new StackLayout { + Children = { + nestedView + } + } + } + } + } + }; + stack.Resources = new ResourceDictionary { + { "foo", resource } + }; + + var found = stack.Resources ["foo"]; + Assert.AreSame (resource, found); + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml b/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml new file mode 100644 index 00000000..a7a91edc --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml @@ -0,0 +1,42 @@ +<?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.X2009Primitives"> + <ContentPage.Resources> + <ResourceDictionary> + <x:String x:Key="aString">foobar</x:String> + <x:String x:Key="defaultString"/> + + <x:Object x:Key="syncHandle"/> + + <x:Boolean x:Key="falsebool">false</x:Boolean> + <x:Boolean x:Key="truebool">true</x:Boolean> + <x:Boolean x:Key="defaultbool"/> + + <x:Char x:Key="singleChar">f</x:Char> + <x:Char x:Key="multipleChar">foo</x:Char> + <x:Char x:Key="defaultChar"/> + + <x:Decimal x:Key="aDecimal">1000.0</x:Decimal> + <x:Decimal x:Key="defaultDecimal"/> + <x:Single x:Key="aSingle">42.2</x:Single> + <x:Single x:Key="defaultSingle"/> + <x:Double x:Key="aDouble">42.3</x:Double> + <x:Double x:Key="aNegativeDouble">-42.3</x:Double> + <x:Double x:Key="defaultDouble"/> + <x:Byte x:Key="aByte">54</x:Byte> + <x:Byte x:Key="defaultByte"/> + <x:Int16 x:Key="anInt16">43</x:Int16> + <x:Int16 x:Key="defaultInt16"/> + <x:Int32 x:Key="anInt32">44</x:Int32> + <x:Int32 x:Key="defaultInt32"/> + <x:Int64 x:Key="anInt64">45</x:Int64> + <x:Int64 x:Key="defaultInt64"/> + <x:TimeSpan x:Key="aTimeSpan">6.12:14:45.3448000</x:TimeSpan> + <x:TimeSpan x:Key="defaultTimeSpan"/> + <x:Uri x:Key="anUri">http://xamarin.com/forms</x:Uri> + <x:Uri x:Key="defaultUri"/> + </ResourceDictionary> + </ContentPage.Resources> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml.cs new file mode 100644 index 00000000..60ead7ca --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/X2009Primitives.xaml.cs @@ -0,0 +1,233 @@ +using System; +using System.Collections.Generic; + +using NUnit.Framework; + +using Xamarin.Forms; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class X2009Primitives : ContentPage + { + public X2009Primitives () + { + InitializeComponent (); + } + + public X2009Primitives (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void SupportsXString (bool useCompiledXaml) + { + var layout = new X2009Primitives (useCompiledXaml); + Assert.True (layout.Resources.ContainsKey ("aString")); + Assert.AreEqual ("foobar", layout.Resources ["aString"]); + + Assert.True (layout.Resources.ContainsKey ("defaultString")); + Assert.AreEqual (String.Empty, layout.Resources ["defaultString"]); + + } + + [TestCase (false)] + [TestCase (true)] + public void SupportsXObject (bool useCompiledXaml) + { + var layout = new X2009Primitives (useCompiledXaml); + Assert.True (layout.Resources.ContainsKey ("syncHandle")); + var value = layout.Resources ["syncHandle"]; + Assert.NotNull (value); + Assert.That (value, Is.TypeOf<object> ()); + } + + [TestCase (false)] + [TestCase (true)] + public void SupportsXBoolean (bool useCompiledXaml) + { + var layout = new X2009Primitives (useCompiledXaml); + + Assert.True (layout.Resources.ContainsKey ("falsebool")); + var falsebool = layout.Resources ["falsebool"]; + Assert.NotNull (falsebool); + Assert.That (falsebool, Is.TypeOf<bool> ()); + Assert.AreEqual (false, (bool)falsebool); + + Assert.True (layout.Resources.ContainsKey ("truebool")); + var truebool = layout.Resources ["truebool"]; + Assert.NotNull (truebool); + Assert.That (truebool, Is.TypeOf<bool> ()); + Assert.AreEqual (true, (bool)truebool); + + Assert.True (layout.Resources.ContainsKey ("defaultbool")); + var defaultbool = layout.Resources ["defaultbool"]; + Assert.NotNull (defaultbool); + Assert.That (defaultbool, Is.TypeOf<bool> ()); + Assert.AreEqual (default(bool), (bool)defaultbool); + } + + [TestCase (false)] + [TestCase (true)] + public void SupportsXChar (bool useCompiledXaml) + { + var layout = new X2009Primitives (useCompiledXaml); + + Assert.True (layout.Resources.ContainsKey ("singleChar")); + var singleChar = layout.Resources ["singleChar"]; + Assert.NotNull (singleChar); + Assert.That (singleChar, Is.TypeOf<char> ()); + Assert.AreEqual ('f', (char)singleChar); + + Assert.True (layout.Resources.ContainsKey ("multipleChar")); + var multipleChar = layout.Resources ["multipleChar"]; + Assert.NotNull (multipleChar); + Assert.That (multipleChar, Is.TypeOf<char> ()); + Assert.AreEqual (default(char), (char)multipleChar); + + Assert.True (layout.Resources.ContainsKey ("defaultChar")); + var defaultChar = layout.Resources ["defaultChar"]; + Assert.NotNull (defaultChar); + Assert.That (defaultChar, Is.TypeOf<char> ()); + Assert.AreEqual (default(char), (char)defaultChar); + } + + [TestCase (false)] + [TestCase (true)] + public void SupportsXNumbers (bool useCompiledXaml) + { + var layout = new X2009Primitives (useCompiledXaml); + + Assert.True (layout.Resources.ContainsKey ("aDecimal")); + var aDecimal = layout.Resources ["aDecimal"]; + Assert.NotNull (aDecimal); + Assert.That (aDecimal, Is.TypeOf<decimal> ()); + Assert.AreEqual (1000, (decimal)aDecimal); + + Assert.True (layout.Resources.ContainsKey ("defaultDecimal")); + var defaultDecimal = layout.Resources ["defaultDecimal"]; + Assert.NotNull (defaultDecimal); + Assert.That (defaultDecimal, Is.TypeOf<decimal> ()); + Assert.AreEqual (default(decimal), (decimal)defaultDecimal); + + Assert.True (layout.Resources.ContainsKey ("aSingle")); + var aSingle = layout.Resources ["aSingle"]; + Assert.NotNull (aSingle); + Assert.That (aSingle, Is.TypeOf<float> ()); + Assert.AreEqual (42.2f, (float)aSingle, .0001f); + + Assert.True (layout.Resources.ContainsKey ("defaultSingle")); + var defaultSingle = layout.Resources ["defaultSingle"]; + Assert.NotNull (defaultSingle); + Assert.That (defaultSingle, Is.TypeOf<Single> ()); + Assert.AreEqual (default(float), (float)defaultSingle, .0001f); + + Assert.True (layout.Resources.ContainsKey ("aDouble")); + var aDouble = layout.Resources ["aDouble"]; + Assert.NotNull (aDouble); + Assert.That (aDouble, Is.TypeOf<double> ()); + Assert.AreEqual (42.3d, (double)aDouble, .0001d); + + Assert.True (layout.Resources.ContainsKey ("aNegativeDouble")); + var aNegativeDouble = layout.Resources ["aNegativeDouble"]; + Assert.NotNull (aNegativeDouble); + Assert.That (aNegativeDouble, Is.TypeOf<double> ()); + Assert.AreEqual (-42.3d, (double)aNegativeDouble, .0001d); + + Assert.True (layout.Resources.ContainsKey ("defaultDouble")); + var defaultDouble = layout.Resources ["defaultDouble"]; + Assert.NotNull (defaultDouble); + Assert.That (defaultDouble, Is.TypeOf<double> ()); + Assert.AreEqual (default(double), (double)defaultDouble, .0001d); + + Assert.True (layout.Resources.ContainsKey ("aByte")); + var aByte = layout.Resources ["aByte"]; + Assert.NotNull (aByte); + Assert.That (aByte, Is.TypeOf<byte> ()); + Assert.AreEqual (54, (byte)aByte); + + Assert.True (layout.Resources.ContainsKey ("defaultByte")); + var defaultByte = layout.Resources ["defaultByte"]; + Assert.NotNull (defaultByte); + Assert.That (defaultByte, Is.TypeOf<byte> ()); + Assert.AreEqual (default(byte), (byte)defaultByte); + + Assert.True (layout.Resources.ContainsKey ("anInt16")); + var anInt16 = layout.Resources ["anInt16"]; + Assert.NotNull (anInt16); + Assert.That (anInt16, Is.TypeOf<short> ()); + Assert.AreEqual (43, (short)anInt16); + + Assert.True (layout.Resources.ContainsKey ("defaultInt16")); + var defaultInt16 = layout.Resources ["defaultInt16"]; + Assert.NotNull (defaultInt16); + Assert.That (defaultInt16, Is.TypeOf<short> ()); + Assert.AreEqual (default(short), (short)defaultInt16); + + Assert.True (layout.Resources.ContainsKey ("anInt32")); + var anInt32 = layout.Resources ["anInt32"]; + Assert.NotNull (anInt32); + Assert.That (anInt32, Is.TypeOf<int> ()); + Assert.AreEqual (44, (int)anInt32); + + Assert.True (layout.Resources.ContainsKey ("defaultInt32")); + var defaultInt32 = layout.Resources ["defaultInt32"]; + Assert.NotNull (defaultInt32); + Assert.That (defaultInt32, Is.TypeOf<int> ()); + Assert.AreEqual (default(int), (int)defaultInt32); + + Assert.True (layout.Resources.ContainsKey ("anInt64")); + var anInt64 = layout.Resources ["anInt64"]; + Assert.NotNull (anInt64); + Assert.That (anInt64, Is.TypeOf<long> ()); + Assert.AreEqual (45, (long)anInt64); + + Assert.True (layout.Resources.ContainsKey ("defaultInt64")); + var defaultInt64 = layout.Resources ["defaultInt64"]; + Assert.NotNull (defaultInt64); + Assert.That (defaultInt64, Is.TypeOf<long> ()); + Assert.AreEqual (default(long), (long)defaultInt64); + } + + [TestCase (false)] + [TestCase (true)] + public void SupportsXTimeSpan (bool useCompiledXaml) + { + var layout = new X2009Primitives (useCompiledXaml); + + Assert.True (layout.Resources.ContainsKey ("aTimeSpan")); + var aTimeSpan = layout.Resources ["aTimeSpan"]; + Assert.NotNull (aTimeSpan); + Assert.That (aTimeSpan, Is.TypeOf<TimeSpan> ()); + Assert.AreEqual (new TimeSpan (6, 12, 14, 45, 344).Add (TimeSpan.FromTicks (8000)), (TimeSpan)aTimeSpan); + + Assert.True (layout.Resources.ContainsKey ("defaultTimeSpan")); + var defaultTimeSpan = layout.Resources ["defaultTimeSpan"]; + Assert.NotNull (defaultTimeSpan); + Assert.That (defaultTimeSpan, Is.TypeOf<TimeSpan> ()); + Assert.AreEqual (default(TimeSpan), (TimeSpan)defaultTimeSpan); + } + + [TestCase (false)] + [TestCase (true)] + public void SupportsXUri (bool useCompiledXaml) + { + var layout = new X2009Primitives (useCompiledXaml); + + Assert.True (layout.Resources.ContainsKey ("anUri")); + var anUri = layout.Resources ["anUri"]; + Assert.NotNull (anUri); + Assert.That (anUri, Is.TypeOf<Uri> ()); + Assert.AreEqual (new Uri ("http://xamarin.com/forms"), (Uri)anUri); + + Assert.True (layout.Resources.ContainsKey ("defaultUri")); + var defaultUri = layout.Resources ["defaultUri"]; + Assert.Null (defaultUri); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/XArray.xaml b/Xamarin.Forms.Xaml.UnitTests/XArray.xaml new file mode 100644 index 00000000..efd878c0 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XArray.xaml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<local:MockBindableForArray + xmlns="http://xamarin.com/schemas/2014/forms" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + xmlns:sys="clr-namespace:System;assembly=mscorlib" + xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests" + x:Class="Xamarin.Forms.Xaml.UnitTests.XArray"> + <x:Array Type="{x:Type sys:String}" x:Key="array"> + <x:String>Hello</x:String> + <x:String>World</x:String> + </x:Array> +</local:MockBindableForArray>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/XArray.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/XArray.xaml.cs new file mode 100644 index 00000000..52327f25 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XArray.xaml.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [ContentProperty ("Content")] + public class MockBindableForArray : View + { + public object Content { get; set; } + } + + public partial class XArray : MockBindableForArray + { + public XArray () + { + InitializeComponent (); + } + + public XArray (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void SupportsXArray (bool useCompiledXaml) + { + var layout = new XArray (useCompiledXaml); + var array = layout.Content; + Assert.NotNull (array); + Assert.That (array, Is.TypeOf<string[]> ()); + Assert.AreEqual (2, ((string[])layout.Content).Length); + Assert.AreEqual ("Hello", ((string[])layout.Content) [0]); + Assert.AreEqual ("World", ((string[])layout.Content) [1]); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/XNull.xaml b/Xamarin.Forms.Xaml.UnitTests/XNull.xaml new file mode 100644 index 00000000..4670e30b --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XNull.xaml @@ -0,0 +1,11 @@ +<?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.XNull"> + <ContentPage.Resources> + <ResourceDictionary> + <x:Null x:Key="null"/> + </ResourceDictionary> + </ContentPage.Resources> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/XNull.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/XNull.xaml.cs new file mode 100644 index 00000000..60ec785d --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XNull.xaml.cs @@ -0,0 +1,32 @@ +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class XNull : ContentPage + { + public XNull () + { + InitializeComponent (); + } + + public XNull (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase(false)] + [TestCase(true)] + public void SupportsXNull (bool useCompiledXaml) + { + var layout = new XNull (useCompiledXaml); + Assert.True (layout.Resources.ContainsKey ("null")); + Assert.Null (layout.Resources ["null"]); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/XReference.xaml b/Xamarin.Forms.Xaml.UnitTests/XReference.xaml new file mode 100644 index 00000000..f09af13e --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XReference.xaml @@ -0,0 +1,37 @@ +<?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.XReference"> + <ContentPage.Resources> + <ResourceDictionary> + <Image x:Name="image" x:Key="imageKey"/> + </ResourceDictionary> + </ContentPage.Resources> + <StackLayout> + <ContentView x:Name="imageView" Content="{x:Reference image}"/> + <Button + x:Name="aButton" + Text="My Button" + Command="{Binding ButtonClickCommand}" + CommandParameter="{x:Reference aButton}"/> + <StackLayout> + <Label x:Name="label0" Text="foo" BindingContext="{x:Reference label1}"/> + <Label x:Name="label1" Text="bar" BindingContext="{x:Reference label0}"/> + <Entry x:Name="entry" Text="{Binding Text, Source={x:Reference label0}}" Placeholder="{Binding Text, Source={x:Reference label1}}"/> + </StackLayout> + +<!-- <ListView x:Name="listView"> + <ListView.ItemTemplate> + <DataTemplate> + <ViewCell> + <StackLayout> + <Label x:Name="foo" BindingContext="{x:Reference bar}"/> + <Label x:Name="bar" BindingContext="{x:Reference foo}"/> + </StackLayout> + </ViewCell> + </DataTemplate> + </ListView.ItemTemplate> + </ListView>--> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/XReference.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/XReference.xaml.cs new file mode 100644 index 00000000..e3ad9e75 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XReference.xaml.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class XReference : ContentPage + { + public XReference () + { + InitializeComponent (); + } + + public XReference (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void SupportsXReference (bool useCompiledXaml) + { + var layout = new XReference (useCompiledXaml); + Assert.AreSame (layout.image, layout.imageView.Content); + } + + [TestCase (false)] + [TestCase (true)] + public void XReferenceAsCommandParameterToSelf (bool useCompiledXaml) + { + var layout = new XReference (useCompiledXaml); + + var button = layout.aButton; + button.BindingContext = new { + ButtonClickCommand = new Command (o => { + if (o == button) + Assert.Pass (); + }) + }; + ((IButtonController) button).SendClicked (); + Assert.Fail (); + } + + [TestCase (false)] + [TestCase (true)] + public void XReferenceAsBindingSource (bool useCompiledXaml) + { + var layout = new XReference (useCompiledXaml); + + Assert.AreEqual ("foo", layout.entry.Text); + Assert.AreEqual ("bar", layout.entry.Placeholder); + } + + [TestCase (false)] + [TestCase (true)] + public void CrossXReference (bool useCompiledXaml) + { + var layout = new XReference (useCompiledXaml); + + Assert.AreSame (layout.label0, layout.label1.BindingContext); + Assert.AreSame (layout.label1, layout.label0.BindingContext); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml b/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml new file mode 100644 index 00000000..7c2910cd --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml @@ -0,0 +1,14 @@ +<?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.XStatic"> + <StackLayout> + <Label x:Name="staticproperty" + Text="{x:Static Member=local:MockxStatic.MockStaticProperty}" /> + <Label x:Name="memberisoptional" + Text="{x:Static local:MockxStatic.MockStaticProperty}" /> + <Label x:Name="color" + TextColor="{x:Static local:MockxStatic.BackgroundColor}" /> + </StackLayout> +</ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs new file mode 100644 index 00000000..ff1f0199 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class MockxStatic + { + public static string MockStaticProperty { get { return "Property"; } } + public const string MockConstant = "Constant"; + public static string MockField = "Field"; + public string InstanceProperty { get { return "InstanceProperty"; } } + public static readonly Color BackgroundColor = Color.Fuchsia; + } + + public enum MockEnum + { + First, + Second, + Third, + } + + public partial class XStatic : ContentPage + { + public XStatic () + { + InitializeComponent (); + } + public XStatic (bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + public class Tests + { + [TestCase (false)] + [TestCase (true)] + public void StaticProperty (bool useCompiledXaml) + { + var layout = new XStatic (useCompiledXaml); + Assert.AreEqual ("Property", layout.staticproperty.Text); + } + + [TestCase (false)] + [TestCase (true)] + public void MemberOptional (bool useCompiledXaml) + { + var layout = new XStatic (useCompiledXaml); + Assert.AreEqual ("Property", layout.memberisoptional.Text); + } + + [TestCase (false)] + [TestCase (true)] + public void FieldColor (bool useCompiledXaml) + { + var layout = new XStatic (useCompiledXaml); + Assert.AreEqual (Color.Fuchsia, layout.color.TextColor); + } + } + } +}
\ 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 new file mode 100644 index 00000000..114b8df1 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj @@ -0,0 +1,608 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{4B14D295-C09B-4C38-B880-7CC768E50585}</ProjectGuid> + <OutputType>Library</OutputType> + <RootNamespace>Xamarin.Forms.Xaml.UnitTests</RootNamespace> + <AssemblyName>Xamarin.Forms.Xaml.UnitTests</AssemblyName> + <TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> + <RestorePackages>true</RestorePackages> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug</OutputPath> + <DefineConstants>DEBUG;</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <ConsolePause>false</ConsolePause> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>full</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release</OutputPath> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <ConsolePause>false</ConsolePause> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Turkey|AnyCPU'"> + <DebugSymbols>true</DebugSymbols> + <OutputPath>bin\Turkey\</OutputPath> + <DefineConstants>DEBUG;TURKEY</DefineConstants> + <DebugType>full</DebugType> + <PlatformTarget>AnyCPU</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> + <WarningLevel>4</WarningLevel> + <Optimize>false</Optimize> + </PropertyGroup> + <ItemGroup> + <Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL"> + <HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Mono.Cecil.Mdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL"> + <HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Mono.Cecil.Pdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL"> + <HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Mono.Cecil.Rocks, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL"> + <HintPath>..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> + <HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Xml" /> + <Reference Include="Microsoft.Build.Utilities.v4.0" /> + <Reference Include="Microsoft.Build.Framework" /> + <Reference Include="Microsoft.Build.Tasks.v4.0" /> + </ItemGroup> + <ItemGroup> + <Compile Include="..\Xamarin.Forms.Core.UnitTests\BaseTestFixture.cs"> + <Link>BaseTestFixture.cs</Link> + </Compile> + <Compile Include="..\Xamarin.Forms.Core.UnitTests\MockPlatformServices.cs"> + <Link>MockPlatformServices.cs</Link> + </Compile> + <Compile Include="FontConverterTests.cs" /> + <Compile Include="LoaderTests.cs" /> + <Compile Include="ViewExtensionsTest.cs" /> + <Compile Include="MarkupExpressionParserTests.cs" /> + <Compile Include="MarkupExtensionTests.cs" /> + <Compile Include="NameScopeTests.cs" /> + <Compile Include="OnPlatformTests.cs" /> + <Compile Include="StaticExtensionTests.cs" /> + <Compile Include="NullExtensionTests.cs" /> + <Compile Include="TypeExtensionTests.cs" /> + <Compile Include="FactoryMethodTests.cs" /> + <Compile Include="XamlgTests.cs" /> + <Compile Include="Issues\TestCases.cs" /> + <Compile Include="Issues\Issue1493.cs" /> + <Compile Include="Issues\Issue1501.cs" /> + <Compile Include="Issues\Issue1497.cs" /> + <Compile Include="Issues\Issue1545.cs" /> + <Compile Include="Issues\Issue1554.cs" /> + <Compile Include="Issues\Issue1549.cs" /> + <Compile Include="Issues\Issue1637.cs" /> + <Compile Include="Issues\Issue1564.cs" /> + <Compile Include="Issues\Issue1641.cs" /> + <Compile Include="Issues\Issue1594.cs" /> + <Compile Include="XamlgFileLockTests.cs" /> + <Compile Include="DummyBuildEngine.cs" /> + <Compile Include="Issues\Issue1794.cs" /> + <Compile Include="StyleTests.xaml.cs"> + <DependentUpon>StyleTests.xaml</DependentUpon> + </Compile> + <Compile Include="CustomXamlView.xaml.cs"> + <DependentUpon>CustomXamlView.xaml</DependentUpon> + </Compile> + <Compile Include="TriggerTests.xaml.cs"> + <DependentUpon>TriggerTests.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue2016.xaml.cs"> + <DependentUpon>Issue2016.xaml</DependentUpon> + </Compile> + <Compile Include="Compiled\FindByName.xaml.cs"> + <DependentUpon>FindByName.xaml</DependentUpon> + </Compile> + <Compile Include="Validation\SetterOnNonBP.xaml.cs"> + <DependentUpon>SetterOnNonBP.xaml</DependentUpon> + </Compile> + <Compile Include="XamlParseExceptionConstraint.cs" /> + <Compile Include="Issues\Issue2062.xaml.cs"> + <DependentUpon>Issue2062.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue2114.xaml.cs"> + <DependentUpon>Issue2114.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue2125.xaml.cs"> + <DependentUpon>Issue2125.xaml</DependentUpon> + </Compile> + <Compile Include="Validation\StaticExtensionException.xaml.cs"> + <DependentUpon>StaticExtensionException.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue2152.xaml.cs"> + <DependentUpon>Issue2152.xaml</DependentUpon> + </Compile> + <Compile Include="ImplicitConversions.xaml.cs"> + <DependentUpon>ImplicitConversions.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue2450.xaml.cs"> + <DependentUpon>Issue2450.xaml</DependentUpon> + </Compile> + <Compile Include="Validation\TypeMismatch.xaml.cs"> + <DependentUpon>TypeMismatch.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue2578.xaml.cs"> + <DependentUpon>Issue2578.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue2489.xaml.cs"> + <DependentUpon>Issue2489.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue2659.xaml.cs"> + <DependentUpon>Issue2659.xaml</DependentUpon> + </Compile> + <Compile Include="TypeLoader.xaml.cs"> + <DependentUpon>TypeLoader.xaml</DependentUpon> + </Compile> + <Compile Include="StringLiterals.xaml.cs"> + <DependentUpon>StringLiterals.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue2742.xaml.cs"> + <DependentUpon>Issue2742.xaml</DependentUpon> + </Compile> + <Compile Include="Compiled\SetValue.xaml.cs"> + <DependentUpon>SetValue.xaml</DependentUpon> + </Compile> + <Compile Include="X2009Primitives.xaml.cs"> + <DependentUpon>X2009Primitives.xaml</DependentUpon> + </Compile> + <Compile Include="XArray.xaml.cs"> + <DependentUpon>XArray.xaml</DependentUpon> + </Compile> + <Compile Include="XReference.xaml.cs"> + <DependentUpon>XReference.xaml</DependentUpon> + </Compile> + <Compile Include="DataTemplate.xaml.cs"> + <DependentUpon>DataTemplate.xaml</DependentUpon> + </Compile> + <Compile Include="XNull.xaml.cs"> + <DependentUpon>XNull.xaml</DependentUpon> + </Compile> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="OnPlatform.xaml.cs"> + <DependentUpon>OnPlatform.xaml</DependentUpon> + </Compile> + <Compile Include="XStatic.xaml.cs"> + <DependentUpon>XStatic.xaml</DependentUpon> + </Compile> + <Compile Include="XamlC\FieldReferenceExtensionsTests.cs" /> + <Compile Include="XamlC\PropertyDefinitionExtensionsTests.cs" /> + <Compile Include="XamlC\MethodReferenceExtensionsTests.cs" /> + <Compile Include="DynamicResource.xaml.cs"> + <DependentUpon>DynamicResource.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue1199.xaml.cs"> + <DependentUpon>Issue1199.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue1213.xaml.cs"> + <DependentUpon>Issue1213.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue1250.xaml.cs"> + <DependentUpon>Issue1250.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue1306.xaml.cs"> + <DependentUpon>Issue1306.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue1415.xaml.cs"> + <DependentUpon>Issue1415.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue1438.xaml.cs"> + <DependentUpon>Issue1438.xaml</DependentUpon> + </Compile> + <Compile Include="Speed\SimpleContentPage.xaml.cs"> + <DependentUpon>SimpleContentPage.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue3076.xaml.cs"> + <DependentUpon>Issue3076.xaml</DependentUpon> + </Compile> + <Compile Include="ConstraintExpression.xaml.cs"> + <DependentUpon>ConstraintExpression.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue3090.xaml.cs"> + <DependentUpon>Issue3090.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Issue3106.xaml.cs"> + <DependentUpon>Issue3106.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz28689.xaml.cs"> + <DependentUpon>Bz28689.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz27863.xaml.cs"> + <DependentUpon>Bz27863.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz24910.xaml.cs"> + <DependentUpon>Bz24910.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz28719.xaml.cs"> + <DependentUpon>Bz28719.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz30074.xaml.cs"> + <DependentUpon>Bz30074.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz29300.xaml.cs"> + <DependentUpon>Bz29300.xaml</DependentUpon> + </Compile> + <Compile Include="GenericsTests.xaml.cs"> + <DependentUpon>GenericsTests.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz27968.xaml.cs"> + <DependentUpon>Bz27968.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz28545.xaml.cs"> + <DependentUpon>Bz28545.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz27299.xaml.cs"> + <DependentUpon>Bz27299.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz24485.xaml.cs"> + <DependentUpon>Bz24485.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz30684.xaml.cs"> + <DependentUpon>Bz30684.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz28556.xaml.cs"> + <DependentUpon>Bz28556.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz31234\A\Bz31234.xaml.cs"> + <DependentUpon>Bz31234.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz31234\B\Bz31234.xaml.cs"> + <DependentUpon>Bz31234.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz31529.xaml.cs"> + <DependentUpon>Bz31529.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz34037.xaml.cs"> + <DependentUpon>Bz34037.xaml</DependentUpon> + </Compile> + <Compile Include="EventsConnection.xaml.cs"> + <DependentUpon>EventsConnection.xaml</DependentUpon> + </Compile> + <Compile Include="GenericCollections.xaml.cs"> + <DependentUpon>GenericCollections.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Pr3384.xaml.cs"> + <DependentUpon>Pr3384.xaml</DependentUpon> + </Compile> + <Compile Include="FactoryMethods.xaml.cs"> + <DependentUpon>FactoryMethods.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Unreported002.xaml.cs"> + <DependentUpon>Unreported002.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Unreported001.xaml.cs"> + <DependentUpon>Unreported001.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz36422.xaml.cs"> + <DependentUpon>Bz36422.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz37306.xaml.cs"> + <DependentUpon>Bz37306.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\BPNotResolvedOnSubClass.xaml.cs"> + <DependentUpon>BPNotResolvedOnSubClass.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Bz37524.xaml.cs"> + <DependentUpon>Bz37524.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\Unreported003.xaml.cs"> + <DependentUpon>Unreported003.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\GrialIssue01.xaml.cs"> + <DependentUpon>GrialIssue01.xaml</DependentUpon> + </Compile> + <Compile Include="Issues\GrialIssue02.xaml.cs"> + <DependentUpon>GrialIssue02.xaml</DependentUpon> + </Compile> + <Compile Include="TypeConverterTestsLegacy.cs" /> + <Compile Include="TypeConverterTests.xaml.cs"> + <DependentUpon>TypeConverterTests.xaml</DependentUpon> + </Compile> + <Compile Include="IsCompiledDefault.xaml.cs"> + <DependentUpon>IsCompiledDefault.xaml</DependentUpon> + </Compile> + <Compile Include="IsCompiledSkip.xaml.cs"> + <DependentUpon>IsCompiledSkip.xaml</DependentUpon> + </Compile> + <Compile Include="McIgnorable.xaml.cs"> + <DependentUpon>McIgnorable.xaml</DependentUpon> + </Compile> + </ItemGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" /> + <ItemGroup> + <ProjectReference Include="..\Xamarin.Forms.Core\Xamarin.Forms.Core.csproj"> + <Project>{57B8B73D-C3B5-4C42-869E-7B2F17D354AC}</Project> + <Name>Xamarin.Forms.Core</Name> + </ProjectReference> + <ProjectReference Include="..\Xamarin.Forms.Platform\Xamarin.Forms.Platform.csproj"> + <Project>{67F9D3A8-F71E-4428-913F-C37AE82CDB24}</Project> + <Name>Xamarin.Forms.Platform</Name> + </ProjectReference> + <ProjectReference Include="..\Xamarin.Forms.Xaml\Xamarin.Forms.Xaml.csproj"> + <Project>{9DB2F292-8034-4E06-89AD-98BBDA4306B9}</Project> + <Name>Xamarin.Forms.Xaml</Name> + </ProjectReference> + <ProjectReference Include="..\Xamarin.Forms.Build.Tasks\Xamarin.Forms.Build.Tasks.csproj"> + <Project>{96D89208-4EB9-4451-BE73-8A9DF3D9D7B7}</Project> + <Name>Xamarin.Forms.Build.Tasks</Name> + </ProjectReference> + <ProjectReference Include="..\Xamarin.Forms.Controls\Xamarin.Forms.Controls.csproj"> + <Project>{CB9C96CE-125C-4A68-B6A1-C3FF1FBF93E1}</Project> + <Name>Xamarin.Forms.Controls</Name> + </ProjectReference> + <ProjectReference Include="..\Xamarin.Forms.Maps\Xamarin.Forms.Maps.csproj"> + <Project>{7D13BAC2-C6A4-416A-B07E-C169B199E52B}</Project> + <Name>Xamarin.Forms.Maps</Name> + </ProjectReference> + </ItemGroup> + <ProjectExtensions> + <MonoDevelop> + <Properties> + <Policies> + <StandardHeader Text="" IncludeInNewFiles="True" /> + </Policies> + </Properties> + </MonoDevelop> + </ProjectExtensions> + <ItemGroup> + <EmbeddedResource Include="CustomXamlView.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="StyleTests.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="TriggerTests.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue2016.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Validation\SetterOnNonBP.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue2062.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue2114.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue2125.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Validation\StaticExtensionException.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue2152.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="ImplicitConversions.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue2450.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Validation\TypeMismatch.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue2578.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue2489.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue2659.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="TypeLoader.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="StringLiterals.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue2742.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Compiled\FindByName.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Compiled\SetValue.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="X2009Primitives.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="XArray.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="XReference.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="DataTemplate.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="XNull.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="OnPlatform.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="XStatic.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="DynamicResource.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue1199.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue1213.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue1250.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue1306.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue1415.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue1438.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Speed\SimpleContentPage.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue3076.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="ConstraintExpression.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue3090.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Issue3106.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz28689.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz27863.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz24910.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz28719.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz30074.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz29300.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="GenericsTests.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz27968.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz28545.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz27299.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz24485.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz30684.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz28556.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz31234\A\Bz31234.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz31234\B\Bz31234.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz31529.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz34037.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="EventsConnection.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="GenericCollections.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Pr3384.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="FactoryMethods.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Unreported002.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Unreported001.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz36422.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz37306.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\BPNotResolvedOnSubClass.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Bz37524.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\Unreported003.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\GrialIssue01.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="Issues\GrialIssue02.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="TypeConverterTests.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="IsCompiledDefault.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="IsCompiledSkip.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + <EmbeddedResource Include="McIgnorable.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <None Include="app.config" /> + <None Include="packages.config" /> + </ItemGroup> + <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> + <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> + <PropertyGroup> + <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> + </PropertyGroup> + <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" /> + </Target> + <ItemGroup /> +</Project> diff --git a/Xamarin.Forms.Xaml.UnitTests/XamlC/FieldReferenceExtensionsTests.cs b/Xamarin.Forms.Xaml.UnitTests/XamlC/FieldReferenceExtensionsTests.cs new file mode 100644 index 00000000..79144f98 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XamlC/FieldReferenceExtensionsTests.cs @@ -0,0 +1,96 @@ +using System; +using System.Linq; + +using Mono.Cecil; + +using Xamarin.Forms.Build.Tasks; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.XamlcUnitTests +{ + [TestFixture] + public class FieldReferenceExtensionsTests + { + public class NonGenericClass { + public object Field; + } + + public class GenericClass<T1,T2> { + public object NonGenericField; + public T1 GenericField1; + public T2 GenericField2; + } + + public class Inheritor : GenericClass<string,double> + { + } + + ModuleDefinition module; + + [SetUp] + public void SetUp () + { + module = ModuleDefinition.CreateModule ("foo", ModuleKind.Dll); + } + + [Test] + public void ResolveGenericsOnNonGenericDoesNotThrow () + { + var type = module.Import (typeof (NonGenericClass)); + TypeReference declaringTypeReference; + FieldDefinition field = type.GetField (fd => fd.Name == "Field", out declaringTypeReference); + Assert.DoesNotThrow (() => field.ResolveGenericParameters (declaringTypeReference)); + } + + [Test] + public void NonGenericFieldOnGenericType () + { + var type = module.Import (typeof (Inheritor)); + TypeReference declaringTypeReference; + FieldDefinition field = type.GetField (fd => fd.Name == "NonGenericField", out declaringTypeReference); + Assert.AreEqual ("NonGenericField", field.Name); + Assert.AreEqual ("Xamarin.Forms.Xaml.XamlcUnitTests.FieldReferenceExtensionsTests/GenericClass`2", field.DeclaringType.FullName); + Assert.False (field.DeclaringType.IsGenericInstance); + var genericField = field.ResolveGenericParameters (declaringTypeReference); + Assert.AreEqual ("NonGenericField", genericField.Name); + Assert.AreEqual ("Xamarin.Forms.Xaml.XamlcUnitTests.FieldReferenceExtensionsTests/GenericClass`2<System.String,System.Double>", genericField.DeclaringType.FullName); + Assert.True (genericField.DeclaringType.IsGenericInstance); + } + + [Test] + public void GenericFieldOnGenericType () + { + var type = module.Import (typeof (Inheritor)); + TypeReference declaringTypeReference; + + FieldDefinition field1 = type.GetField (fd => fd.Name == "GenericField1", out declaringTypeReference); + Assert.AreEqual ("GenericField1", field1.Name); + Assert.AreEqual ("Xamarin.Forms.Xaml.XamlcUnitTests.FieldReferenceExtensionsTests/GenericClass`2", field1.DeclaringType.FullName); + Assert.False (field1.DeclaringType.IsGenericInstance); + Assert.True (field1.FieldType.IsGenericParameter); + Assert.AreEqual ("T1", field1.FieldType.FullName); + + var genericField1 = field1.ResolveGenericParameters (declaringTypeReference); + Assert.AreEqual ("GenericField1", genericField1.Name); + Assert.AreEqual ("Xamarin.Forms.Xaml.XamlcUnitTests.FieldReferenceExtensionsTests/GenericClass`2<System.String,System.Double>", genericField1.DeclaringType.FullName); + Assert.True (genericField1.DeclaringType.IsGenericInstance); + Assert.False (genericField1.FieldType.IsGenericParameter); + Assert.AreEqual ("System.String", genericField1.FieldType.FullName); + + FieldDefinition field2 = type.GetField (fd => fd.Name == "GenericField2", out declaringTypeReference); + Assert.AreEqual ("GenericField2", field2.Name); + Assert.AreEqual ("Xamarin.Forms.Xaml.XamlcUnitTests.FieldReferenceExtensionsTests/GenericClass`2", field2.DeclaringType.FullName); + Assert.False (field2.DeclaringType.IsGenericInstance); + Assert.True (field2.FieldType.IsGenericParameter); + Assert.AreEqual ("T2", field2.FieldType.FullName); + + var genericField2 = field2.ResolveGenericParameters (declaringTypeReference); + Assert.AreEqual ("GenericField2", genericField2.Name); + Assert.AreEqual ("Xamarin.Forms.Xaml.XamlcUnitTests.FieldReferenceExtensionsTests/GenericClass`2<System.String,System.Double>", genericField2.DeclaringType.FullName); + Assert.True (genericField2.DeclaringType.IsGenericInstance); + Assert.False (genericField2.FieldType.IsGenericParameter); + Assert.AreEqual ("System.Double", genericField2.FieldType.FullName); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/XamlC/MethodReferenceExtensionsTests.cs b/Xamarin.Forms.Xaml.UnitTests/XamlC/MethodReferenceExtensionsTests.cs new file mode 100644 index 00000000..ab7925ac --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XamlC/MethodReferenceExtensionsTests.cs @@ -0,0 +1,92 @@ +using System; +using System.Linq; + +using Mono.Cecil; + +using Xamarin.Forms.Build.Tasks; + +using NUnit.Framework; +using System.Collections.Generic; + +namespace Xamarin.Forms.Xaml.XamlcUnitTests +{ + [TestFixture] + public class MethodReferenceExtensionsTests + { + ModuleDefinition module; + + [SetUp] + public void SetUp () + { + module = ModuleDefinition.CreateModule ("foo", ModuleKind.Dll); + } + + [Test] + public void ResolveRowDefAdder () + { + var propertyType = module.Import(typeof (RowDefinitionCollection)); + var adderT = propertyType.GetMethods ((md, tr) => md.Name == "Add", module).Single (); + var adder = adderT.Item1; + var ptype = adderT.Item2; + Assert.AreEqual ("System.Void Xamarin.Forms.DefinitionCollection`1::Add(T)", adder.FullName); + Assert.AreEqual ("Xamarin.Forms.DefinitionCollection`1<Xamarin.Forms.RowDefinition>", ptype.FullName); + var adderRef = module.Import (adder); + Assert.AreEqual ("System.Void Xamarin.Forms.DefinitionCollection`1::Add(T)", adderRef.FullName); + adderRef = adderRef.ResolveGenericParameters (ptype, module); + Assert.AreEqual ("System.Void Xamarin.Forms.DefinitionCollection`1<Xamarin.Forms.RowDefinition>::Add(T)", adderRef.FullName); + } + + [Test] + public void GenericGetter () + { + TypeReference declaringTypeReference; + var type = module.Import (typeof (StackLayout)); + var property = type.GetProperty (pd => pd.Name == "Children", out declaringTypeReference); + Assert.AreEqual ("System.Collections.Generic.IList`1<T> Xamarin.Forms.Layout`1::Children()", property.FullName); + Assert.AreEqual ("Xamarin.Forms.Layout`1<Xamarin.Forms.View>", declaringTypeReference.FullName); + var propertyGetter = property.GetMethod; + Assert.AreEqual ("System.Collections.Generic.IList`1<T> Xamarin.Forms.Layout`1::get_Children()", propertyGetter.FullName); + var propertyGetterRef = module.Import (propertyGetter); + Assert.AreEqual ("System.Collections.Generic.IList`1<T> Xamarin.Forms.Layout`1::get_Children()", propertyGetterRef.FullName); + + propertyGetterRef = module.Import (propertyGetterRef.ResolveGenericParameters (declaringTypeReference, module)); + Assert.AreEqual ("System.Collections.Generic.IList`1<T> Xamarin.Forms.Layout`1<Xamarin.Forms.View>::get_Children()", propertyGetterRef.FullName); + var returnType = propertyGetterRef.ReturnType.ResolveGenericParameters (declaringTypeReference); + Assert.AreEqual ("System.Collections.Generic.IList`1<Xamarin.Forms.View>", returnType.FullName); + } + + [Test] + public void GetterWithGenericReturnType () + { + TypeReference declaringTypeReference; + var type = module.Import (typeof (Style)); + var property = type.GetProperty (pd => pd.Name == "Setters", out declaringTypeReference); + Assert.AreEqual ("System.Collections.Generic.IList`1<Xamarin.Forms.Setter> Xamarin.Forms.Style::Setters()", property.FullName); + Assert.AreEqual ("Xamarin.Forms.Style", declaringTypeReference.FullName); + var propertyGetter = property.GetMethod; + Assert.AreEqual ("System.Collections.Generic.IList`1<Xamarin.Forms.Setter> Xamarin.Forms.Style::get_Setters()", propertyGetter.FullName); + + var propertyGetterRef = module.Import (propertyGetter); + Assert.AreEqual ("System.Collections.Generic.IList`1<Xamarin.Forms.Setter> Xamarin.Forms.Style::get_Setters()", propertyGetterRef.FullName); + propertyGetterRef = module.Import (propertyGetterRef.ResolveGenericParameters (declaringTypeReference, module)); + Assert.AreEqual ("System.Collections.Generic.IList`1<Xamarin.Forms.Setter> Xamarin.Forms.Style::get_Setters()", propertyGetterRef.FullName); + var returnType = propertyGetterRef.ReturnType.ResolveGenericParameters (declaringTypeReference); + Assert.AreEqual ("System.Collections.Generic.IList`1<Xamarin.Forms.Setter>", returnType.FullName); + } + + [Test] + public void ResolveChildren () + { + var propertyType = module.Import (typeof (IList<View>)); + var adderT = propertyType.GetMethods (md => md.Name == "Add" && md.Parameters.Count == 1, module).Single (); + var adder = adderT.Item1; + var ptype = adderT.Item2; + Assert.AreEqual ("System.Void System.Collections.Generic.ICollection`1::Add(T)", adder.FullName); + Assert.AreEqual ("System.Collections.Generic.ICollection`1<Xamarin.Forms.View>", ptype.FullName); + var adderRef = module.Import (adder); + Assert.AreEqual ("System.Void System.Collections.Generic.ICollection`1::Add(T)", adderRef.FullName); + adderRef = adderRef.ResolveGenericParameters (ptype, module); + Assert.AreEqual ("System.Void System.Collections.Generic.ICollection`1<Xamarin.Forms.View>::Add(T)", adderRef.FullName); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/XamlC/PropertyDefinitionExtensionsTests.cs b/Xamarin.Forms.Xaml.UnitTests/XamlC/PropertyDefinitionExtensionsTests.cs new file mode 100644 index 00000000..b43e4c9d --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XamlC/PropertyDefinitionExtensionsTests.cs @@ -0,0 +1,75 @@ +using System; +using System.Linq; + +using Mono.Cecil; + +using Xamarin.Forms.Build.Tasks; + +using NUnit.Framework; + +namespace Xamarin.Forms.Xaml.XamlcUnitTests +{ + [TestFixture] + public class PropertyDefinitionExtensionsTests + { + public class NonGenericClass + { + public object Property { get; set; } + } + + public class GenericClass<T> + { + public object Property { get; set; } + public T GenericProperty { get; set; } + } + + ModuleDefinition module; + + [SetUp] + public void SetUp () + { + module = ModuleDefinition.CreateModule ("foo", ModuleKind.Dll); + } + +// [Test] +// public void ResolveGenericsOnNonGenericPreserveAccessors () +// { +// var type = module.Import (typeof (NonGenericClass)); +// TypeReference declaringTypeReference; +// PropertyDefinition prop = type.GetProperty (fd => fd.Name == "Property", out declaringTypeReference); +// Assert.AreEqual ("System.Object", prop.PropertyType.FullName); +// Assert.AreEqual ("System.Void Xamarin.Forms.Xaml.XamlcUnitTests.PropertyDefinitionExtensionsTests/NonGenericClass::set_Property(System.Object)", prop.SetMethod.FullName); +// Assert.AreEqual ("System.Object Xamarin.Forms.Xaml.XamlcUnitTests.PropertyDefinitionExtensionsTests/NonGenericClass::get_Property()", prop.GetMethod.FullName); +// Assert.AreEqual ("Xamarin.Forms.Xaml.XamlcUnitTests.PropertyDefinitionExtensionsTests/NonGenericClass", prop.DeclaringType.FullName); +// +// prop.ResolveGenericParameters (declaringTypeReference); +// +// Assert.AreEqual ("System.Object", prop.PropertyType.FullName); +// Assert.AreEqual ("System.Void Xamarin.Forms.Xaml.XamlcUnitTests.PropertyDefinitionExtensionsTests/NonGenericClass::set_Property(System.Object)", prop.SetMethod.FullName); +// Assert.AreEqual ("System.Object Xamarin.Forms.Xaml.XamlcUnitTests.PropertyDefinitionExtensionsTests/NonGenericClass::get_Property()", prop.GetMethod.FullName); +// Assert.AreEqual ("Xamarin.Forms.Xaml.XamlcUnitTests.PropertyDefinitionExtensionsTests/NonGenericClass", prop.DeclaringType.FullName); +// +// } +// +// [Test] +// public void NonGenericPropertyOnGenericType () +// { +// var type = module.Import (typeof (GenericClass<bool>)); +// TypeReference declaringTypeReference; +// PropertyDefinition prop = type.GetProperty (fd => fd.Name == "Property", out declaringTypeReference); +// Assert.AreEqual ("System.Object", prop.PropertyType.FullName); +// Assert.AreEqual ("System.Void Xamarin.Forms.Xaml.XamlcUnitTests.PropertyDefinitionExtensionsTests/GenericClass`1::set_Property(System.Object)", prop.SetMethod.FullName); +// Assert.AreEqual ("System.Object Xamarin.Forms.Xaml.XamlcUnitTests.PropertyDefinitionExtensionsTests/GenericClass`1::get_Property()", prop.GetMethod.FullName); +// Assert.AreEqual ("Xamarin.Forms.Xaml.XamlcUnitTests.PropertyDefinitionExtensionsTests/GenericClass`1", prop.DeclaringType.FullName); +// Assert.False (prop.DeclaringType.IsGenericInstance); +// +// prop.ResolveGenericParameters (declaringTypeReference); +// Assert.AreEqual ("System.Object", prop.PropertyType.FullName); +// Assert.AreEqual ("System.Void Xamarin.Forms.Xaml.XamlcUnitTests.PropertyDefinitionExtensionsTests/GenericClass`1::set_Property(System.Object)", prop.SetMethod.FullName); +// Assert.AreEqual ("System.Object Xamarin.Forms.Xaml.XamlcUnitTests.PropertyDefinitionExtensionsTests/GenericClass`1::get_Property()", prop.GetMethod.FullName); +// Assert.AreEqual ("Xamarin.Forms.Xaml.XamlcUnitTests.PropertyDefinitionExtensionsTests/GenericClass`1", prop.DeclaringType.FullName); +// Assert.True (prop.DeclaringType.IsGenericInstance); +// +// } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/XamlParseExceptionConstraint.cs b/Xamarin.Forms.Xaml.UnitTests/XamlParseExceptionConstraint.cs new file mode 100644 index 00000000..cdff5ca8 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XamlParseExceptionConstraint.cs @@ -0,0 +1,67 @@ +using System; +using NUnit.Framework.Constraints; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class XamlParseExceptionConstraint : ExceptionTypeConstraint + { + bool haslineinfo; + int linenumber; + int lineposition; + Func<string, bool> messagePredicate; + + XamlParseExceptionConstraint (bool haslineinfo) : base (typeof (XamlParseException)) + { + this.haslineinfo = haslineinfo; + DisplayName = "xamlparse"; + } + + public XamlParseExceptionConstraint () : this (false) + { + } + + public XamlParseExceptionConstraint (int linenumber, int lineposition, Func<string, bool> messagePredicate = null) : this (true) + { + this.linenumber = linenumber; + this.lineposition = lineposition; + this.messagePredicate = messagePredicate; + } + + public override bool Matches (object actual) + { + this.actual = actual; + if (!base.Matches (actual)) + return false; + var xmlInfo = ((XamlParseException)actual).XmlInfo; + if (!haslineinfo) + return true; + if (xmlInfo == null || !xmlInfo.HasLineInfo ()) + return false; + if (messagePredicate != null) + if (!messagePredicate (((XamlParseException)actual).UnformattedMessage)) + return false; + return xmlInfo.LineNumber == linenumber && xmlInfo.LinePosition == lineposition; + } + + public override void WriteDescriptionTo (MessageWriter writer) + { + base.WriteDescriptionTo (writer); + if (haslineinfo) + writer.Write (string.Format (" line {0}, position {1}", linenumber, lineposition)); + } + + public override void WriteActualValueTo (MessageWriter writer) + { + var ex = actual as XamlParseException; + writer.WriteActualValue ((actual == null) ? null : actual.GetType ()); + if (ex != null) { + if (ex.XmlInfo != null && ex.XmlInfo.HasLineInfo ()) + writer.Write (" line {0}, position {1}", ex.XmlInfo.LineNumber, ex.XmlInfo.LinePosition); + else + writer.Write (" no line info"); + writer.WriteLine (" ({0})", ex.Message); + writer.Write (ex.StackTrace); + } + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/XamlgFileLockTests.cs b/Xamarin.Forms.Xaml.UnitTests/XamlgFileLockTests.cs new file mode 100644 index 00000000..4034ef5b --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XamlgFileLockTests.cs @@ -0,0 +1,43 @@ +using System; +using System.IO; +using NUnit.Framework; +using Xamarin.Forms.Build.Tasks; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class XamlgFileLockTests : BaseTestFixture + { + string CreateXamlInputFile () + { + string xaml = + @"<ContentPage xmlns='http://xamarin.com/schemas/2014/forms' xmlns:x='http://schemas.microsoft.com/winfx/2009/xaml' x:Class='Test.MyPage'> + <ContentPage.Content></ContentPage.Content> + </ContentPage>"; + + string fileName = Path.GetTempFileName (); + File.WriteAllText (fileName, xaml); + + return fileName; + } + + [Test] + public void XamlFileShouldNotBeLockedAfterFileIsGenerated () + { + string xamlInputFile = CreateXamlInputFile (); + string xamlOutputFile = Path.ChangeExtension (xamlInputFile, ".xaml.g.cs"); + var generator = new XamlGTask (); + generator.BuildEngine = new DummyBuildEngine (); + generator.AssemblyName = "Test"; + generator.Source = xamlInputFile; + generator.OutputFile = xamlOutputFile; + generator.Language = "C#"; + + generator.Execute(); + File.Delete (xamlOutputFile); + + Assert.DoesNotThrow (() => File.Delete (xamlInputFile)); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/XamlgTests.cs b/Xamarin.Forms.Xaml.UnitTests/XamlgTests.cs new file mode 100644 index 00000000..9303539e --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/XamlgTests.cs @@ -0,0 +1,300 @@ +using System; +using NUnit.Framework; +using System.IO; +using System.CodeDom; +using Xamarin.Forms.Build.Tasks; +using System.Collections.Generic; +using System.Linq; + +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + [TestFixture] + public class XamlgTests : BaseTestFixture + { + [Test] + public void LoadXaml2006 () + { + var xaml = @"<View + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" + x:Class=""Xamarin.Forms.Xaml.UnitTests.CustomView"" > + <Label x:Name=""label0""/> + </View>"; + + var reader = new StringReader (xaml); + string rootType, rootNs; + CodeTypeReference baseType; + IDictionary<string,CodeTypeReference> namesAndTypes; + + XamlGTask.ParseXaml (reader, out rootType, out rootNs, out baseType, out namesAndTypes); + Assert.NotNull (rootType); + Assert.NotNull (rootNs); + Assert.NotNull (baseType); + Assert.NotNull (namesAndTypes); + + Assert.AreEqual ("CustomView", rootType); + Assert.AreEqual ("Xamarin.Forms.Xaml.UnitTests", rootNs); + Assert.AreEqual ("Xamarin.Forms.View", baseType.BaseType); + Assert.AreEqual (1, namesAndTypes.Count); + Assert.AreEqual ("label0", namesAndTypes.First().Key); + Assert.AreEqual ("Xamarin.Forms.Label", namesAndTypes.First().Value.BaseType); + } + + [Test] + public void LoadXaml2009 () + { + var xaml = @"<View + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + x:Class=""Xamarin.Forms.Xaml.UnitTests.CustomView"" > + <Label x:Name=""label0""/> + </View>"; + + var reader = new StringReader (xaml); + string rootType, rootNs; + CodeTypeReference baseType; + IDictionary<string,CodeTypeReference> namesAndTypes; + + XamlGTask.ParseXaml (reader, out rootType, out rootNs, out baseType, out namesAndTypes); + Assert.NotNull (rootType); + Assert.NotNull (rootNs); + Assert.NotNull (baseType); + Assert.NotNull (namesAndTypes); + + Assert.AreEqual ("CustomView", rootType); + Assert.AreEqual ("Xamarin.Forms.Xaml.UnitTests", rootNs); + Assert.AreEqual ("Xamarin.Forms.View", baseType.BaseType); + Assert.AreEqual (1, namesAndTypes.Count); + Assert.AreEqual ("label0", namesAndTypes.First().Key); + Assert.AreEqual ("Xamarin.Forms.Label", namesAndTypes.First().Value.BaseType); + } + + [Test] + //https://github.com/xamarin/Duplo/issues/1207#issuecomment-47159917 + public void xNameInCustomTypes () + { + var xaml = @"<ContentPage + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + xmlns:local=""clr-namespace:CustomListViewSample;assembly=CustomListViewSample"" + x:Class=""CustomListViewSample.TestPage""> + <StackLayout + VerticalOptions=""CenterAndExpand"" + HorizontalOptions=""CenterAndExpand""> + <Label Text=""Hello, Custom Renderer!"" /> + <local:CustomListView x:Name=""listView"" + WidthRequest=""960"" CornerRadius=""50"" OutlineColor=""Blue"" /> + </StackLayout> +</ContentPage>"; + + var reader = new StringReader (xaml); + string rootType, rootNs; + CodeTypeReference baseType; + IDictionary<string,CodeTypeReference> namesAndTypes; + + XamlGTask.ParseXaml (reader, out rootType, out rootNs, out baseType, out namesAndTypes); + Assert.AreEqual (1, namesAndTypes.Count); + Assert.AreEqual ("listView", namesAndTypes.First ().Key); + Assert.AreEqual ("CustomListViewSample.CustomListView", namesAndTypes.First ().Value.BaseType); + + } + + [Test] + public void xNameInDataTemplates () + { + var xaml = @"<StackLayout + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + x:Class=""FooBar"" > + <ListView> + <ListView.ItemTemplate> + <DataTemplate> + <ViewCell> + <Label x:Name=""notincluded""/> + </ViewCell> + </DataTemplate> + </ListView.ItemTemplate> + </ListView> + <Label x:Name=""included""/> + </StackLayout>"; + var reader = new StringReader (xaml); + string rootType, rootNs; + CodeTypeReference baseType; + IDictionary<string,CodeTypeReference> namesAndTypes; + + XamlGTask.ParseXaml (reader, out rootType, out rootNs, out baseType, out namesAndTypes); + Assert.Contains ("included", namesAndTypes.Keys.ToList()); + Assert.False (namesAndTypes.Keys.Contains ("notincluded")); + Assert.AreEqual (1, namesAndTypes.Count); + } + + [Test] + public void xNameInStyles () + { + var xaml = @"<StackLayout + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + x:Class=""FooBar"" > + <StackLayout.Resources> + <ResourceDictionary> + <Style TargetType=""Label"" > + <Setter Property=""Text""> + <Setter.Value> + <Label x:Name=""notincluded"" /> + </Setter.Value> + </Setter> + </Style> + </ResourceDictionary> + </StackLayout.Resources> + </StackLayout>"; + var reader = new StringReader (xaml); + string rootType, rootNs; + CodeTypeReference baseType; + IDictionary<string,CodeTypeReference> namesAndTypes; + + XamlGTask.ParseXaml (reader, out rootType, out rootNs, out baseType, out namesAndTypes); + Assert.False (namesAndTypes.Keys.Contains ("notincluded")); + Assert.AreEqual (0, namesAndTypes.Count); + } + + [Test] + public void xTypeArgumentsOnRootElement () + { + var xaml = @"<Foo + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + x:Class=""FooBar"" + x:TypeArguments=""x:String"" + />"; + var reader = new StringReader (xaml); + string rootType, rootNs; + CodeTypeReference baseType; + IDictionary<string,CodeTypeReference> namesAndTypes; + + XamlGTask.ParseXaml (reader, out rootType, out rootNs, out baseType, out namesAndTypes); + Assert.AreEqual ("FooBar", rootType); + Assert.AreEqual ("Xamarin.Forms.Foo`1", baseType.BaseType); + Assert.AreEqual (1, baseType.TypeArguments.Count); + Assert.AreEqual ("System.String", baseType.TypeArguments [0].BaseType); + } + + [Test] + public void MulipleXTypeArgumentsOnRootElement () + { + var xaml = @"<Foo + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + x:Class=""FooBar"" + x:TypeArguments=""x:String,x:Int32"" + />"; + var reader = new StringReader (xaml); + string rootType, rootNs; + CodeTypeReference baseType; + IDictionary<string,CodeTypeReference> namesAndTypes; + + XamlGTask.ParseXaml (reader, out rootType, out rootNs, out baseType, out namesAndTypes); + Assert.AreEqual ("FooBar", rootType); + Assert.AreEqual ("Xamarin.Forms.Foo`2", baseType.BaseType); + Assert.AreEqual (2, baseType.TypeArguments.Count); + Assert.AreEqual ("System.String", baseType.TypeArguments [0].BaseType); + Assert.AreEqual ("System.Int32", baseType.TypeArguments [1].BaseType); + } + + [Test] + public void MulipleXTypeArgumentsOnRootElementWithWhitespace () + { + var xaml = @"<Foo + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + x:Class=""FooBar"" + x:TypeArguments=""x:String, x:Int32"" + />"; + var reader = new StringReader (xaml); + string rootType, rootNs; + CodeTypeReference baseType; + IDictionary<string,CodeTypeReference> namesAndTypes; + + XamlGTask.ParseXaml (reader, out rootType, out rootNs, out baseType, out namesAndTypes); + Assert.AreEqual ("FooBar", rootType); + Assert.AreEqual ("Xamarin.Forms.Foo`2", baseType.BaseType); + Assert.AreEqual (2, baseType.TypeArguments.Count); + Assert.AreEqual ("System.String", baseType.TypeArguments [0].BaseType); + Assert.AreEqual ("System.Int32", baseType.TypeArguments [1].BaseType); + } + + [Test] + public void MulipleXTypeArgumentsMulitpleNamespacesOnRootElement () + { + var xaml = @"<Foo + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + x:Class=""FooBar"" + x:TypeArguments=""nsone:IDummyInterface,nstwo:IDummyInterfaceTwo"" + xmlns:nsone=""clr-namespace:Xamarin.Forms.Xaml.UnitTests.Bugzilla24258.Interfaces"" + xmlns:nstwo=""clr-namespace:Xamarin.Forms.Xaml.UnitTests.Bugzilla24258.InterfacesTwo"" + + />"; + var reader = new StringReader (xaml); + string rootType, rootNs; + CodeTypeReference baseType; + IDictionary<string,CodeTypeReference> namesAndTypes; + + XamlGTask.ParseXaml (reader, out rootType, out rootNs, out baseType, out namesAndTypes); + Assert.AreEqual ("FooBar", rootType); + Assert.AreEqual ("Xamarin.Forms.Foo`2", baseType.BaseType); + Assert.AreEqual (2, baseType.TypeArguments.Count); + Assert.AreEqual ("Xamarin.Forms.Xaml.UnitTests.Bugzilla24258.Interfaces.IDummyInterface", baseType.TypeArguments [0].BaseType); + Assert.AreEqual ("Xamarin.Forms.Xaml.UnitTests.Bugzilla24258.InterfacesTwo.IDummyInterfaceTwo", baseType.TypeArguments [1].BaseType); + } + + [Test] + public void MulipleXTypeArgumentsMulitpleNamespacesOnRootElementWithWhitespace () + { + var xaml = @"<Foo + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + x:Class=""FooBar"" + x:TypeArguments=""nsone:IDummyInterface, nstwo:IDummyInterfaceTwo"" + xmlns:nsone=""clr-namespace:Xamarin.Forms.Xaml.UnitTests.Bugzilla24258.Interfaces"" + xmlns:nstwo=""clr-namespace:Xamarin.Forms.Xaml.UnitTests.Bugzilla24258.InterfacesTwo"" + + />"; + var reader = new StringReader (xaml); + string rootType, rootNs; + CodeTypeReference baseType; + IDictionary<string,CodeTypeReference> namesAndTypes; + + XamlGTask.ParseXaml (reader, out rootType, out rootNs, out baseType, out namesAndTypes); + Assert.AreEqual ("FooBar", rootType); + Assert.AreEqual ("Xamarin.Forms.Foo`2", baseType.BaseType); + Assert.AreEqual (2, baseType.TypeArguments.Count); + Assert.AreEqual ("Xamarin.Forms.Xaml.UnitTests.Bugzilla24258.Interfaces.IDummyInterface", baseType.TypeArguments [0].BaseType); + Assert.AreEqual ("Xamarin.Forms.Xaml.UnitTests.Bugzilla24258.InterfacesTwo.IDummyInterfaceTwo", baseType.TypeArguments [1].BaseType); + } + + [Test] + //https://bugzilla.xamarin.com/show_bug.cgi?id=33256 + public void AlwaysUseGlobalReference () + { + var xaml = @" + <ContentPage + xmlns=""http://xamarin.com/schemas/2014/forms"" + xmlns:x=""http://schemas.microsoft.com/winfx/2009/xaml"" + x:Class=""FooBar"" > + <Label x:Name=""label0""/> + </ContentPage>"; + using (var reader = new StringReader (xaml)) { + string rootType, rootNs; + CodeTypeReference baseType; + IDictionary<string,CodeTypeReference> namesAndTypes; + + XamlGTask.ParseXaml (reader, out rootType, out rootNs, out baseType, out namesAndTypes); + Assert.IsTrue (baseType.Options.HasFlag (CodeTypeReferenceOptions.GlobalReference)); + Assert.IsTrue (namesAndTypes.Values.First ().Options.HasFlag (CodeTypeReferenceOptions.GlobalReference)); + } + } + } +} + diff --git a/Xamarin.Forms.Xaml.UnitTests/app.config b/Xamarin.Forms.Xaml.UnitTests/app.config new file mode 100644 index 00000000..b1d2a5a3 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/app.config @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <runtime> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> + <dependentAssembly> + <assemblyIdentity name="Mono.Cecil" publicKeyToken="0738eb9f132ed756" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-0.9.6.0" newVersion="0.9.6.0" /> + </dependentAssembly> + </assemblyBinding> + </runtime> +</configuration>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/packages.config b/Xamarin.Forms.Xaml.UnitTests/packages.config new file mode 100644 index 00000000..86bf3eaa --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/packages.config @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Mono.Cecil" version="0.9.6.1" targetFramework="net451" /> + <package id="NUnit" version="2.6.4" targetFramework="net451" /> +</packages>
\ No newline at end of file |