Merge branch 'loaded-branch'
[moon.git] / test / 2.0 / moon-unit / System.Windows / StyleTest5.cs
blobc4cb944e827f154ab39297eb27e5e28222c17bb9
1 using System;
2 using System.ComponentModel;
3 using System.Globalization;
4 using System.Net;
5 using System.Windows;
6 using System.Windows.Controls;
7 using System.Windows.Controls.Primitives;
8 using System.Windows.Documents;
9 using System.Windows.Ink;
10 using System.Windows.Input;
11 using System.Windows.Markup;
12 using System.Windows.Media;
13 using System.Windows.Media.Animation;
14 using System.Windows.Shapes;
15 using System.Collections.Generic;
16 using Mono.Moonlight.UnitTesting;
17 using Microsoft.VisualStudio.TestTools.UnitTesting;
19 namespace MoonTest.System.Windows
21 [TestClass]
22 public class StyleTest5_TypeConverterOnType_MisnamedProperty {
24 public class HappyStructConverter : TypeConverter {
25 public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
27 return sourceType == typeof(string);
30 public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
32 // don't actually parse the string, just return a new HappyStruct
33 return new HappyStruct (5, 5);
37 [TypeConverter (typeof (HappyStructConverter))]
38 public struct HappyStruct {
39 public HappyStruct (int _x, int _y)
41 x = _x;
42 y = _y;
45 public int X {
46 get { return x; }
47 set { x = value; }
50 public int Y {
51 get { return y; }
52 set { y = value; }
55 public override string ToString ()
57 return string.Format ("Happy ({0},{1})", x, y);
60 private int x;
61 private int y;
64 public class HappyButton : Button {
65 public static readonly DependencyProperty HappyProperty = DependencyProperty.Register ("Happpy", typeof (HappyStruct),
66 typeof (HappyButton),
67 null);
69 public HappyStruct Happy {
70 get { return (HappyStruct)GetValue (HappyButton.HappyProperty); }
71 set { SetValue (HappyButton.HappyProperty, value); }
75 [TestMethod]
76 public void TestWithValue ()
78 HappyButton b = new HappyButton ();
79 Style s = new Style (typeof (HappyButton));
81 s.Setters.Add (new Setter (HappyButton.HappyProperty, new HappyStruct (10, 10)));
83 b.Style = s;
85 Assert.AreEqual (new HappyStruct (10, 10), b.Happy);
88 [TestMethod]
89 [MoonlightBug]
90 public void TestWithString ()
92 HappyButton b = new HappyButton ();
93 Style s = new Style (typeof (HappyButton));
95 s.Setters.Add (new Setter (HappyButton.HappyProperty, "just to invoke the type converter"));
97 b.Style = s;
99 Assert.AreEqual (new HappyStruct (5, 5), b.Happy);