Browse Source

Added tests for testing that property values are written correctly as attribute in XAML; namespace prefix should only be used for attached properties, and prefix should be generated and added if not already present.

pull/68/head
gumme 12 years ago
parent
commit
ee33a1c6d6
  1. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/NamespaceTests.cs
  2. 25
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/SetPropertyTests.cs

38
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/NamespaceTests.cs

@ -1,7 +1,9 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // 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) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using NUnit.Framework; using NUnit.Framework;
namespace ICSharpCode.WpfDesign.Tests.Designer namespace ICSharpCode.WpfDesign.Tests.Designer
@ -105,6 +107,18 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
public class CustomButton : Button public class CustomButton : Button
{ {
public static readonly DependencyProperty TestAttachedProperty = DependencyProperty.RegisterAttached("TestAttached", typeof(double), typeof(CustomButton),
new FrameworkPropertyMetadata(Double.NaN));
public static double GetTestAttached(UIElement element)
{
return (double)element.GetValue(TestAttachedProperty);
}
public static void SetTestAttached(UIElement element, double value)
{
element.SetValue(TestAttachedProperty, value);
}
} }
public class CustomCheckBox : CheckBox public class CustomCheckBox : CheckBox
@ -116,6 +130,18 @@ namespace ICSharpCode.WpfDesign.Tests.Controls
{ {
public class CustomButton : Button public class CustomButton : Button
{ {
public static readonly DependencyProperty TestAttachedProperty = DependencyProperty.RegisterAttached("TestAttached", typeof(double), typeof(CustomButton),
new FrameworkPropertyMetadata(Double.NaN));
public static double GetTestAttached(UIElement element)
{
return (double)element.GetValue(TestAttachedProperty);
}
public static void SetTestAttached(UIElement element, double value)
{
element.SetValue(TestAttachedProperty, value);
}
} }
public class CustomCheckBox : CheckBox public class CustomCheckBox : CheckBox
@ -127,6 +153,18 @@ namespace ICSharpCode.WpfDesign.Tests.OtherControls
{ {
public class CustomButton : Button public class CustomButton : Button
{ {
public static readonly DependencyProperty TestAttachedProperty = DependencyProperty.RegisterAttached("TestAttached", typeof(double), typeof(CustomButton),
new FrameworkPropertyMetadata(Double.NaN));
public static double GetTestAttached(UIElement element)
{
return (double)element.GetValue(TestAttachedProperty);
}
public static void SetTestAttached(UIElement element, double value)
{
element.SetValue(TestAttachedProperty, value);
}
} }
public class CustomCheckBox : CheckBox public class CustomCheckBox : CheckBox

25
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/SetPropertyTests.cs

@ -3,6 +3,7 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Markup; using System.Windows.Markup;
@ -47,5 +48,29 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
button.Properties.GetProperty("Content").SetValue("Hello World!"); button.Properties.GetProperty("Content").SetValue("Hello World!");
AssertCanvasDesignerOutput("<Button Width=\"100\" Height=\"200\" Content=\"Hello World!\" />", button.Context); AssertCanvasDesignerOutput("<Button Width=\"100\" Height=\"200\" Content=\"Hello World!\" />", button.Context);
} }
[Test]
public void SetAttachedProperties()
{
DesignItem button = CreateCanvasContext("<Button />");
button.Properties.GetAttachedProperty(Grid.ColumnProperty).SetValue(0);
button.Properties.GetAttachedProperty(CustomButton.TestAttachedProperty).SetValue(0);
button.Properties.GetAttachedProperty(ICSharpCode.WpfDesign.Tests.Controls.CustomButton.TestAttachedProperty).SetValue(0);
button.Properties.GetAttachedProperty(ICSharpCode.WpfDesign.Tests.OtherControls.CustomButton.TestAttachedProperty).SetValue(0);
AssertCanvasDesignerOutput("<Button Grid.Column=\"0\" t:CustomButton.TestAttached=\"0\" sdtcontrols:CustomButton.TestAttached=\"0\" Controls0:CustomButton.TestAttached=\"0\" />",
button.Context,
"xmlns:sdtcontrols=\"http://sharpdevelop.net/WpfDesign/Tests/Controls\"",
"xmlns:Controls0=\"clr-namespace:ICSharpCode.WpfDesign.Tests.OtherControls;assembly=ICSharpCode.WpfDesign.Tests\"");
}
[Test]
public void SetInstanceProperty()
{
DesignItem button = CreateCanvasContext("<Button />");
button.Properties.GetProperty("Width").SetValue(10);
AssertCanvasDesignerOutput("<Button Width=\"10\" />", button.Context);
}
} }
} }

Loading…
Cancel
Save