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
39 public class AssociationAttributeTest
42 public void Constructor ()
44 AssociationAttribute attr;
46 attr = new AssociationAttribute (null, "key1,key2", "key3,key4");
47 Assert.AreEqual (null, attr.Name, "#A1-1");
48 Assert.AreEqual ("key1,key2", attr.ThisKey, "#A1-2");
49 Assert.AreEqual ("key3,key4", attr.OtherKey, "#A1-3");
50 Assert.IsNotNull (attr.OtherKeyMembers, "#A2-1");
53 var list = new List<string> ();
54 foreach (string m in attr.OtherKeyMembers) {
58 Assert.AreEqual (2, count, "#A2-2");
59 Assert.AreEqual ("key3", list [0], "#A2-3");
60 Assert.AreEqual ("key4", list [1], "#A2-4");
62 Assert.IsNotNull (attr.ThisKeyMembers, "#A3-1");
65 list = new List<string> ();
66 foreach (string m in attr.ThisKeyMembers) {
70 Assert.AreEqual (2, count, "#A3-2");
71 Assert.AreEqual ("key1", list [0], "#A3-3");
72 Assert.AreEqual ("key2", list [1], "#A3-4");
74 attr = new AssociationAttribute ("name", null, "key3,key4");
75 Assert.AreEqual ("name", attr.Name, "#B1-1");
76 Assert.AreEqual (null, attr.ThisKey, "#B1-2");
77 Assert.AreEqual ("key3,key4", attr.OtherKey, "#B1-3");
78 Assert.IsNotNull (attr.OtherKeyMembers, "#B2-1");
81 list = new List<string> ();
82 foreach (string m in attr.OtherKeyMembers) {
86 Assert.AreEqual (2, count, "#B2-2");
87 Assert.AreEqual ("key3", list [0], "#B2-3");
88 Assert.AreEqual ("key4", list [1], "#B2-4");
90 // this is just sad...
92 var m = attr.ThisKeyMembers;
93 Assert.Fail ("#B2-5");
94 } catch (NullReferenceException) {
98 attr = new AssociationAttribute ("name", " key1 , key 2 ,, ,key 3 ", " ");
99 Assert.IsNotNull (attr.ThisKeyMembers, "#C1");
102 list = new List<string> ();
103 foreach (string m in attr.ThisKeyMembers) {
108 // It seems all the whitespace is removed from key names
109 Assert.AreEqual (5, count, "#C2-1");
110 Assert.AreEqual ("key1", list [0], "#C2-2");
111 Assert.AreEqual ("key2", list [1], "#C2-3");
112 Assert.AreEqual (String.Empty, list [2], "#C2-4");
113 Assert.AreEqual (String.Empty, list [3], "#C2-5");
114 Assert.AreEqual ("key3", list [4], "#C2-6");
116 Assert.IsNotNull (attr.OtherKeyMembers, "#C3");
118 list = new List<string> ();
119 foreach (string m in attr.OtherKeyMembers) {
123 Assert.AreEqual (1, count, "#C4-1");
124 Assert.AreEqual (String.Empty, list [0], "#C4-2");