1 // (c) Copyright Microsoft Corporation.
2 // This source is subject to the Microsoft Public License (Ms-PL).
3 // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
4 // All other rights reserved.
6 // https://silverlight.svn.codeplex.com/svn/Release/Silverlight4/Source/RiaClient.Tests/System.ComponentModel.DataAnnotations/UIHintAttributeTest.cs
10 using System.ComponentModel;
11 using System.ComponentModel.DataAnnotations;
13 using NUnit.Framework;
15 namespace MonoTests.System.ComponentModel.DataAnnotations
18 public class UIHintAttributeTest {
20 public void UIHintAttribute_Simple_Ctors_Set_Properties() {
21 var attr = new UIHintAttribute(null, null);
22 Assert.IsNull(attr.UIHint);
23 Assert.IsNull(attr.PresentationLayer);
24 Assert.AreEqual(0, attr.ControlParameters.Count);
26 attr = new UIHintAttribute(string.Empty, string.Empty);
27 Assert.AreEqual(string.Empty, attr.UIHint);
28 Assert.AreEqual(string.Empty, attr.PresentationLayer);
29 Assert.AreEqual(0, attr.ControlParameters.Count);
31 attr = new UIHintAttribute("theHint");
32 Assert.AreEqual("theHint", attr.UIHint);
33 Assert.IsNull(attr.PresentationLayer);
34 Assert.AreEqual(0, attr.ControlParameters.Count);
36 attr = new UIHintAttribute("theHint", "theLayer");
37 Assert.AreEqual("theHint", attr.UIHint);
38 Assert.AreEqual("theLayer", attr.PresentationLayer);
39 Assert.AreEqual(0, attr.ControlParameters.Count);
43 public void ConstructorControlParameters() {
44 Assert.AreEqual(2, new UIHintAttribute("", "", "a", 1, "b", 2).ControlParameters.Keys.Count);
48 public void ConstructorControlParameters_NoParams() {
49 Assert.AreEqual(0, new UIHintAttribute("", "", new object[0]).ControlParameters.Keys.Count);
50 Assert.AreEqual(0, new UIHintAttribute("", "", (object[])null).ControlParameters.Keys.Count);
51 Assert.AreEqual(0, new UIHintAttribute("", "").ControlParameters.Keys.Count);
52 Assert.AreEqual(0, new UIHintAttribute("").ControlParameters.Keys.Count);
56 [ExpectedException (typeof (InvalidOperationException))]
57 public void ConstructorControlParameters_UnevenNumber() {
58 var attr = new UIHintAttribute("", "", "");
59 var v = attr.ControlParameters;
63 [ExpectedException (typeof (InvalidOperationException))]
64 public void ConstructorControlParameters_NonStringKey() {
65 var attr = new UIHintAttribute("", "", 1, "value");
66 var v = attr.ControlParameters;
70 [ExpectedException (typeof (InvalidOperationException))]
71 public void ConstructorControlParameters_NullKey() {
72 var attr = new UIHintAttribute("", "", null, "value");
73 var v = attr.ControlParameters;
77 [ExpectedException (typeof (InvalidOperationException))]
78 public void ConstructorControlParameters_DuplicateKey() {
79 var attr = new UIHintAttribute("", "", "key", "value1", "key", "value2");
80 var v = attr.ControlParameters;
84 public void Equals_DifferentObjectType() {
85 Assert.IsFalse(new UIHintAttribute("foo", "bar").Equals(new object()));
89 public void Equals_NullObject() {
90 Assert.IsFalse(new UIHintAttribute("foo").Equals(null));
94 public void Equals_SameObjectType() {
95 var a1 = new UIHintAttribute("foo");
96 var a2 = new UIHintAttribute("foo");
97 var b1 = new UIHintAttribute("foo", "bar");
98 var b2 = new UIHintAttribute("foo", "bar");
100 Assert.IsTrue(a1.Equals(a2));
101 Assert.IsTrue(a2.Equals(a1));
103 Assert.IsTrue(b1.Equals(b2));
104 Assert.IsTrue(b2.Equals(b1));
106 Assert.IsFalse(a1.Equals(b1));
107 Assert.IsFalse(b1.Equals(a1));
111 public void Equals_SameObjectType_WithParamsDictionary() {
112 var a1 = new UIHintAttribute("foo", "bar", "a", 1, "b", false);
113 var a2 = new UIHintAttribute("foo", "bar", "b", false, "a", 1);
115 Assert.IsTrue(a1.Equals(a2));
116 Assert.IsTrue(a2.Equals(a1));
120 public void Equals_DoesNotThrow() {
121 var a1 = new UIHintAttribute("foo", "bar");
122 var a2 = new UIHintAttribute("foo", "bar", 1);
124 Assert.IsFalse(a1.Equals(a2));
125 Assert.IsFalse(a2.Equals(a1));
130 public void TypeId_ReturnsDifferentValuesForDifferentInstances()
132 Assert.AreNotEqual(new UIHintAttribute("foo").TypeId, new UIHintAttribute("bar").TypeId);