2 // TypedDataSetGeneratorTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #if !MOBILE && !MONOMAC
35 using System.CodeDom.Compiler;
37 using NUnit.Framework;
38 using Microsoft.CSharp;
40 namespace MonoTests.System.Data
43 public class TypedDataSetGeneratorTest
45 private ICodeGenerator gen;
46 private ICodeCompiler compiler;
48 public TypedDataSetGeneratorTest ()
50 CodeDomProvider p = new CSharpCodeProvider ();
51 gen = p.CreateGenerator ();
52 compiler = p.CreateCompiler ();
56 [ExpectedException (typeof (NullReferenceException))]
57 public void TestGenerateIdNameNullName ()
59 TypedDataSetGenerator.GenerateIdName (null, gen);
63 [ExpectedException (typeof (NullReferenceException))]
64 public void TestGenerateIdNameNullProvider ()
66 TypedDataSetGenerator.GenerateIdName ("a", null);
70 public void TestGenerateIdName ()
73 Assert.AreEqual ("a", TypedDataSetGenerator.GenerateIdName ("a", gen), "#1");
74 Assert.AreEqual ("_int", TypedDataSetGenerator.GenerateIdName ("int", gen), "#2");
75 Assert.AreEqual ("_", TypedDataSetGenerator.GenerateIdName ("_", gen), "#3");
76 Assert.AreEqual ("_", TypedDataSetGenerator.GenerateIdName ("_", gen), "#3-2");
77 Assert.AreEqual ("_1", TypedDataSetGenerator.GenerateIdName ("1", gen), "#4");
78 Assert.AreEqual ("_1", TypedDataSetGenerator.GenerateIdName ("1", gen), "#4-2");
79 Assert.AreEqual ("_1a", TypedDataSetGenerator.GenerateIdName ("1a", gen), "#5");
80 Assert.AreEqual ("_1_2", TypedDataSetGenerator.GenerateIdName ("1*2", gen), "#6");
81 Assert.AreEqual ("__", TypedDataSetGenerator.GenerateIdName ("-", gen), "#7");
82 Assert.AreEqual ("__", TypedDataSetGenerator.GenerateIdName ("+", gen), "#8");
83 Assert.AreEqual ("_", TypedDataSetGenerator.GenerateIdName ("", gen), "#9");
84 Assert.AreEqual ("___", TypedDataSetGenerator.GenerateIdName ("--", gen), "#10");
85 Assert.AreEqual ("___", TypedDataSetGenerator.GenerateIdName ("++", gen), "#11");
86 Assert.AreEqual ("\u3042", TypedDataSetGenerator.GenerateIdName ("\u3042", gen), "#12");
90 [Ignore ("We cannot depend on CodeCompiler since it expects mcs to exist.")]
91 public void RelationConnectsSameTable ()
93 DataSet ds = new DataSet ();
94 ds.ReadXmlSchema ("Test/System.Data/schemas/bug77248.xsd");
95 CodeNamespace cns = new CodeNamespace ();
96 TypedDataSetGenerator.Generate (ds, cns, gen);
97 CodeCompileUnit ccu = new CodeCompileUnit ();
98 ccu.Namespaces.Add (cns);
99 CompilerResults r = compiler.CompileAssemblyFromDom (
100 new CompilerParameters (), ccu);
101 Assert.AreEqual (0, r.Errors.Count);