Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2238 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
18 changed files with 551 additions and 22 deletions
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
// Information about this assembly is defined by the following
|
||||
// attributes.
|
||||
//
|
||||
// change them to the information which is associated with the assembly
|
||||
// you compile.
|
||||
|
||||
[assembly: AssemblyTitle("WpfDesign.Designer.Tests")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
@ -0,0 +1,97 @@
@@ -0,0 +1,97 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Text; |
||||
using System.IO; |
||||
using System.Xml; |
||||
using System.Diagnostics; |
||||
using System.Windows; |
||||
using System.Windows.Media; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Controls.Primitives; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.WpfDesign.Designer.Xaml; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer.Tests |
||||
{ |
||||
/// <summary>
|
||||
/// Base class for model tests.
|
||||
/// </summary>
|
||||
public class ModelTestHelper |
||||
{ |
||||
protected StringBuilder log; |
||||
|
||||
protected XamlDesignContext CreateContext(string xaml) |
||||
{ |
||||
log = new StringBuilder(); |
||||
XamlDesignContext context = new XamlDesignContext(new XmlTextReader(new StringReader(xaml))); |
||||
context.Services.Component.ComponentRegistered += delegate(object sender, DesignItemEventArgs e) { |
||||
log.AppendLine("Register " + ItemIdentity(e.Item)); |
||||
}; |
||||
context.Services.Component.ComponentUnregistered += delegate(object sender, DesignItemEventArgs e) { |
||||
log.AppendLine("Unregister " + ItemIdentity(e.Item)); |
||||
}; |
||||
return context; |
||||
} |
||||
|
||||
protected DesignItem CreateCanvasContext(string xaml) |
||||
{ |
||||
XamlDesignContext context = CreateContext(@"<Canvas
|
||||
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
||||
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
|
||||
" + xaml + "</Canvas>");
|
||||
Canvas canvas = (Canvas)context.RootItem.Component; |
||||
DesignItem canvasChild = context.Services.Component.GetDesignItem(canvas.Children[0]); |
||||
Assert.IsNotNull(canvasChild); |
||||
|
||||
return canvasChild; |
||||
} |
||||
|
||||
protected void AssertCanvasDesignerOutput(string expectedXaml, DesignContext context) |
||||
{ |
||||
expectedXaml = |
||||
"<?xml version=\"1.0\" encoding=\"utf-16\"?>\n" + |
||||
("<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" " + |
||||
"xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">\n" + expectedXaml.Trim()) |
||||
.Replace("\r", "").Replace("\n", "\n ") |
||||
+ "\n</Canvas>"; |
||||
|
||||
StringWriter stringWriter = new StringWriter(); |
||||
XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter); |
||||
xmlWriter.Formatting = Formatting.Indented; |
||||
context.Save(xmlWriter); |
||||
|
||||
string actualXaml = stringWriter.ToString().Replace("\r", "");; |
||||
if (expectedXaml != actualXaml) { |
||||
Debug.WriteLine("expected xaml:"); |
||||
Debug.WriteLine(expectedXaml); |
||||
Debug.WriteLine("actual xaml:"); |
||||
Debug.WriteLine(actualXaml); |
||||
} |
||||
Assert.AreEqual(expectedXaml, actualXaml); |
||||
} |
||||
|
||||
static string ItemIdentity(DesignItem item) |
||||
{ |
||||
return item.Component.GetType().Name + " (" + item.GetHashCode() + ")"; |
||||
} |
||||
|
||||
protected void AssertLog(string expectedLog) |
||||
{ |
||||
expectedLog = expectedLog.Replace("\r", ""); |
||||
string actualLog = log.ToString().Replace("\r", ""); |
||||
if (expectedLog != actualLog) { |
||||
Debug.WriteLine("expected log:"); |
||||
Debug.WriteLine(expectedLog); |
||||
Debug.WriteLine("actual log:"); |
||||
Debug.WriteLine(actualLog); |
||||
} |
||||
Assert.AreEqual(expectedLog, actualLog); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Text; |
||||
using System.IO; |
||||
using System.Xml; |
||||
using System.Diagnostics; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.WpfDesign.Designer.Xaml; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class ModelTests : ModelTestHelper |
||||
{ |
||||
[Test] |
||||
public void SetButtonWidth() |
||||
{ |
||||
DesignItem button = CreateCanvasContext("<Button/>"); |
||||
button.Properties["Width"].SetValue(100.0); |
||||
AssertCanvasDesignerOutput(@"<Button Width=""100"" />", button.Context); |
||||
AssertLog(""); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<ProjectGuid>{943DBBB3-E84E-4CF4-917C-C05AFA8743C1}</ProjectGuid> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<OutputType>Library</OutputType> |
||||
<RootNamespace>ICSharpCode.WpfDesign.Designer.Tests</RootNamespace> |
||||
<AssemblyName>ICSharpCode.WpfDesign.Designer.Tests</AssemblyName> |
||||
<OutputPath>..\..\..\..\..\..\bin\UnitTests\</OutputPath> |
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||
<NoStdLib>False</NoStdLib> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>Full</DebugType> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
<Optimize>False</Optimize> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||
<DebugSymbols>False</DebugSymbols> |
||||
<DebugType>None</DebugType> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> |
||||
<RegisterForComInterop>False</RegisterForComInterop> |
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||
<BaseAddress>4194304</BaseAddress> |
||||
<PlatformTarget>AnyCPU</PlatformTarget> |
||||
<FileAlignment>4096</FileAlignment> |
||||
</PropertyGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
<ItemGroup> |
||||
<Reference Include="nunit.framework"> |
||||
<HintPath>..\..\..\..\..\Tools\NUnit\nunit.framework.dll</HintPath> |
||||
<SpecificVersion>False</SpecificVersion> |
||||
</Reference> |
||||
<Reference Include="PresentationCore" /> |
||||
<Reference Include="PresentationFramework" /> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Xml" /> |
||||
<Reference Include="WindowsBase" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="..\..\..\..\..\Main\GlobalAssemblyInfo.cs"> |
||||
<Link>GlobalAssemblyInfo.cs</Link> |
||||
</Compile> |
||||
<Compile Include="AssemblyInfo.cs" /> |
||||
<Compile Include="ModelTestHelper.cs" /> |
||||
<Compile Include="ModelTests.cs" /> |
||||
<None Include="app.config" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\..\WpfDesign\Project\WpfDesign.csproj"> |
||||
<Project>{66A378A1-E9F4-4AD5-8946-D0EC06C2902F}</Project> |
||||
<Name>WpfDesign</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\Project\WpfDesign.Designer.csproj"> |
||||
<Project>{78CC29AC-CC79-4355-B1F2-97936DF198AC}</Project> |
||||
<Name>WpfDesign.Designer</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
</Project> |
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?> |
||||
<configuration> |
||||
<configSections> |
||||
<sectionGroup name="NUnit"> |
||||
<section name="TestRunner" |
||||
type="System.Configuration.NameValueSectionHandler" /> |
||||
</sectionGroup> |
||||
</configSections> |
||||
<NUnit> |
||||
<TestRunner> |
||||
<!-- Valid values are STA,MTA. Others ignored. --> |
||||
<add key="ApartmentState" value="STA" /> |
||||
</TestRunner> |
||||
</NUnit> |
||||
</configuration> |
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
|
||||
using System; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.WpfDesign.XamlDom.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class SystemTypesLoadTest : TestHelper |
||||
{ |
||||
[Test] |
||||
public void Int32() |
||||
{ |
||||
TestLoading(@"<Int32 xmlns=""clr-namespace:System;assembly=mscorlib"">3</Int32>"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Double() |
||||
{ |
||||
TestLoading(@"<Double xmlns=""clr-namespace:System;assembly=mscorlib"">3.1</Double>"); |
||||
} |
||||
|
||||
[Test] |
||||
public void String() |
||||
{ |
||||
TestLoading(@"<String xmlns=""clr-namespace:System;assembly=mscorlib"">text</String>"); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue