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.
35 using System.CodeDom.Compiler;
37 using NUnit.Framework;
38 using Microsoft.CSharp;
40 namespace MonoTests.System.Data
43 public class TypedDataSetGeneratorTest : Assertion
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 AssertEquals ("#1", "a", TypedDataSetGenerator.GenerateIdName ("a", gen));
74 AssertEquals ("#2", "_int", TypedDataSetGenerator.GenerateIdName ("int", gen));
75 AssertEquals ("#3", "_", TypedDataSetGenerator.GenerateIdName ("_", gen));
76 AssertEquals ("#3-2", "_", TypedDataSetGenerator.GenerateIdName ("_", gen));
77 AssertEquals ("#4", "_1", TypedDataSetGenerator.GenerateIdName ("1", gen));
78 AssertEquals ("#4-2", "_1", TypedDataSetGenerator.GenerateIdName ("1", gen));
79 AssertEquals ("#5", "_1a", TypedDataSetGenerator.GenerateIdName ("1a", gen));
80 AssertEquals ("#6", "_1_2", TypedDataSetGenerator.GenerateIdName ("1*2", gen));
81 AssertEquals ("#7", "__", TypedDataSetGenerator.GenerateIdName ("-", gen));
82 AssertEquals ("#8", "__", TypedDataSetGenerator.GenerateIdName ("+", gen));
83 AssertEquals ("#9", "_", TypedDataSetGenerator.GenerateIdName ("", gen));
84 AssertEquals ("#10", "___", TypedDataSetGenerator.GenerateIdName ("--", gen));
85 AssertEquals ("#11", "___", TypedDataSetGenerator.GenerateIdName ("++", gen));
86 AssertEquals ("#12", "\u3042", TypedDataSetGenerator.GenerateIdName ("\u3042", gen));
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 AssertEquals (0, r.Errors.Count);