0
|
1 using System;
|
|
2 using System.IO;
|
|
3
|
|
4 using NUnit.Framework;
|
|
5
|
|
6 using BLToolkit.Data.DataProvider;
|
|
7 using BLToolkit.Data.Linq;
|
|
8
|
|
9 using Data.Linq;
|
|
10 using Data.Linq.Model;
|
|
11
|
|
12 namespace Create
|
|
13 {
|
|
14 [TestFixture]
|
|
15 public class CreateData : TestBase
|
|
16 {
|
|
17 static void RunScript(string configString, string divider, string name)
|
|
18 {
|
|
19 Console.WriteLine("=== " + name + " === \n");
|
|
20
|
|
21 var text = File.ReadAllText(@"..\..\..\..\Data\Create Scripts\" + name + ".sql");
|
|
22
|
|
23 while (true)
|
|
24 {
|
|
25 var idx = text.IndexOf("SKIP " + configString + " BEGIN");
|
|
26
|
|
27 if (idx >= 0)
|
|
28 text = text.Substring(0, idx) + text.Substring(text.IndexOf("SKIP " + configString + " END", idx));
|
|
29 else
|
|
30 break;
|
|
31 }
|
|
32
|
|
33 var cmds = text.Replace("\r", "").Replace(divider, "\x1").Split('\x1');
|
|
34
|
|
35 Exception exception = null;
|
|
36
|
|
37 using (var db = new TestDbManager(configString))
|
|
38 {
|
|
39 foreach (var cmd in cmds)
|
|
40 {
|
|
41 var command = cmd.Trim();
|
|
42
|
|
43 if (command.Length == 0)
|
|
44 continue;
|
|
45
|
|
46 try
|
|
47 {
|
|
48 Console.WriteLine(command);
|
|
49 db.SetCommand(command).ExecuteNonQuery();
|
|
50 Console.WriteLine("\nOK\n");
|
|
51 }
|
|
52 catch (Exception ex)
|
|
53 {
|
|
54 Console.WriteLine(ex.Message);
|
|
55 Console.WriteLine("\nFAILED\n");
|
|
56
|
|
57 if (exception == null)
|
|
58 exception = ex;
|
|
59 }
|
|
60 }
|
|
61
|
|
62 if (exception != null)
|
|
63 throw exception;
|
|
64
|
|
65 db.InsertBatch(new[]
|
|
66 {
|
|
67 new LinqDataTypes { ID = 1, MoneyValue = 1.11m, DateTimeValue = new DateTime(2001, 1, 11, 1, 11, 21, 100), BoolValue = true, GuidValue = new Guid("ef129165-6ffe-4df9-bb6b-bb16e413c883"), SmallIntValue = 1 },
|
|
68 new LinqDataTypes { ID = 2, MoneyValue = 2.49m, DateTimeValue = new DateTime(2005, 5, 15, 5, 15, 25, 500), BoolValue = false, GuidValue = new Guid("bc663a61-7b40-4681-ac38-f9aaf55b706b"), SmallIntValue = 2 },
|
|
69 new LinqDataTypes { ID = 3, MoneyValue = 3.99m, DateTimeValue = new DateTime(2009, 9, 19, 9, 19, 29, 90), BoolValue = true, GuidValue = new Guid("d2f970c0-35ac-4987-9cd5-5badb1757436"), SmallIntValue = 3 },
|
|
70 new LinqDataTypes { ID = 4, MoneyValue = 4.50m, DateTimeValue = new DateTime(2009, 9, 20, 9, 19, 29, 90), BoolValue = false, GuidValue = new Guid("40932fdb-1543-4e4a-ac2c-ca371604fb4b"), SmallIntValue = 4 },
|
|
71 new LinqDataTypes { ID = 5, MoneyValue = 5.50m, DateTimeValue = new DateTime(2009, 9, 21, 9, 19, 29, 90), BoolValue = true, GuidValue = new Guid("febe3eca-cb5f-40b2-ad39-2979d312afca"), SmallIntValue = 5 },
|
|
72 new LinqDataTypes { ID = 6, MoneyValue = 6.55m, DateTimeValue = new DateTime(2009, 9, 22, 9, 19, 29, 90), BoolValue = false, GuidValue = new Guid("8d3c5d1d-47db-4730-9fe7-968f6228a4c0"), SmallIntValue = 6 },
|
|
73 new LinqDataTypes { ID = 7, MoneyValue = 7.00m, DateTimeValue = new DateTime(2009, 9, 23, 9, 19, 29, 90), BoolValue = true, GuidValue = new Guid("48094115-83af-46dd-a906-bff26ee21ee2"), SmallIntValue = 7 },
|
|
74 new LinqDataTypes { ID = 8, MoneyValue = 8.99m, DateTimeValue = new DateTime(2009, 9, 24, 9, 19, 29, 90), BoolValue = false, GuidValue = new Guid("c1139f1f-1335-4cd4-937e-92602f732dd3"), SmallIntValue = 8 },
|
|
75 new LinqDataTypes { ID = 9, MoneyValue = 9.63m, DateTimeValue = new DateTime(2009, 9, 25, 9, 19, 29, 90), BoolValue = true, GuidValue = new Guid("46c5c512-3d4b-4cf7-b4e7-1de080789e5d"), SmallIntValue = 9 },
|
|
76 new LinqDataTypes { ID = 10, MoneyValue = 10.77m, DateTimeValue = new DateTime(2009, 9, 26, 9, 19, 29, 90), BoolValue = false, GuidValue = new Guid("61b2bc55-147f-4b40-93ed-a4aa83602fee"), SmallIntValue = 10 },
|
|
77 new LinqDataTypes { ID = 11, MoneyValue = 11.45m, DateTimeValue = new DateTime(2009, 9, 27, 9, 19, 29, 90), BoolValue = true, GuidValue = new Guid("d3021d18-97f0-4dc0-98d0-f0c7df4a1230"), SmallIntValue = 11 },
|
|
78 new LinqDataTypes { ID = 12, MoneyValue = 11.45m, DateTimeValue = new DateTime(2012, 11, 7, 19, 19, 29, 90), BoolValue = true, GuidValue = new Guid("03021d18-97f0-4dc0-98d0-f0c7df4a1230"), SmallIntValue = 12 },
|
|
79 });
|
|
80
|
|
81 db.InsertBatch(new[]
|
|
82 {
|
|
83 new Parent { ParentID = 1, Value1 = 1 },
|
|
84 new Parent { ParentID = 2, Value1 = null },
|
|
85 new Parent { ParentID = 3, Value1 = 3 },
|
|
86 new Parent { ParentID = 4, Value1 = null },
|
|
87 new Parent { ParentID = 5, Value1 = 5 },
|
|
88 new Parent { ParentID = 6, Value1 = 6 },
|
|
89 new Parent { ParentID = 7, Value1 = 1 },
|
|
90 });
|
|
91
|
|
92 db.InsertBatch(new[]
|
|
93 {
|
|
94 new Child { ParentID = 1, ChildID = 11 },
|
|
95 new Child { ParentID = 2, ChildID = 21 },
|
|
96 new Child { ParentID = 2, ChildID = 22 },
|
|
97 new Child { ParentID = 3, ChildID = 31 },
|
|
98 new Child { ParentID = 3, ChildID = 32 },
|
|
99 new Child { ParentID = 3, ChildID = 33 },
|
|
100 new Child { ParentID = 4, ChildID = 41 },
|
|
101 new Child { ParentID = 4, ChildID = 42 },
|
|
102 new Child { ParentID = 4, ChildID = 43 },
|
|
103 new Child { ParentID = 4, ChildID = 44 },
|
|
104 new Child { ParentID = 6, ChildID = 61 },
|
|
105 new Child { ParentID = 6, ChildID = 62 },
|
|
106 new Child { ParentID = 6, ChildID = 63 },
|
|
107 new Child { ParentID = 6, ChildID = 64 },
|
|
108 new Child { ParentID = 6, ChildID = 65 },
|
|
109 new Child { ParentID = 6, ChildID = 66 },
|
|
110 new Child { ParentID = 7, ChildID = 77 },
|
|
111 });
|
|
112
|
|
113 db.InsertBatch(new[]
|
|
114 {
|
|
115 new GrandChild { ParentID = 1, ChildID = 11, GrandChildID = 111 },
|
|
116 new GrandChild { ParentID = 2, ChildID = 21, GrandChildID = 211 },
|
|
117 new GrandChild { ParentID = 2, ChildID = 21, GrandChildID = 212 },
|
|
118 new GrandChild { ParentID = 2, ChildID = 22, GrandChildID = 221 },
|
|
119 new GrandChild { ParentID = 2, ChildID = 22, GrandChildID = 222 },
|
|
120 new GrandChild { ParentID = 3, ChildID = 31, GrandChildID = 311 },
|
|
121 new GrandChild { ParentID = 3, ChildID = 31, GrandChildID = 312 },
|
|
122 new GrandChild { ParentID = 3, ChildID = 31, GrandChildID = 313 },
|
|
123 new GrandChild { ParentID = 3, ChildID = 32, GrandChildID = 321 },
|
|
124 new GrandChild { ParentID = 3, ChildID = 32, GrandChildID = 322 },
|
|
125 new GrandChild { ParentID = 3, ChildID = 32, GrandChildID = 323 },
|
|
126 new GrandChild { ParentID = 3, ChildID = 33, GrandChildID = 331 },
|
|
127 new GrandChild { ParentID = 3, ChildID = 33, GrandChildID = 332 },
|
|
128 new GrandChild { ParentID = 3, ChildID = 33, GrandChildID = 333 },
|
|
129 new GrandChild { ParentID = 4, ChildID = 41, GrandChildID = 411 },
|
|
130 new GrandChild { ParentID = 4, ChildID = 41, GrandChildID = 412 },
|
|
131 new GrandChild { ParentID = 4, ChildID = 41, GrandChildID = 413 },
|
|
132 new GrandChild { ParentID = 4, ChildID = 41, GrandChildID = 414 },
|
|
133 new GrandChild { ParentID = 4, ChildID = 42, GrandChildID = 421 },
|
|
134 new GrandChild { ParentID = 4, ChildID = 42, GrandChildID = 422 },
|
|
135 new GrandChild { ParentID = 4, ChildID = 42, GrandChildID = 423 },
|
|
136 new GrandChild { ParentID = 4, ChildID = 42, GrandChildID = 424 },
|
|
137 });
|
|
138 }
|
|
139 }
|
|
140
|
|
141 [Test] public void DB2 ([IncludeDataContexts(ProviderName.DB2 )] string context) { RunScript(context, "\nGO\n", "DB2"); }
|
|
142 [Test] public void Informix ([IncludeDataContexts(ProviderName.Informix )] string context) { RunScript(context, "\nGO\n", "Informix"); }
|
|
143 [Test] public void Oracle ([IncludeDataContexts("Oracle" )] string context) { RunScript(context, "\n/\n", "Oracle"); }
|
|
144 [Test] public void Firebird ([IncludeDataContexts(ProviderName.Firebird )] string context) { RunScript(context, "COMMIT;", "Firebird2"); }
|
|
145 [Test] public void PostgreSQL([IncludeDataContexts(ProviderName.PostgreSQL)] string context) { RunScript(context, "\nGO\n", "PostgreSQL"); }
|
|
146 [Test] public void MySql ([IncludeDataContexts(ProviderName.MySql )] string context) { RunScript(context, "\nGO\n", "MySql"); }
|
|
147 [Test] public void Sql2000 ([IncludeDataContexts("Sql2000" )] string context) { RunScript(context, "\nGO\n", "MsSql2000"); }
|
|
148 [Test] public void Sql2005 ([IncludeDataContexts("Sql2005" )] string context) { RunScript(context, "\nGO\n", "MsSql"); }
|
|
149 [Test] public void Sql2008 ([IncludeDataContexts("Sql2008" )] string context) { RunScript(context, "\nGO\n", "MsSql"); }
|
|
150 [Test] public void Sql2012 ([IncludeDataContexts("Sql2012" )] string context) { RunScript(context, "\nGO\n", "MsSql"); }
|
|
151 [Test] public void SqlCe ([IncludeDataContexts(ProviderName.SqlCe )] string context) { RunScript(context, "\nGO\n", "SqlCe"); }
|
|
152 [Test] public void SqlCeData ([IncludeDataContexts(ProviderName.SqlCe )] string context) { RunScript(context + ".Data", "\nGO\n", "SqlCe"); }
|
|
153 [Test] public void SQLite ([IncludeDataContexts(ProviderName.SQLite )] string context) { RunScript(context, "\nGO\n", "SQLite"); }
|
|
154 [Test] public void SQLiteData([IncludeDataContexts(ProviderName.SQLite )] string context) { RunScript(context + ".Data", "\nGO\n", "SQLite"); }
|
|
155 [Test] public void Access ([IncludeDataContexts(ProviderName.Access )] string context) { RunScript(context, "\nGO\n", "Access"); }
|
|
156 [Test] public void AccessData([IncludeDataContexts(ProviderName.Access )] string context) { RunScript(context + ".Data", "\nGO\n", "Access"); }
|
|
157 [Test] public void Sybase ([IncludeDataContexts(ProviderName.Sybase )] string context) { RunScript(context, "\nGO\n", "Sybase"); }
|
|
158 }
|
|
159 }
|