Skip to content

Commit

Permalink
Merge pull request #162 from nventive/dev/dr/TypeConversion
Browse files Browse the repository at this point in the history
Add tests for the string to `Type` conversion
  • Loading branch information
dr1rrb authored Aug 30, 2018
2 parents c7b5e6a + c7b5384 commit 5f429dc
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 10 deletions.
16 changes: 16 additions & 0 deletions src/SourceGenerators/XamlGenerationTests/TypeConvertersControl.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
22 changes: 22 additions & 0 deletions src/SourceGenerators/XamlGenerationTests/TypeConvertersTests.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<UserControl
x:Class="XamlGenerationTests.TypeConvertersTests"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uConv="using:Uno.UI.Converters"
xmlns:xamlExpanded="using:Windows.Xaml.UI"
xmlns:ios="http://uno.ui/ios"
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:android="http://uno.ui/android"
xmlns:xamarin="http://uno.ui/xamarin"
xmlns:uloc="http://uno.ui/localization/1.0"
xmlns:local="using:XamlGenerationTests"
mc:Ignorable="d uloc android ios xamarin"
d:DesignHeight="300"
d:DesignWidth="400">

<local:TypeConvertersControl
TypeProperty="local:TypeConvertersControl"
UriProperty="https://platform.uno/" />
</UserControl>
1 change: 1 addition & 0 deletions src/Uno.UI.Tests/Uno.UI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<None Remove="XamlReaderTests\When_TextBlock_FontFamily.xamltest" />
<None Remove="XamlReaderTests\When_TextBlock_ImplicitRun.xamltest" />
<None Remove="XamlReaderTests\When_TextBlock_NestedSpan.xamltest" />
<None Remove="XamlReaderTests\When_TypeConverters.xamltest" />
<None Remove="XamlReaderTests\When_UserControl_With_Content.xamltest" />
<None Remove="XamlReaderTests\When_UserControl_With_Grid.xamltest" />
<None Remove="XamlReaderTests\When_VisualStateGroup.xamltest" />
Expand Down
32 changes: 22 additions & 10 deletions src/Uno.UI.Tests/XamlReaderTests/Given_XamlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
}
16 changes: 16 additions & 0 deletions src/Uno.UI.Tests/XamlReaderTests/TypeConvertersControl.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
14 changes: 14 additions & 0 deletions src/Uno.UI.Tests/XamlReaderTests/When_TypeConverters.xamltest
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:local="using:Uno.UI.Tests.XamlReaderTests"
x:Name="testPage"
mc:Ignorable="d">

<local:TypeConvertersControl
TypeProperty="local:TypeConvertersControl"
UriProperty="https://platform.uno/" />
</Page>

0 comments on commit 5f429dc

Please sign in to comment.