Merge pull request #484 from roji/transactions_pspe
[mono.git] / mcs / class / System.Data.Linq / src / DbMetal / Test / NameFormatterTest.cs
1 #region MIT license\r
2 // \r
3 // MIT license\r
4 //\r
5 // Copyright (c) 2007-2008 Jiri Moudry\r
6 // \r
7 // Permission is hereby granted, free of charge, to any person obtaining a copy\r
8 // of this software and associated documentation files (the "Software"), to deal\r
9 // in the Software without restriction, including without limitation the rights\r
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
11 // copies of the Software, and to permit persons to whom the Software is\r
12 // furnished to do so, subject to the following conditions:\r
13 // \r
14 // The above copyright notice and this permission notice shall be included in\r
15 // all copies or substantial portions of the Software.\r
16 // \r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
23 // THE SOFTWARE.\r
24 // \r
25 #endregion\r
26 \r
27 using System.Globalization;\r
28 using DbLinq;\r
29 using DbLinq.Factory;\r
30 using DbLinq.Schema;\r
31 using DbLinq.Schema.Implementation;\r
32 using DbLinq.Util;\r
33 using DbMetal;\r
34 using DbMetal.Language;\r
35 using NUnit.Framework;\r
36 \r
37 // These don't build in tools/sqlmetal\r
38 #if FALSE\r
39 \r
40 using Case = DbLinq.Schema.Case;\r
41 using WordsExtraction = DbLinq.Schema.WordsExtraction;\r
42 \r
43 namespace DbLinqTest\r
44 {\r
45     /// <summary>\r
46     /// Test for NameFormatter\r
47     /// </summary>\r
48     [TestFixture]\r
49     public class NameFormatterTest\r
50     {\r
51         private NameFormat InvariantNameFormat\r
52         {\r
53             get\r
54             {\r
55                 return new NameFormat(false, Case.PascalCase, CultureInfo.InvariantCulture);\r
56             }\r
57         }\r
58 \r
59         private NameFormat EnglishNameFormat\r
60         {\r
61             get\r
62             {\r
63                 Reference.DbLinqLocalizations();\r
64                 return new NameFormat(false, Case.NetCase, new CultureInfo("en-us"));\r
65             }\r
66         }\r
67 \r
68         private NameFormat EnglishNameFormatCamelCase\r
69         {\r
70             get\r
71             {\r
72                 Reference.DbLinqLocalizations();\r
73                 return new NameFormat(false, Case.camelCase, new CultureInfo("en-us"));\r
74             }\r
75         }\r
76 \r
77         [Test]\r
78         public void InvalidCharactersCaseTest()\r
79         {\r
80             var nf = new NameFormatter();\r
81             var tn = nf.GetTableName("A#?", WordsExtraction.FromCase, InvariantNameFormat);\r
82             Assert.AreEqual("A__", tn.ClassName);\r
83         }\r
84 \r
85         [Test]\r
86         public void InvalidCharactersLanguageTest()\r
87         {\r
88             var nf = new NameFormatter();\r
89             var tn = nf.GetTableName("A#?", WordsExtraction.FromDictionary, InvariantNameFormat);\r
90             Assert.AreEqual("A__", tn.ClassName);\r
91         }\r
92 \r
93         [Test]\r
94         public void InvalidCharactersLanguage2Test()\r
95         {\r
96             try\r
97             {\r
98                 ObjectFactory.Current.Register(typeof(EnglishWords));\r
99                 var nf = new NameFormatter();\r
100                 var tn = nf.GetTableName("Test#?", WordsExtraction.FromDictionary, EnglishNameFormat);\r
101                 Assert.AreEqual("Test__", tn.ClassName);\r
102             }\r
103             finally\r
104             {\r
105                 ObjectFactory.Current.Unregister(typeof(EnglishWords));\r
106             }\r
107         }\r
108 \r
109         [Test]\r
110         public void GetWordsTest_MyTableName()\r
111         {\r
112             try\r
113             {\r
114                 ObjectFactory.Current.Register(typeof(EnglishWords));\r
115                 var nf = new NameFormatter();\r
116                 var tn = nf.GetTableName("MY_TABLE_NAME_", WordsExtraction.FromDictionary, EnglishNameFormat);\r
117                 Assert.AreEqual("MyTableName", tn.ClassName);\r
118             }\r
119             finally\r
120             {\r
121                 ObjectFactory.Current.Unregister(typeof(EnglishWords));\r
122             }\r
123         }\r
124 \r
125         [Test]\r
126         public void GetWordsTest_MyTableName2()\r
127         {\r
128             try\r
129             {\r
130                 ObjectFactory.Current.Register(typeof(EnglishWords));\r
131                 var nf = new NameFormatter();\r
132                 var tn = nf.GetTableName("_MY_TABLE__NAME", WordsExtraction.FromDictionary, EnglishNameFormat);\r
133                 Assert.AreEqual("MyTableName", tn.ClassName);\r
134             }\r
135             finally\r
136             {\r
137                 ObjectFactory.Current.Unregister(typeof(EnglishWords));\r
138             }\r
139         }\r
140 \r
141         [Test]\r
142         public void GetWordsTest_MyColumnName()\r
143         {\r
144             try\r
145             {\r
146                 ObjectFactory.Current.Register(typeof(EnglishWords));\r
147                 var nf = new NameFormatter();\r
148                 ColumnName cn = nf.GetColumnName("MY_COLUMN_NAME_", WordsExtraction.FromDictionary, EnglishNameFormat);\r
149                 Assert.AreEqual("MyColumnName", cn.PropertyName);\r
150                 cn = nf.GetColumnName("MY_COLUMN_NAME_", WordsExtraction.FromDictionary, EnglishNameFormatCamelCase);\r
151                 Assert.AreEqual("myColumnName", cn.PropertyName);\r
152             }\r
153             finally\r
154             {\r
155                 ObjectFactory.Current.Unregister(typeof(EnglishWords));\r
156             }\r
157         }\r
158     }\r
159 }\r
160 \r
161 #endif\r