5 // Copyright (c) 2007-2008 Jiri Moudry
\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
14 // The above copyright notice and this permission notice shall be included in
\r
15 // all copies or substantial portions of the Software.
\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
27 using System.Globalization;
\r
29 using DbLinq.Factory;
\r
30 using DbLinq.Schema;
\r
31 using DbLinq.Schema.Implementation;
\r
34 using DbMetal.Language;
\r
35 using NUnit.Framework;
\r
37 // These don't build in tools/sqlmetal
\r
40 using Case = DbLinq.Schema.Case;
\r
41 using WordsExtraction = DbLinq.Schema.WordsExtraction;
\r
43 namespace DbLinqTest
\r
46 /// Test for NameFormatter
\r
49 public class NameFormatterTest
\r
51 private NameFormat InvariantNameFormat
\r
55 return new NameFormat(false, Case.PascalCase, CultureInfo.InvariantCulture);
\r
59 private NameFormat EnglishNameFormat
\r
63 Reference.DbLinqLocalizations();
\r
64 return new NameFormat(false, Case.NetCase, new CultureInfo("en-us"));
\r
68 private NameFormat EnglishNameFormatCamelCase
\r
72 Reference.DbLinqLocalizations();
\r
73 return new NameFormat(false, Case.camelCase, new CultureInfo("en-us"));
\r
78 public void InvalidCharactersCaseTest()
\r
80 var nf = new NameFormatter();
\r
81 var tn = nf.GetTableName("A#?", WordsExtraction.FromCase, InvariantNameFormat);
\r
82 Assert.AreEqual("A__", tn.ClassName);
\r
86 public void InvalidCharactersLanguageTest()
\r
88 var nf = new NameFormatter();
\r
89 var tn = nf.GetTableName("A#?", WordsExtraction.FromDictionary, InvariantNameFormat);
\r
90 Assert.AreEqual("A__", tn.ClassName);
\r
94 public void InvalidCharactersLanguage2Test()
\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
105 ObjectFactory.Current.Unregister(typeof(EnglishWords));
\r
110 public void GetWordsTest_MyTableName()
\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
121 ObjectFactory.Current.Unregister(typeof(EnglishWords));
\r
126 public void GetWordsTest_MyTableName2()
\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
137 ObjectFactory.Current.Unregister(typeof(EnglishWords));
\r
142 public void GetWordsTest_MyColumnName()
\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
155 ObjectFactory.Current.Unregister(typeof(EnglishWords));
\r