2 // AssociationAttributeTest.cs
5 // Marek Habersack <mhabersack@novell.com>
7 // Copyright (C) 2010 Novell, Inc. (http://novell.com/)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Collections.Generic;
30 using System.ComponentModel.DataAnnotations;
31 using System.ComponentModel.Design;
34 using NUnit.Framework;
36 namespace MonoTests.System.ComponentModel.DataAnnotations
40 public class AssociationAttributeTest
43 public void Constructor ()
45 AssociationAttribute attr;
47 attr = new AssociationAttribute (null, "key1,key2", "key3,key4");
48 Assert.AreEqual (null, attr.Name, "#A1-1");
49 Assert.AreEqual ("key1,key2", attr.ThisKey, "#A1-2");
50 Assert.AreEqual ("key3,key4", attr.OtherKey, "#A1-3");
51 Assert.IsNotNull (attr.OtherKeyMembers, "#A2-1");
54 var list = new List<string> ();
55 foreach (string m in attr.OtherKeyMembers) {
59 Assert.AreEqual (2, count, "#A2-2");
60 Assert.AreEqual ("key3", list [0], "#A2-3");
61 Assert.AreEqual ("key4", list [1], "#A2-4");
63 Assert.IsNotNull (attr.ThisKeyMembers, "#A3-1");
66 list = new List<string> ();
67 foreach (string m in attr.ThisKeyMembers) {
71 Assert.AreEqual (2, count, "#A3-2");
72 Assert.AreEqual ("key1", list [0], "#A3-3");
73 Assert.AreEqual ("key2", list [1], "#A3-4");
75 attr = new AssociationAttribute ("name", null, "key3,key4");
76 Assert.AreEqual ("name", attr.Name, "#B1-1");
77 Assert.AreEqual (null, attr.ThisKey, "#B1-2");
78 Assert.AreEqual ("key3,key4", attr.OtherKey, "#B1-3");
79 Assert.IsNotNull (attr.OtherKeyMembers, "#B2-1");
82 list = new List<string> ();
83 foreach (string m in attr.OtherKeyMembers) {
87 Assert.AreEqual (2, count, "#B2-2");
88 Assert.AreEqual ("key3", list [0], "#B2-3");
89 Assert.AreEqual ("key4", list [1], "#B2-4");
91 // this is just sad...
93 var m = attr.ThisKeyMembers;
94 Assert.Fail ("#B2-5");
95 } catch (NullReferenceException) {
99 attr = new AssociationAttribute ("name", " key1 , key 2 ,, ,key 3 ", " ");
100 Assert.IsNotNull (attr.ThisKeyMembers, "#C1");
103 list = new List<string> ();
104 foreach (string m in attr.ThisKeyMembers) {
109 // It seems all the whitespace is removed from key names
110 Assert.AreEqual (5, count, "#C2-1");
111 Assert.AreEqual ("key1", list [0], "#C2-2");
112 Assert.AreEqual ("key2", list [1], "#C2-3");
113 Assert.AreEqual (String.Empty, list [2], "#C2-4");
114 Assert.AreEqual (String.Empty, list [3], "#C2-5");
115 Assert.AreEqual ("key3", list [4], "#C2-6");
117 Assert.IsNotNull (attr.OtherKeyMembers, "#C3");
119 list = new List<string> ();
120 foreach (string m in attr.OtherKeyMembers) {
124 Assert.AreEqual (1, count, "#C4-1");
125 Assert.AreEqual (String.Empty, list [0], "#C4-2");