summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Pages.UnitTests
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-04-24 12:25:26 -0400
committerRui Marinho <me@ruimarinho.net>2016-04-24 12:25:26 -0400
commit5907152c50ee2c658b266f2804e6b383bb15a6f1 (patch)
tree9beb907623359723456c5c03b08922bebc4f41f3 /Xamarin.Forms.Pages.UnitTests
parentfeac1ba3ed6df5e27b3fa2076bd15c190cbacd1c (diff)
downloadxamarin-forms-5907152c50ee2c658b266f2804e6b383bb15a6f1.tar.gz
xamarin-forms-5907152c50ee2c658b266f2804e6b383bb15a6f1.tar.bz2
xamarin-forms-5907152c50ee2c658b266f2804e6b383bb15a6f1.zip
Evolve feature branch (#117)
* Initial import of evolve features * [Android] Add Xamarin.Forms.Platform.Android.AppLinks project * [iOS] Fix issues with c# 6 features on iOS AppLinks * Added naive stanza to update-docs-windows.bat to produce Pages docs. Not tested. (#69) * Update packages * Add AppLinks android nuspec and fix linker issues * Fix build * Fix nusepc * Fix nuspec * Update android support nugets to 23.2.1 * Update Xamarin.UITest * Add CardView * [iOS] Fix app link for CoreSpotlight * [Android] Update AppLinks android support libs * Add Newtonsoft.Json dependency to nuspec * Fix NRE when setting ControlTemplate to null * Move to ModernHttpClient for download * Try fix build * Preserve android app links * Fix margin issue * General coding and simple fixes
Diffstat (limited to 'Xamarin.Forms.Pages.UnitTests')
-rw-r--r--Xamarin.Forms.Pages.UnitTests/DataPageTests.cs165
-rw-r--r--Xamarin.Forms.Pages.UnitTests/DataSourceListTests.cs81
-rw-r--r--Xamarin.Forms.Pages.UnitTests/IntegrationTests.cs150
-rw-r--r--Xamarin.Forms.Pages.UnitTests/Properties/AssemblyInfo.cs36
-rw-r--r--Xamarin.Forms.Pages.UnitTests/Xamarin.Forms.Pages.UnitTests.csproj92
-rw-r--r--Xamarin.Forms.Pages.UnitTests/packages.config5
6 files changed, 529 insertions, 0 deletions
diff --git a/Xamarin.Forms.Pages.UnitTests/DataPageTests.cs b/Xamarin.Forms.Pages.UnitTests/DataPageTests.cs
new file mode 100644
index 00000000..49fe38b2
--- /dev/null
+++ b/Xamarin.Forms.Pages.UnitTests/DataPageTests.cs
@@ -0,0 +1,165 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
+
+namespace Xamarin.Forms.Pages.UnitTests
+{
+ [TestFixture]
+ public class DataPageTests
+ {
+ [SetUp]
+ public void Setup ()
+ {
+ Device.PlatformServices = new MockPlatformServices ();
+ }
+
+ [TearDown]
+ public void TearDown ()
+ {
+ Device.PlatformServices = null;
+ }
+
+ class TestDataPage : DataPage
+ {
+ public static readonly BindableProperty NameProperty =
+ BindableProperty.Create (nameof (Name), typeof (string), typeof (TestDataPage), null);
+
+ public string Name
+ {
+ get { return (string)GetValue (NameProperty); }
+ set { SetValue (NameProperty, value); }
+ }
+
+ public TestDataPage ()
+ {
+ SetBinding (NameProperty, new DataSourceBinding ("Name"));
+ }
+ }
+
+ class DataSource : BaseDataSource
+ {
+ ObservableCollection<IDataItem> data = new ObservableCollection<IDataItem> ();
+ protected override Task<IList<IDataItem>> GetRawData ()
+ {
+ return Task.FromResult<IList<IDataItem>> (data);
+ }
+
+ protected override object GetValue (string key)
+ {
+ var target = data.FirstOrDefault (d => d.Name == key);
+ if (target == null)
+ throw new KeyNotFoundException ();
+ return target.Value;
+ }
+
+ protected override bool SetValue (string key, object value)
+ {
+ var target = data.FirstOrDefault (d => d.Name == key);
+ if (target == null)
+ data.Add (new DataItem (key, value));
+ else if (target.Value == value)
+ return false;
+ else
+ target.Value = value;
+ return true;
+ }
+ }
+
+ [Test]
+ public void DefaultBindingsLoad ()
+ {
+ IDataSource dataSource = new DataSource ();
+ dataSource["Name"] = "Jason";
+
+ var detailpage = new TestDataPage ();
+ detailpage.Platform = new UnitPlatform ();
+ detailpage.DataSource = dataSource;
+
+ Assert.AreEqual ("Jason", detailpage.Name);
+ }
+
+ [Test]
+ public void RebindingDataSource ()
+ {
+ IDataSource dataSource = new DataSource ();
+ dataSource["UserName"] = "Jason";
+
+ var detailpage = new TestDataPage ();
+ detailpage.Platform = new UnitPlatform ();
+ detailpage.SetBinding (TestDataPage.NameProperty, new DataSourceBinding ("UserName"));
+ detailpage.DataSource = dataSource;
+
+ Assert.AreEqual ("Jason", detailpage.Name);
+ }
+
+ [Test]
+ public void RebindingDataSourceNotMasked ()
+ {
+ IDataSource dataSource = new DataSource ();
+ dataSource["UserName"] = "Jason";
+
+ var detailpage = new TestDataPage ();
+ detailpage.Platform = new UnitPlatform ();
+ detailpage.DataSource = dataSource;
+
+ detailpage.SetBinding (TestDataPage.NameProperty, new DataSourceBinding ("UserName"));
+ Assert.AreEqual ("Jason", detailpage.Name);
+
+ Assert.AreEqual (1, detailpage.DataSource.MaskedKeys.Count ());
+ }
+
+ [Test]
+ public void UpdateDataSource ()
+ {
+ IDataSource dataSource = new DataSource ();
+ dataSource["UserName"] = "Jason";
+
+ var detailpage = new TestDataPage ();
+ detailpage.Platform = new UnitPlatform ();
+ detailpage.SetBinding (TestDataPage.NameProperty, new DataSourceBinding ("UserName"));
+ detailpage.DataSource = dataSource;
+
+ dataSource["UserName"] = "Jerry";
+
+ Assert.AreEqual ("Jerry", detailpage.Name);
+ }
+
+ [Test]
+ public void MaskedItemsNotInData ()
+ {
+ IDataSource dataSource = new DataSource ();
+ dataSource["Name"] = "Jason";
+ dataSource["Other"] = "Foo";
+
+ var detailpage = new TestDataPage ();
+ detailpage.Platform = new UnitPlatform ();
+ detailpage.DataSource = dataSource;
+
+ Assert.AreEqual ("Jason", detailpage.Name);
+
+ Assert.AreEqual (1, detailpage.Data.Count ());
+ Assert.AreEqual ("Other", detailpage.Data.First ().Name);
+ }
+
+ [Test]
+ public void TwoWayDataSourceBinding ()
+ {
+ IDataSource dataSource = new DataSource ();
+ dataSource["UserName"] = "Jason";
+
+ var detailpage = new TestDataPage ();
+ detailpage.Platform = new UnitPlatform ();
+ detailpage.SetBinding (TestDataPage.NameProperty, new DataSourceBinding ("UserName", BindingMode.TwoWay));
+ detailpage.DataSource = dataSource;
+
+ ((IElementController)detailpage).SetValueFromRenderer (TestDataPage.NameProperty, "John");
+
+ Assert.AreEqual ("John", dataSource["UserName"]);
+ }
+ }
+}
diff --git a/Xamarin.Forms.Pages.UnitTests/DataSourceListTests.cs b/Xamarin.Forms.Pages.UnitTests/DataSourceListTests.cs
new file mode 100644
index 00000000..4585e0d6
--- /dev/null
+++ b/Xamarin.Forms.Pages.UnitTests/DataSourceListTests.cs
@@ -0,0 +1,81 @@
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Net.NetworkInformation;
+using System.Threading.Tasks;
+using NUnit.Framework;
+
+namespace Xamarin.Forms.Pages.UnitTests
+{
+ [TestFixture]
+ public class DataSourceListTests
+ {
+ public class TestDataSource : BaseDataSource
+ {
+ public ObservableCollection<IDataItem> DataItems { get; } = new ObservableCollection<IDataItem> ();
+
+ protected override Task<IList<IDataItem>> GetRawData ()
+ {
+ return Task.FromResult<IList<IDataItem>> (DataItems);
+ }
+
+ protected override object GetValue (string key)
+ {
+ var target = DataItems.FirstOrDefault (d => d.Name == key);
+ if (target == null)
+ throw new KeyNotFoundException ();
+ return target.Value;
+ }
+
+ protected override bool SetValue (string key, object value)
+ {
+ var target = DataItems.FirstOrDefault (d => d.Name == key);
+ if (target == null)
+ DataItems.Add (new DataItem (key, value));
+ else if (target.Value == value)
+ return false;
+ else
+ target.Value = value;
+ return true;
+ }
+ }
+
+ [Test]
+ public void DataSourceListIndexer ()
+ {
+ var source = new TestDataSource ();
+ IDataSource s = source;
+ source.DataItems.Add (new DataItem ("Foo", "Bar"));
+
+ Assert.AreEqual ("Bar", s["Foo"]);
+
+ Assert.AreEqual ("Bar", s.Data[0].Value);
+ }
+
+ [Test]
+ public void CompoundListPrepend ()
+ {
+ var source = new TestDataSource ();
+ IDataSource s = source;
+ source.DataItems.Add (new DataItem ("Foo1", "Bar1"));
+ source.DataItems.Add (new DataItem ("Foo2", "Bar2"));
+
+ var compoundList = new CompoundCollection {
+ MainList = s.Data
+ };
+ var prependItem = new DataItem ("Pre1", "Val1");
+ compoundList.PrependList.Add (prependItem);
+
+ Assert.AreEqual (prependItem, compoundList[0]);
+ Assert.AreEqual (source.DataItems[0], s.Data[0]);
+ Assert.AreEqual (source.DataItems[1], s.Data[1]);
+
+ Assert.AreEqual (source.DataItems[0], compoundList[1]);
+ Assert.AreEqual (source.DataItems[1], compoundList[2]);
+
+ s.MaskKey ("Foo1");
+
+ Assert.AreEqual (source.DataItems[1], compoundList[1]);
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Pages.UnitTests/IntegrationTests.cs b/Xamarin.Forms.Pages.UnitTests/IntegrationTests.cs
new file mode 100644
index 00000000..480706fc
--- /dev/null
+++ b/Xamarin.Forms.Pages.UnitTests/IntegrationTests.cs
@@ -0,0 +1,150 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
+
+namespace Xamarin.Forms.Pages.UnitTests
+{
+ [TestFixture]
+ internal class IntegrationTests
+ {
+ [SetUp]
+ public void Setup ()
+ {
+ Device.PlatformServices = new MockPlatformServices ();
+ }
+
+ [TearDown]
+ public void TearDown ()
+ {
+ Device.PlatformServices = null;
+ }
+
+ public class SimpleDataSource : BaseDataSource
+ {
+ readonly ObservableCollection<IDataItem> dataItems = new ObservableCollection<IDataItem> ();
+ string json;
+
+ public SimpleDataSource ()
+ {
+ Json = @"{
+ 'Name' : 'Jason Smith',
+ 'Phone' : '(555)248-7561',
+ 'PrimaryEmail' : 'jason@xamarin.com',
+ 'JobTitle' : 'Software Engineering Manager',
+ 'TimeZone' : 'PST',
+ 'Image' : 'https://c1.staticflickr.com/3/2877/10612763564_7f2d1734ea_b.jpg',
+ 'Address' : '430 Pacific Ave, San Francisico CA, 55592',
+}";
+ }
+
+ public string Json
+ {
+ get { return json; }
+ set
+ {
+ json = value;
+ try {
+ var dict = JsonConvert.DeserializeObject<Dictionary<string, object>> (json);
+ foreach (var kvp in dict)
+ dataItems.Add (new DataItem (kvp.Key, kvp.Value));
+ } catch (Exception ex) {
+ Debug.WriteLine (ex.Message);
+ }
+ }
+ }
+
+ protected override Task<IList<IDataItem>> GetRawData ()
+ {
+ return Task.FromResult<IList<IDataItem>> (dataItems);
+ }
+
+ protected override object GetValue (string key)
+ {
+ var target = dataItems.FirstOrDefault (d => d.Name == key);
+ if (target == null)
+ return null;
+ //throw new KeyNotFoundException ();
+ return target.Value;
+ }
+
+ protected override bool SetValue (string key, object value)
+ {
+ var target = dataItems.FirstOrDefault (d => d.Name == key);
+ if (target == null) {
+ dataItems.Add (new DataItem (key, value));
+ return true;
+ }
+ if (target.Value == value)
+ return false;
+ target.Value = value;
+ return true;
+ }
+ }
+
+ public class TestPage : PersonDetailPage
+ {
+ public TestPage ()
+ {
+ SetBinding (DisplayNameProperty, new DataSourceBinding ("Name"));
+ SetBinding (PhoneNumberProperty, new DataSourceBinding ("Phone"));
+ SetBinding (EmailProperty, new DataSourceBinding ("PrimaryEmail"));
+ }
+ }
+
+ [Test]
+ public void Test1 ()
+ {
+ var page = new TestPage ();
+
+ page.DataSource = new SimpleDataSource ();
+ page.Platform = new UnitPlatform();
+
+ Assert.AreEqual (9, page.DataSource.MaskedKeys.Count ());
+ }
+
+ [Test]
+ public void JsonDataSourceComplex ()
+ {
+ var jsonDataSource = new JsonDataSource ();
+
+ var json = @"[
+ {
+ 'Name': 'Kristen Perez',
+ 'Address': 'Ap #325-3386 Ac Av.',
+ 'Phone': '(016977) 7108',
+ 'Title': 'Lorem Ipsum Dolor Incorporated',
+ 'Email': 'ac.risus.Morbi@interdum.co.uk',
+ 'List' : [
+ 'Foo', 'Bar', 'Baz'
+ ]
+ },
+ {
+ 'Name': 'Murphy Cote',
+ 'Address': '906-6938 Porttitor Ave',
+ 'Phone': '076 9223 8954',
+ 'Title': 'Vulputate Industries',
+ 'Email': 'non@consequat.ca',
+ 'List' : [ { 'Second' : 'Thing' } ]
+ },
+ {
+ 'Name': 'Nicole Valdez',
+ 'Address': '485-9530 Ut Rd.',
+ 'Phone': '0800 364 0760',
+ 'Title': 'Diam At Ltd',
+ 'Email': 'nisl@ipsum.edu'
+ }
+]";
+ jsonDataSource.Source = json;
+ Debug.WriteLine (jsonDataSource);
+ }
+ }
+}
diff --git a/Xamarin.Forms.Pages.UnitTests/Properties/AssemblyInfo.cs b/Xamarin.Forms.Pages.UnitTests/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000..3f2de233
--- /dev/null
+++ b/Xamarin.Forms.Pages.UnitTests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Xamarin.Forms.Pages.UnitTests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Xamarin.Forms.Pages.UnitTests")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("447dc60e-c485-4427-8cf7-50074c6b61de")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Xamarin.Forms.Pages.UnitTests/Xamarin.Forms.Pages.UnitTests.csproj b/Xamarin.Forms.Pages.UnitTests/Xamarin.Forms.Pages.UnitTests.csproj
new file mode 100644
index 00000000..7d211310
--- /dev/null
+++ b/Xamarin.Forms.Pages.UnitTests/Xamarin.Forms.Pages.UnitTests.csproj
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{447DC60E-C485-4427-8CF7-50074C6B61DE}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Xamarin.Forms.Pages.UnitTests</RootNamespace>
+ <AssemblyName>Xamarin.Forms.Pages.UnitTests</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <TargetFrameworkProfile />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\Xamarin.Forms.Core.UnitTests\MockPlatformServices.cs">
+ <Link>MockPlatformServices.cs</Link>
+ </Compile>
+ <Compile Include="..\Xamarin.Forms.Core.UnitTests\UnitPlatform.cs">
+ <Link>UnitPlatform.cs</Link>
+ </Compile>
+ <Compile Include="DataPageTests.cs" />
+ <Compile Include="DataSourceListTests.cs" />
+ <Compile Include="IntegrationTests.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <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.Maps\Xamarin.Forms.Maps.csproj">
+ <Project>{7d13bac2-c6a4-416a-b07e-c169b199e52b}</Project>
+ <Name>Xamarin.Forms.Maps</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Xamarin.Forms.Pages\Xamarin.Forms.Pages.csproj">
+ <Project>{d6133dbd-6c60-4bd5-bea2-07e0a3927c31}</Project>
+ <Name>Xamarin.Forms.Pages</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Xamarin.Forms.Platform\Xamarin.Forms.Platform.csproj">
+ <Project>{67f9d3a8-f71e-4428-913f-c37ae82cdb24}</Project>
+ <Name>Xamarin.Forms.Platform</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/Xamarin.Forms.Pages.UnitTests/packages.config b/Xamarin.Forms.Pages.UnitTests/packages.config
new file mode 100644
index 00000000..2cf632d9
--- /dev/null
+++ b/Xamarin.Forms.Pages.UnitTests/packages.config
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" />
+ <package id="NUnit" version="2.6.2" targetFramework="net452" />
+</packages> \ No newline at end of file