[eglib] Prefer <langinfo.h> to <localcharset.h>
[mono.git] / mcs / class / System.ComponentModel.DataAnnotations / Test / System.ComponentModel.DataAnnotations / AssociationAttributeTest.cs
1 //
2 // AssociationAttributeTest.cs
3 //
4 // Authors:
5 //      Marek Habersack <mhabersack@novell.com>
6 //
7 // Copyright (C) 2010 Novell, Inc. (http://novell.com/)
8 //
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:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
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.
27 //
28 using System;
29 using System.Collections.Generic;
30 using System.ComponentModel.DataAnnotations;
31 using System.ComponentModel.Design;
32 using System.Text;
33
34 using NUnit.Framework;
35
36 namespace MonoTests.System.ComponentModel.DataAnnotations
37 {
38 #if NET_4_0
39         [TestFixture]
40         public class AssociationAttributeTest
41         {
42                 [Test]
43                 public void Constructor ()
44                 {
45                         AssociationAttribute attr;
46
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");
52
53                         int count = 0;
54                         var list = new List<string> ();
55                         foreach (string m in attr.OtherKeyMembers) {
56                                 count++;
57                                 list.Add (m);
58                         }
59                         Assert.AreEqual (2, count, "#A2-2");
60                         Assert.AreEqual ("key3", list [0], "#A2-3");
61                         Assert.AreEqual ("key4", list [1], "#A2-4");
62
63                         Assert.IsNotNull (attr.ThisKeyMembers, "#A3-1");
64
65                         count = 0;
66                         list = new List<string> ();
67                         foreach (string m in attr.ThisKeyMembers) {
68                                 count++;
69                                 list.Add (m);
70                         }
71                         Assert.AreEqual (2, count, "#A3-2");
72                         Assert.AreEqual ("key1", list [0], "#A3-3");
73                         Assert.AreEqual ("key2", list [1], "#A3-4");
74
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");
80
81                         count = 0;
82                         list = new List<string> ();
83                         foreach (string m in attr.OtherKeyMembers) {
84                                 count++;
85                                 list.Add (m);
86                         }
87                         Assert.AreEqual (2, count, "#B2-2");
88                         Assert.AreEqual ("key3", list [0], "#B2-3");
89                         Assert.AreEqual ("key4", list [1], "#B2-4");
90
91                         // this is just sad...
92                         try {
93                                 var m = attr.ThisKeyMembers;
94                                 Assert.Fail ("#B2-5");
95                         } catch (NullReferenceException) {
96                                 // success
97                         }
98
99                         attr = new AssociationAttribute ("name", " key1  ,   key 2  ,, ,key    3  ", "       ");
100                         Assert.IsNotNull (attr.ThisKeyMembers, "#C1");
101
102                         count = 0;
103                         list = new List<string> ();
104                         foreach (string m in attr.ThisKeyMembers) {
105                                 count++;
106                                 list.Add (m);
107                         }
108
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");
116
117                         Assert.IsNotNull (attr.OtherKeyMembers, "#C3");
118                         count = 0;
119                         list = new List<string> ();
120                         foreach (string m in attr.OtherKeyMembers) {
121                                 count++;
122                                 list.Add (m);
123                         }
124                         Assert.AreEqual (1, count, "#C4-1");
125                         Assert.AreEqual (String.Empty, list [0], "#C4-2");
126                 }
127         }
128 #endif
129 }