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 && !XAMMAC_4_5
35 using System
.CodeDom
.Compiler
;
37 using NUnit
.Framework
;
38 using Microsoft
.CSharp
;
40 using MonoTests
.Helpers
;
42 namespace MonoTests
.System
.Data
45 public class TypedDataSetGeneratorTest
47 private ICodeGenerator gen
;
48 private ICodeCompiler compiler
;
50 public TypedDataSetGeneratorTest ()
52 CodeDomProvider p
= new CSharpCodeProvider ();
53 gen
= p
.CreateGenerator ();
54 compiler
= p
.CreateCompiler ();
58 [ExpectedException (typeof (NullReferenceException
))]
59 public void TestGenerateIdNameNullName ()
61 TypedDataSetGenerator
.GenerateIdName (null, gen
);
65 [ExpectedException (typeof (NullReferenceException
))]
66 public void TestGenerateIdNameNullProvider ()
68 TypedDataSetGenerator
.GenerateIdName ("a", null);
72 public void TestGenerateIdName ()
75 Assert
.AreEqual ("a", TypedDataSetGenerator
.GenerateIdName ("a", gen
), "#1");
76 Assert
.AreEqual ("_int", TypedDataSetGenerator
.GenerateIdName ("int", gen
), "#2");
77 Assert
.AreEqual ("_", TypedDataSetGenerator
.GenerateIdName ("_", gen
), "#3");
78 Assert
.AreEqual ("_", TypedDataSetGenerator
.GenerateIdName ("_", gen
), "#3-2");
79 Assert
.AreEqual ("_1", TypedDataSetGenerator
.GenerateIdName ("1", gen
), "#4");
80 Assert
.AreEqual ("_1", TypedDataSetGenerator
.GenerateIdName ("1", gen
), "#4-2");
81 Assert
.AreEqual ("_1a", TypedDataSetGenerator
.GenerateIdName ("1a", gen
), "#5");
82 Assert
.AreEqual ("_1_2", TypedDataSetGenerator
.GenerateIdName ("1*2", gen
), "#6");
83 Assert
.AreEqual ("__", TypedDataSetGenerator
.GenerateIdName ("-", gen
), "#7");
84 Assert
.AreEqual ("__", TypedDataSetGenerator
.GenerateIdName ("+", gen
), "#8");
85 Assert
.AreEqual ("_", TypedDataSetGenerator
.GenerateIdName ("", gen
), "#9");
86 Assert
.AreEqual ("___", TypedDataSetGenerator
.GenerateIdName ("--", gen
), "#10");
87 Assert
.AreEqual ("___", TypedDataSetGenerator
.GenerateIdName ("++", gen
), "#11");
88 Assert
.AreEqual ("\u3042", TypedDataSetGenerator
.GenerateIdName ("\u3042", gen
), "#12");
92 [Ignore ("We cannot depend on CodeCompiler since it expects mcs to exist.")]
93 public void RelationConnectsSameTable ()
95 DataSet ds
= new DataSet ();
96 ds
.ReadXmlSchema (TestResourceHelper
.GetFullPathOfResource ("Test/System.Data/schemas/bug77248.xsd"));
97 CodeNamespace cns
= new CodeNamespace ();
98 TypedDataSetGenerator
.Generate (ds
, cns
, gen
);
99 CodeCompileUnit ccu
= new CodeCompileUnit ();
100 ccu
.Namespaces
.Add (cns
);
101 CompilerResults r
= compiler
.CompileAssemblyFromDom (
102 new CompilerParameters (), ccu
);
103 Assert
.AreEqual (0, r
.Errors
.Count
);