Merge pull request #2247 from ivmai/match-ext-libgc-api
[mono.git] / mcs / class / System.ComponentModel.DataAnnotations / Test / System.ComponentModel.DataAnnotations / UIHintAttributeTest.cs
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.
5
6 // https://silverlight.svn.codeplex.com/svn/Release/Silverlight4/Source/RiaClient.Tests/System.ComponentModel.DataAnnotations/UIHintAttributeTest.cs
7
8
9 using System;
10 using System.ComponentModel;
11 using System.ComponentModel.DataAnnotations;
12
13 using NUnit.Framework;
14
15 namespace MonoTests.System.ComponentModel.DataAnnotations
16 {
17     [TestFixture]
18     public class UIHintAttributeTest {
19         [Test]
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);
25
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);
30
31             attr = new UIHintAttribute("theHint");
32             Assert.AreEqual("theHint", attr.UIHint);
33             Assert.IsNull(attr.PresentationLayer);
34             Assert.AreEqual(0, attr.ControlParameters.Count);
35
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);
40         }
41
42         [Test]
43         public void ConstructorControlParameters() {
44             Assert.AreEqual(2, new UIHintAttribute("", "", "a", 1, "b", 2).ControlParameters.Keys.Count);
45         }
46
47         [Test]
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);
53         }
54
55         [Test]
56         [ExpectedException (typeof (InvalidOperationException))]
57         public void ConstructorControlParameters_UnevenNumber() {
58             var attr = new UIHintAttribute("", "", "");
59                 var v = attr.ControlParameters;
60         }
61
62         [Test]
63         [ExpectedException (typeof (InvalidOperationException))]
64         public void ConstructorControlParameters_NonStringKey() {
65             var attr = new UIHintAttribute("", "", 1, "value");
66                 var v = attr.ControlParameters;
67         }
68
69         [Test]
70         [ExpectedException (typeof (InvalidOperationException))]
71         public void ConstructorControlParameters_NullKey() {
72             var attr = new UIHintAttribute("", "", null, "value");
73                 var v = attr.ControlParameters;
74         }
75
76         [Test]
77         [ExpectedException (typeof (InvalidOperationException))]
78         public void ConstructorControlParameters_DuplicateKey() {
79             var attr = new UIHintAttribute("", "", "key", "value1", "key", "value2");
80                 var v = attr.ControlParameters;
81         }
82
83         [Test]
84         public void Equals_DifferentObjectType() {
85             Assert.IsFalse(new UIHintAttribute("foo", "bar").Equals(new object()));
86         }
87
88         [Test]
89         public void Equals_NullObject() {
90             Assert.IsFalse(new UIHintAttribute("foo").Equals(null));
91         }
92
93         [Test]
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");
99
100             Assert.IsTrue(a1.Equals(a2));
101             Assert.IsTrue(a2.Equals(a1));
102
103             Assert.IsTrue(b1.Equals(b2));
104             Assert.IsTrue(b2.Equals(b1));
105
106             Assert.IsFalse(a1.Equals(b1));
107             Assert.IsFalse(b1.Equals(a1));
108         }
109
110         [Test]
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);
114
115             Assert.IsTrue(a1.Equals(a2));
116             Assert.IsTrue(a2.Equals(a1));
117         }
118
119         [Test]
120         public void Equals_DoesNotThrow() {
121             var a1 = new UIHintAttribute("foo", "bar");
122             var a2 = new UIHintAttribute("foo", "bar", 1);
123
124             Assert.IsFalse(a1.Equals(a2));
125             Assert.IsFalse(a2.Equals(a1));
126         }
127
128 #if !SILVERLIGHT
129         [Test]
130         public void TypeId_ReturnsDifferentValuesForDifferentInstances()
131         {
132             Assert.AreNotEqual(new UIHintAttribute("foo").TypeId, new UIHintAttribute("bar").TypeId);
133         }
134 #endif
135     }
136 }
137