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