diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-04-24 12:25:26 -0400 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-04-24 12:25:26 -0400 |
commit | 5907152c50ee2c658b266f2804e6b383bb15a6f1 (patch) | |
tree | 9beb907623359723456c5c03b08922bebc4f41f3 /Xamarin.Forms.Pages.UnitTests/IntegrationTests.cs | |
parent | feac1ba3ed6df5e27b3fa2076bd15c190cbacd1c (diff) | |
download | xamarin-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/IntegrationTests.cs')
-rw-r--r-- | Xamarin.Forms.Pages.UnitTests/IntegrationTests.cs | 150 |
1 files changed, 150 insertions, 0 deletions
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); + } + } +} |