summaryrefslogtreecommitdiff
path: root/mcs/class/System.ComponentModel.DataAnnotations/Test/System.ComponentModel.DataAnnotations/UIHintAttributeTest.cs
blob: d0329f7e2c880b8e824aea45249969d9cc3f36c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

// https://silverlight.svn.codeplex.com/svn/Release/Silverlight4/Source/RiaClient.Tests/System.ComponentModel.DataAnnotations/UIHintAttributeTest.cs

#if NET_4_0

using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

using NUnit.Framework;

namespace MonoTests.System.ComponentModel.DataAnnotations
{
    [TestFixture]
    public class UIHintAttributeTest {
        [Test]
        [Description("Simple ctors set expected properties.")]
        public void UIHintAttribute_Simple_Ctors_Set_Properties() {
            var attr = new UIHintAttribute(null, null);
            Assert.IsNull(attr.UIHint);
            Assert.IsNull(attr.PresentationLayer);
            Assert.AreEqual(0, attr.ControlParameters.Count);

            attr = new UIHintAttribute(string.Empty, string.Empty);
            Assert.AreEqual(string.Empty, attr.UIHint);
            Assert.AreEqual(string.Empty, attr.PresentationLayer);
            Assert.AreEqual(0, attr.ControlParameters.Count);

            attr = new UIHintAttribute("theHint");
            Assert.AreEqual("theHint", attr.UIHint);
            Assert.IsNull(attr.PresentationLayer);
            Assert.AreEqual(0, attr.ControlParameters.Count);

            attr = new UIHintAttribute("theHint", "theLayer");
            Assert.AreEqual("theHint", attr.UIHint);
            Assert.AreEqual("theLayer", attr.PresentationLayer);
            Assert.AreEqual(0, attr.ControlParameters.Count);
        }

        [Test]
        public void ConstructorControlParameters() {
            Assert.AreEqual(2, new UIHintAttribute("", "", "a", 1, "b", 2).ControlParameters.Keys.Count);
        }

        [Test]
        public void ConstructorControlParameters_NoParams() {
            Assert.AreEqual(0, new UIHintAttribute("", "", new object[0]).ControlParameters.Keys.Count);
            Assert.AreEqual(0, new UIHintAttribute("", "", (object[])null).ControlParameters.Keys.Count);
            Assert.AreEqual(0, new UIHintAttribute("", "").ControlParameters.Keys.Count);
            Assert.AreEqual(0, new UIHintAttribute("").ControlParameters.Keys.Count);
        }

        [Test]
        [ExpectedException (typeof (InvalidOperationException))]
        public void ConstructorControlParameters_UnevenNumber() {
            var attr = new UIHintAttribute("", "", "");
                var v = attr.ControlParameters;
        }

        [Test]
        [ExpectedException (typeof (InvalidOperationException))]
        public void ConstructorControlParameters_NonStringKey() {
            var attr = new UIHintAttribute("", "", 1, "value");
                var v = attr.ControlParameters;
        }

        [Test]
        [ExpectedException (typeof (InvalidOperationException))]
        public void ConstructorControlParameters_NullKey() {
            var attr = new UIHintAttribute("", "", null, "value");
                var v = attr.ControlParameters;
        }

        [Test]
        [ExpectedException (typeof (InvalidOperationException))]
        public void ConstructorControlParameters_DuplicateKey() {
            var attr = new UIHintAttribute("", "", "key", "value1", "key", "value2");
                var v = attr.ControlParameters;
        }

        [Test]
        public void Equals_DifferentObjectType() {
            Assert.IsFalse(new UIHintAttribute("foo", "bar").Equals(new object()));
        }

        [Test]
        public void Equals_NullObject() {
            Assert.IsFalse(new UIHintAttribute("foo").Equals(null));
        }

        [Test]
        public void Equals_SameObjectType() {
            var a1 = new UIHintAttribute("foo");
            var a2 = new UIHintAttribute("foo");
            var b1 = new UIHintAttribute("foo", "bar");
            var b2 = new UIHintAttribute("foo", "bar");

            Assert.IsTrue(a1.Equals(a2));
            Assert.IsTrue(a2.Equals(a1));

            Assert.IsTrue(b1.Equals(b2));
            Assert.IsTrue(b2.Equals(b1));

            Assert.IsFalse(a1.Equals(b1));
            Assert.IsFalse(b1.Equals(a1));
        }

        [Test]
        public void Equals_SameObjectType_WithParamsDictionary() {
            var a1 = new UIHintAttribute("foo", "bar", "a", 1, "b", false);
            var a2 = new UIHintAttribute("foo", "bar", "b", false, "a", 1);

            Assert.IsTrue(a1.Equals(a2));
            Assert.IsTrue(a2.Equals(a1));
        }

        [Test]
        public void Equals_DoesNotThrow() {
            var a1 = new UIHintAttribute("foo", "bar");
            var a2 = new UIHintAttribute("foo", "bar", 1);

            Assert.IsFalse(a1.Equals(a2));
            Assert.IsFalse(a2.Equals(a1));
        }

#if !SILVERLIGHT
        [Test]
        public void TypeId_ReturnsDifferentValuesForDifferentInstances()
        {
            Assert.AreNotEqual(new UIHintAttribute("foo").TypeId, new UIHintAttribute("bar").TypeId);
        }
#endif
    }
}

#endif