From 43845558aea181053f210eb8b2ae27d1f49c02c3 Mon Sep 17 00:00:00 2001 From: "Dr.Rx" Date: Thu, 30 Aug 2018 15:37:42 -0400 Subject: [PATCH] Add tests for the string to `Type` conversion --- .../TypeConvertersControl.cs | 16 ++++++++++ .../TypeConvertersTests.xaml | 22 +++++++++++++ src/Uno.UI.Tests/Uno.UI.Tests.csproj | 1 + .../XamlReaderTests/Given_XamlReader.cs | 32 +++++++++++++------ .../XamlReaderTests/TypeConvertersControl.cs | 16 ++++++++++ .../When_TypeConverters.xamltest | 14 ++++++++ 6 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 src/SourceGenerators/XamlGenerationTests/TypeConvertersControl.cs create mode 100644 src/SourceGenerators/XamlGenerationTests/TypeConvertersTests.xaml create mode 100644 src/Uno.UI.Tests/XamlReaderTests/TypeConvertersControl.cs create mode 100644 src/Uno.UI.Tests/XamlReaderTests/When_TypeConverters.xamltest diff --git a/src/SourceGenerators/XamlGenerationTests/TypeConvertersControl.cs b/src/SourceGenerators/XamlGenerationTests/TypeConvertersControl.cs new file mode 100644 index 000000000000..d7882a8fbec8 --- /dev/null +++ b/src/SourceGenerators/XamlGenerationTests/TypeConvertersControl.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.UI.Xaml; + +namespace XamlGenerationTests +{ + public partial class TypeConvertersControl : FrameworkElement + { + public Type TypeProperty { get; set; } + + public Uri UriProperty { get; set; } + } +} diff --git a/src/SourceGenerators/XamlGenerationTests/TypeConvertersTests.xaml b/src/SourceGenerators/XamlGenerationTests/TypeConvertersTests.xaml new file mode 100644 index 000000000000..0193c3fa272a --- /dev/null +++ b/src/SourceGenerators/XamlGenerationTests/TypeConvertersTests.xaml @@ -0,0 +1,22 @@ + + + + diff --git a/src/Uno.UI.Tests/Uno.UI.Tests.csproj b/src/Uno.UI.Tests/Uno.UI.Tests.csproj index f0fc01c1fde3..d13a4fa0a6bc 100644 --- a/src/Uno.UI.Tests/Uno.UI.Tests.csproj +++ b/src/Uno.UI.Tests/Uno.UI.Tests.csproj @@ -95,6 +95,7 @@ + diff --git a/src/Uno.UI.Tests/XamlReaderTests/Given_XamlReader.cs b/src/Uno.UI.Tests/XamlReaderTests/Given_XamlReader.cs index cbc667fae721..62cbfee14ec3 100644 --- a/src/Uno.UI.Tests/XamlReaderTests/Given_XamlReader.cs +++ b/src/Uno.UI.Tests/XamlReaderTests/Given_XamlReader.cs @@ -681,15 +681,27 @@ public void When_NonDependencyProperty_Binding() Assert.AreEqual("Text", inner.MyBinding.Path.Path); } + [TestMethod] + public void When_TypeConverters() + { + var s = GetContent(nameof(When_TypeConverters)); + var r = Windows.UI.Xaml.Markup.XamlReader.Load(s) as UserControl; + + var root = (TypeConvertersControl)r.Content; + + Assert.AreEqual(typeof(TypeConvertersControl), root.TypeProperty); + Assert.AreEqual(new Uri("https://platform.uno/"), root.UriProperty); + } + private string GetContent(string testName) - { - var assembly = this.GetType().Assembly; - var name = $"{GetType().Namespace}.{testName}.xamltest"; - // "Uno.UI.Tests.XamlReaderTests.BasicReader.xamltest" - using (var stream = assembly.GetManifestResourceStream(name)) - { - return stream.ReadToEnd(); - } - } - } + { + var assembly = this.GetType().Assembly; + var name = $"{GetType().Namespace}.{testName}.xamltest"; + // "Uno.UI.Tests.XamlReaderTests.BasicReader.xamltest" + using (var stream = assembly.GetManifestResourceStream(name)) + { + return stream.ReadToEnd(); + } + } + } } diff --git a/src/Uno.UI.Tests/XamlReaderTests/TypeConvertersControl.cs b/src/Uno.UI.Tests/XamlReaderTests/TypeConvertersControl.cs new file mode 100644 index 000000000000..14b2948ce3fb --- /dev/null +++ b/src/Uno.UI.Tests/XamlReaderTests/TypeConvertersControl.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Uno.UI.Tests.XamlReaderTests +{ + public class TypeConvertersControl : FrameworkElement + { + public Type TypeProperty { get; set; } + + public Uri UriProperty { get; set; } + } +} diff --git a/src/Uno.UI.Tests/XamlReaderTests/When_TypeConverters.xamltest b/src/Uno.UI.Tests/XamlReaderTests/When_TypeConverters.xamltest new file mode 100644 index 000000000000..2ca380eaa98b --- /dev/null +++ b/src/Uno.UI.Tests/XamlReaderTests/When_TypeConverters.xamltest @@ -0,0 +1,14 @@ + + + +