summaryrefslogtreecommitdiff
path: root/mcs/class/System.ComponentModel.DataAnnotations/Test/System.ComponentModel.DataAnnotations/FilterUIHintAttributeTest.cs
blob: f1d24d7b957aa36de02867228e8a8a0812085673 (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
// (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/FilterUIHintAttributeTest.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 FilterUIHintAttributeTest {
        [Test]
        [Description("Simple ctors set expected properties.")]
        public void FilterUIHintAttribute_Simple_Ctors_Set_Properties() {
            var attr = new FilterUIHintAttribute(null, null);
            Assert.IsNull(attr.FilterUIHint);
            Assert.IsNull(attr.PresentationLayer);
            Assert.AreEqual(0, attr.ControlParameters.Count);

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

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

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

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

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

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

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

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

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

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

#endif