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
11 using System.ComponentModel;
12 using System.ComponentModel.DataAnnotations;
14 using NUnit.Framework;
16 namespace MonoTests.System.ComponentModel.DataAnnotations
19 public class UIHintAttributeTest {
21 public void UIHintAttribute_Simple_Ctors_Set_Properties() {
22 var attr = new UIHintAttribute(null, null);
23 Assert.IsNull(attr.UIHint);
24 Assert.IsNull(attr.PresentationLayer);
25 Assert.AreEqual(0, attr.ControlParameters.Count);
27 attr = new UIHintAttribute(string.Empty, string.Empty);
28 Assert.AreEqual(string.Empty, attr.UIHint);
29 Assert.AreEqual(string.Empty, attr.PresentationLayer);
30 Assert.AreEqual(0, attr.ControlParameters.Count);
32 attr = new UIHintAttribute("theHint");
33 Assert.AreEqual("theHint", attr.UIHint);
34 Assert.IsNull(attr.PresentationLayer);
35 Assert.AreEqual(0, attr.ControlParameters.Count);
37 attr = new UIHintAttribute("theHint", "theLayer");
38 Assert.AreEqual("theHint", attr.UIHint);
39 Assert.AreEqual("theLayer", attr.PresentationLayer);
40 Assert.AreEqual(0, attr.ControlParameters.Count);
44 public void ConstructorControlParameters() {
45 Assert.AreEqual(2, new UIHintAttribute("", "", "a", 1, "b", 2).ControlParameters.Keys.Count);
49 public void ConstructorControlParameters_NoParams() {
50 Assert.AreEqual(0, new UIHintAttribute("", "", new object[0]).ControlParameters.Keys.Count);
51 Assert.AreEqual(0, new UIHintAttribute("", "", (object[])null).ControlParameters.Keys.Count);
52 Assert.AreEqual(0, new UIHintAttribute("", "").ControlParameters.Keys.Count);
53 Assert.AreEqual(0, new UIHintAttribute("").ControlParameters.Keys.Count);
57 [ExpectedException (typeof (InvalidOperationException))]
58 public void ConstructorControlParameters_UnevenNumber() {
59 var attr = new UIHintAttribute("", "", "");
60 var v = attr.ControlParameters;
64 [ExpectedException (typeof (InvalidOperationException))]
65 public void ConstructorControlParameters_NonStringKey() {
66 var attr = new UIHintAttribute("", "", 1, "value");
67 var v = attr.ControlParameters;
71 [ExpectedException (typeof (InvalidOperationException))]
72 public void ConstructorControlParameters_NullKey() {
73 var attr = new UIHintAttribute("", "", null, "value");
74 var v = attr.ControlParameters;
78 [ExpectedException (typeof (InvalidOperationException))]
79 public void ConstructorControlParameters_DuplicateKey() {
80 var attr = new UIHintAttribute("", "", "key", "value1", "key", "value2");
81 var v = attr.ControlParameters;
85 public void Equals_DifferentObjectType() {
86 Assert.IsFalse(new UIHintAttribute("foo", "bar").Equals(new object()));
90 public void Equals_NullObject() {
91 Assert.IsFalse(new UIHintAttribute("foo").Equals(null));
95 public void Equals_SameObjectType() {
96 var a1 = new UIHintAttribute("foo");
97 var a2 = new UIHintAttribute("foo");
98 var b1 = new UIHintAttribute("foo", "bar");
99 var b2 = new UIHintAttribute("foo", "bar");
101 Assert.IsTrue(a1.Equals(a2));
102 Assert.IsTrue(a2.Equals(a1));
104 Assert.IsTrue(b1.Equals(b2));
105 Assert.IsTrue(b2.Equals(b1));
107 Assert.IsFalse(a1.Equals(b1));
108 Assert.IsFalse(b1.Equals(a1));
112 public void Equals_SameObjectType_WithParamsDictionary() {
113 var a1 = new UIHintAttribute("foo", "bar", "a", 1, "b", false);
114 var a2 = new UIHintAttribute("foo", "bar", "b", false, "a", 1);
116 Assert.IsTrue(a1.Equals(a2));
117 Assert.IsTrue(a2.Equals(a1));
121 public void Equals_DoesNotThrow() {
122 var a1 = new UIHintAttribute("foo", "bar");
123 var a2 = new UIHintAttribute("foo", "bar", 1);
125 Assert.IsFalse(a1.Equals(a2));
126 Assert.IsFalse(a2.Equals(a1));
131 public void TypeId_ReturnsDifferentValuesForDifferentInstances()
133 Assert.AreNotEqual(new UIHintAttribute("foo").TypeId, new UIHintAttribute("bar").TypeId);