From 5ef8af1346af0264943b1b82790e5a72d4ceb7e1 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 1 Jun 2011 14:09:25 +0200 Subject: [PATCH] add more unit tests; use current type instead of declaring type for PropertyElements --- .../XmlBamlElement.cs | 5 +- .../XmlBamlPropertyElement.cs | 3 +- .../XmlBamlReader.cs | 9 ++- .../Tests/Cases/AvalonDockBrushes.xaml | 77 +++++++++++++++++++ .../Tests/Cases/Resources.xaml | 8 +- .../Tests/ILSpy.BamlDecompiler.Tests.csproj | 3 + .../Tests/Mocks/AvalonDock.cs | 46 +++++++++++ ILSpy.BamlDecompiler/Tests/TestRunner.cs | 8 +- 8 files changed, 149 insertions(+), 10 deletions(-) create mode 100644 ILSpy.BamlDecompiler/Tests/Cases/AvalonDockBrushes.xaml create mode 100644 ILSpy.BamlDecompiler/Tests/Mocks/AvalonDock.cs diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlElement.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlElement.cs index cc8d7f316..25d8f466f 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlElement.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlElement.cs @@ -19,6 +19,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection public XmlBamlElement(XmlBamlElement parent) { + this.Parent = parent; this.Namespaces.AddRange(parent.Namespaces); } @@ -26,7 +27,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection { get { return _namespaces; } } - + + public XmlBamlElement Parent { get; private set; } + public TypeDeclaration TypeDeclaration { get; set; } public override XmlNodeType NodeType { diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlPropertyElement.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlPropertyElement.cs index fbb312cf0..a6ce053d9 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlPropertyElement.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlPropertyElement.cs @@ -11,8 +11,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection { private readonly PropertyType _propertyType; private PropertyDeclaration propertyDeclaration; - - + public XmlBamlPropertyElement(PropertyType propertyType, PropertyDeclaration propertyDeclaration) { _propertyType = propertyType; diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs index a92ed4806..48f2f99fc 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs @@ -604,7 +604,12 @@ namespace Ricciolo.StylesExplorer.MarkupReflection else if (node is XmlBamlPropertyElement) { XmlBamlPropertyElement property = (XmlBamlPropertyElement)node; - localName = String.Format("{0}.{1}", property.TypeDeclaration.Name, property.PropertyDeclaration.Name); + string typeName = property.TypeDeclaration.Name; + + if (property.Parent.TypeDeclaration.Type.IsSubclassOf(property.PropertyDeclaration.DeclaringType.Type)) + typeName = property.Parent.TypeDeclaration.Name; + + localName = String.Format("{0}.{1}", typeName, property.PropertyDeclaration.Name); } else if (node is XmlBamlElement) localName = ((XmlBamlElement)node).TypeDeclaration.Name; @@ -1117,7 +1122,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection sb.Append(sep); sb.Append(((XmlBamlText)node).Text); } - sep = ","; + sep = ", "; } } diff --git a/ILSpy.BamlDecompiler/Tests/Cases/AvalonDockBrushes.xaml b/ILSpy.BamlDecompiler/Tests/Cases/AvalonDockBrushes.xaml new file mode 100644 index 000000000..5760368b2 --- /dev/null +++ b/ILSpy.BamlDecompiler/Tests/Cases/AvalonDockBrushes.xaml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ILSpy.BamlDecompiler/Tests/Cases/Resources.xaml b/ILSpy.BamlDecompiler/Tests/Cases/Resources.xaml index 04fc3f921..7e1a0514a 100644 --- a/ILSpy.BamlDecompiler/Tests/Cases/Resources.xaml +++ b/ILSpy.BamlDecompiler/Tests/Cases/Resources.xaml @@ -1,16 +1,16 @@  - + - + - + - + \ No newline at end of file diff --git a/ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj b/ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj index 4c65ef0e0..b13ef3e7e 100644 --- a/ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj +++ b/ILSpy.BamlDecompiler/Tests/ILSpy.BamlDecompiler.Tests.csproj @@ -74,6 +74,7 @@ Simple.xaml Code + @@ -101,9 +102,11 @@ + + Always diff --git a/ILSpy.BamlDecompiler/Tests/Mocks/AvalonDock.cs b/ILSpy.BamlDecompiler/Tests/Mocks/AvalonDock.cs new file mode 100644 index 000000000..8b177bedd --- /dev/null +++ b/ILSpy.BamlDecompiler/Tests/Mocks/AvalonDock.cs @@ -0,0 +1,46 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Windows.Media; + +namespace AvalonDock +{ + public class DockingManager + { + public DockingManager() + { + } + } + + public enum AvalonDockBrushes + { + DefaultBackgroundBrush, + DockablePaneTitleBackground, + DockablePaneTitleBackgroundSelected, + DockablePaneTitleForeground, + DockablePaneTitleForegroundSelected, + PaneHeaderCommandBackground, + PaneHeaderCommandBorderBrush, + DocumentHeaderBackground, + DocumentHeaderForeground, + DocumentHeaderForegroundSelected, + DocumentHeaderForegroundSelectedActivated, + DocumentHeaderBackgroundSelected, + DocumentHeaderBackgroundSelectedActivated, + DocumentHeaderBackgroundMouseOver, + DocumentHeaderBorderBrushMouseOver, + DocumentHeaderBorder, + DocumentHeaderBorderSelected, + DocumentHeaderBorderSelectedActivated, + NavigatorWindowTopBackground, + NavigatorWindowTitleForeground, + NavigatorWindowDocumentTypeForeground, + NavigatorWindowInfoTipForeground, + NavigatorWindowForeground, + NavigatorWindowBackground, + NavigatorWindowSelectionBackground, + NavigatorWindowSelectionBorderbrush, + NavigatorWindowBottomBackground + } +} diff --git a/ILSpy.BamlDecompiler/Tests/TestRunner.cs b/ILSpy.BamlDecompiler/Tests/TestRunner.cs index 4211d4102..ddd4014f3 100644 --- a/ILSpy.BamlDecompiler/Tests/TestRunner.cs +++ b/ILSpy.BamlDecompiler/Tests/TestRunner.cs @@ -37,6 +37,12 @@ namespace ILSpy.BamlDecompiler.Tests RunTest("cases/resources"); } + [Test] + public void AvalonDockBrushes() + { + RunTest("cases/avalondockbrushes"); + } + #region RunTest void RunTest(string name) { @@ -48,7 +54,7 @@ namespace ILSpy.BamlDecompiler.Tests XDocument document = BamlResourceEntryNode.LoadIntoDocument(new DefaultAssemblyResolver(), assembly, bamlStream); string path = Path.Combine("..\\..\\Tests", name + ".xaml"); - CodeAssert.AreEqual(document.ToString(), File.ReadAllText(path)); + CodeAssert.AreEqual(File.ReadAllText(path), document.ToString()); } Stream LoadBaml(Resource res, string name)