Browse Source

A few Unit-tests for INamescope (more to follow...)

pull/593/head
jogibear9988 11 years ago
parent
commit
9bb1062dc8
  1. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  2. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/UIHelpers.cs
  3. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj
  4. 23
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/ExampleControl.cs
  5. 132
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamescopeTest.cs
  6. 13
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamscopeTestUsercontrol.xaml
  7. 28
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamscopeTestUsercontrol.xaml.cs

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs

@ -119,7 +119,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -119,7 +119,7 @@ namespace ICSharpCode.WpfDesign.Designer
}
}
internal static void CreateVisualTree(this UIElement element)
public static void CreateVisualTree(this UIElement element)
{
try
{

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/UIHelpers.cs

@ -25,7 +25,7 @@ using System.Windows.Media; @@ -25,7 +25,7 @@ using System.Windows.Media;
namespace ICSharpCode.WpfDesign.Designer
{
static class UIHelpers
public static class UIHelpers
{
public static DependencyObject GetParentObject(this DependencyObject child)
{
@ -85,7 +85,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -85,7 +85,7 @@ namespace ICSharpCode.WpfDesign.Designer
return null;
}
public static T TryFindChild<T>(DependencyObject parent, string childName) where T : DependencyObject
public static T TryFindChild<T>(this DependencyObject parent, string childName) where T : DependencyObject
{
if (parent == null) return null;
T foundChild = null;

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj

@ -75,8 +75,13 @@ @@ -75,8 +75,13 @@
<Compile Include="XamlDom\CollectionTests.cs" />
<Compile Include="XamlDom\ExampleClass.cs" />
<Compile Include="XamlDom\ExampleClassContainer.cs" />
<Compile Include="XamlDom\ExampleControl.cs" />
<Compile Include="XamlDom\ExampleService.cs" />
<Compile Include="XamlDom\MarkupExtensionTests.cs" />
<Compile Include="XamlDom\NamescopeTest.cs" />
<Compile Include="XamlDom\NamscopeTestUsercontrol.xaml.cs">
<DependentUpon>NamscopeTestUsercontrol.xaml</DependentUpon>
</Compile>
<Compile Include="XamlDom\SamplesTests.cs" />
<Compile Include="XamlDom\SimpleLoadTests.cs" />
<Compile Include="XamlDom\SystemTypesLoadTest.cs" />
@ -106,5 +111,9 @@ @@ -106,5 +111,9 @@
<Page Include="Test.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="XamlDom\NamscopeTestUsercontrol.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
</Project>

23
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/ExampleControl.cs

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace ICSharpCode.WpfDesign.Tests.XamlDom
{
public class ExampleControl : Control
{
public object Property1
{
get { return (object)GetValue(Property1Property); }
set { SetValue(Property1Property, value); }
}
public static readonly DependencyProperty Property1Property =
DependencyProperty.Register("Property1", typeof(object), typeof(ExampleControl), new PropertyMetadata(null));
}
}

132
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamescopeTest.cs

@ -0,0 +1,132 @@ @@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Xml;
using ICSharpCode.WpfDesign.XamlDom;
using NUnit.Framework;
using ICSharpCode.WpfDesign.Designer;
namespace ICSharpCode.WpfDesign.Tests.XamlDom
{
[TestFixture]
public class NamescopeTest : TestHelper
{
/// <summary>
/// NamescopeTest 1
/// </summary>
[Test]
public void NamescopeTest1()
{
var xaml= @"
<UserControl
xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation""
xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
x:Name=""root""
>
<Grid x:Name=""rootGrid"" >
<Button x:Name=""aa"" />
<Button x:Name=""bb"" />
<t:ExampleControl Property1=""{x:Reference aa}"" />
</Grid>
</UserControl>";
var obj = XamlParser.Parse(new StringReader(xaml));
((FrameworkElement)obj.RootInstance).CreateVisualTree();
var example = ((FrameworkElement) obj.RootInstance).TryFindChild<ExampleControl>();
var buttonAa = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("aa");
Assert.AreEqual(example.Property1, buttonAa);
}
/// <summary>
/// NamescopeTest 2
/// </summary>
[Test]
public void NamescopeTest2()
{
var xaml = @"
<UserControl
xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation""
xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
x:Name=""root""
>
<Grid x:Name=""grid"" >
<Button Content=""level0"" x:Name=""aa"" />
<t:NamscopeTestUsercontrol />
<Button Content=""level0"" x:Name=""bb"" />
<t:ExampleControl Property1=""{x:Reference aa}"" />
<t:ExampleControl x:Name=""exampleb"" Property1=""{x:Reference bb}"" />
</Grid>
</UserControl>";
object officialResult = XamlReader.Load(new XmlTextReader(new StringReader(xaml)));
((FrameworkElement)officialResult).CreateVisualTree();
var example1 = ((FrameworkElement)officialResult).TryFindChild<ExampleControl>();
var exampleb1 = ((FrameworkElement)officialResult).TryFindChild<ExampleControl>("exampleb");
var buttonAa1 = ((FrameworkElement)officialResult).TryFindChild<Button>("aa");
var buttonbb1 = ((FrameworkElement)officialResult).TryFindChild<Button>("bb");
Assert.AreEqual(example1.Property1, buttonAa1);
Assert.AreNotEqual(exampleb1.Property1, buttonbb1);
var obj = XamlParser.Parse(new StringReader(xaml));
((FrameworkElement)obj.RootInstance).CreateVisualTree();
var example2 = ((FrameworkElement)obj.RootInstance).TryFindChild<ExampleControl>();
var exampleb2 = ((FrameworkElement)obj.RootInstance).TryFindChild<ExampleControl>("exampleb");
var buttonAa2 = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("aa");
var buttonbb2 = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("bb");
Assert.AreEqual(example2.Property1, buttonAa2);
Assert.AreNotEqual(exampleb2.Property1, buttonbb2);
}
/// <summary>
/// NamescopeTest 3
/// </summary>
[Test]
public void NamescopeTest3()
{
var xaml = @"
<Grid
xmlns=""http://schemas.microsoft.com/netfx/2007/xaml/presentation""
xmlns:t=""" + XamlTypeFinderTests.XamlDomTestsNamespace + @"""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
x:Name=""root""
>
<Button Content=""level0"" x:Name=""aa"" />
<t:NamscopeTestUsercontrol />
<Button Content=""level0"" x:Name=""bb"" />
<t:ExampleControl Property1=""{x:Reference aa}"" />
<t:ExampleControl x:Name=""exampleb"" Property1=""{x:Reference bb}"" />
</Grid>";
object officialResult = XamlReader.Load(new XmlTextReader(new StringReader(xaml)));
((FrameworkElement)officialResult).CreateVisualTree();
var example1 = ((FrameworkElement)officialResult).TryFindChild<ExampleControl>();
var exampleb1 = ((FrameworkElement)officialResult).TryFindChild<ExampleControl>("exampleb");
var buttonAa1 = ((FrameworkElement)officialResult).TryFindChild<Button>("aa");
var buttonbb1 = ((FrameworkElement)officialResult).TryFindChild<Button>("bb");
Assert.AreEqual(example1.Property1, buttonAa1);
Assert.AreNotEqual(exampleb1.Property1, buttonbb1);
var obj = XamlParser.Parse(new StringReader(xaml));
((FrameworkElement)obj.RootInstance).CreateVisualTree();
var example2 = ((FrameworkElement)obj.RootInstance).TryFindChild<ExampleControl>();
var exampleb2 = ((FrameworkElement)obj.RootInstance).TryFindChild<ExampleControl>("exampleb");
var buttonAa2 = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("aa");
var buttonbb2 = ((FrameworkElement)obj.RootInstance).TryFindChild<Button>("bb");
Assert.AreEqual(example2.Property1, buttonAa2);
Assert.AreNotEqual(exampleb2.Property1, buttonbb2);
}
}
}

13
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamscopeTestUsercontrol.xaml

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
<UserControl x:Class="ICSharpCode.WpfDesign.Tests.XamlDom.NamscopeTestUsercontrol"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ICSharpCode.WpfDesign.Tests.XamlDom"
mc:Ignorable="d" x:Name="usercontrol"
d:DesignHeight="300" d:DesignWidth="300">
<Grid x:Name="grid">
<Button x:Name="aa" Content="level1" />
<Button x:Name="bb" Content="level1" />
</Grid>
</UserControl>

28
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamscopeTestUsercontrol.xaml.cs

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ICSharpCode.WpfDesign.Tests.XamlDom
{
/// <summary>
/// Interaction logic for NamscopeTestUsercontrol.xaml
/// </summary>
public partial class NamscopeTestUsercontrol : UserControl
{
public NamscopeTestUsercontrol()
{
InitializeComponent();
}
}
}
Loading…
Cancel
Save