diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/DbModelTable_tests.cs b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/DbModelTable_tests.cs
new file mode 100644
index 0000000..679b8ad
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/DbModelTable_tests.cs
@@ -0,0 +1,55 @@
+#region License
+// Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved.
+// This source code is made available under the terms of the GNU Lesser General Public License v3.0
+// https://github.com/paulkohler/minisqlquery/blob/master/LICENSE
+#endregion
+using MiniSqlQuery.Core.DbModel;
+using NUnit.Framework;
+
+
+// ReSharper disable InconsistentNaming
+
+namespace MiniSqlQuery.Tests.DbModel
+{
+ /// <summary>
+ /// Microsoft SQL Server Compact 4.0 tests.
+ ///
+ /// To run this fixture you will need SQLCE installed, see:
+ /// https://www.microsoft.com/en-us/download/details.aspx?id=17876
+ /// </summary>
+ [TestFixture(Description = "Requires SQLCE DB")]
+ [Category("Functional")] // todo - build db model manually for unit test to remove db dependency
+ public class DbModelTable_tests
+ {
+ #region Setup/Teardown
+
+ [SetUp]
+ public void TestSetup()
+ {
+ _service = new SqlCeSchemaService { ProviderName = _providerName };
+ _model = _service.GetDbObjectModel(_connStr);
+ }
+
+ #endregion
+
+ private SqlCeSchemaService _service;
+ private string _connStr = @"data source=|DataDirectory|\sqlce-test.v4.sdf";
+ private string _providerName = "System.Data.SqlServerCe.4.0";
+
+ private DbModelInstance _model;
+
+ [Test]
+ public void Can_find_tables_by_name()
+ {
+ var table = _model.FindTable("[StaffUnit]");
+ Assert.That(table, Is.Not.Null);
+ }
+
+ [Test]
+ public void Returns_null_if_cant_find_table_by_name()
+ {
+ var table = _model.FindTable("[foo]");
+ Assert.That(table, Is.Null);
+ }
+ }
+}
\ No newline at end of file
diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/DbTypeTests.cs b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/DbTypeTests.cs
new file mode 100644
index 0000000..6c05782
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/DbTypeTests.cs
@@ -0,0 +1,64 @@
+#region License
+// Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved.
+// This source code is made available under the terms of the GNU Lesser General Public License v3.0
+// https://github.com/paulkohler/minisqlquery/blob/master/LICENSE
+#endregion
+
+using MiniSqlQuery.Core.DbModel;
+using NUnit.Framework;
+
+// ReSharper disable InconsistentNaming
+
+namespace MiniSqlQuery.Tests.DbModel
+{
+ [TestFixture]
+ public class DbTypeTests
+ {
+ [Test]
+ public void Summary_renders_an_int()
+ {
+ DbModelType dbType = new DbModelType("int", 4) { CreateFormat = "int" };
+ Assert.That(dbType.Summary, Is.EqualTo("int"));
+ }
+
+ [Test]
+ public void Summary_renders_a_varchar_10()
+ {
+ DbModelType dbType = new DbModelType("varchar", 10) { CreateFormat = "varchar({0})" };
+ Assert.That(dbType.Summary, Is.EqualTo("varchar(10)"));
+ }
+
+ [Test]
+ public void Summary_renders_a_decimal_8_6()
+ {
+ DbModelType dbType = new DbModelType("decimal", 8 + 6) { Precision = 8, Scale = 6, CreateFormat = "decimal({0}, {1})" };
+ Assert.That(dbType.Summary, Is.EqualTo("decimal(8, 6)"));
+ }
+
+ [Test]
+ public void Summary_renders_a_decimal_as_default()
+ {
+ DbModelType dbType = new DbModelType("decimal", 26) { Precision = -1, Scale = -1, CreateFormat = "decimal({0}, {1})" };
+ Assert.That(dbType.Summary, Is.EqualTo("decimal"));
+ }
+
+ [Test]
+ public void Summary_renders_uses_CreateFormat_over_name_if_present()
+ {
+ DbModelType dbType = new DbModelType("mytype", 100) { CreateFormat = "MyType" };
+ Assert.That(dbType.Summary, Is.EqualTo("MyType"));
+ }
+
+ [Test]
+ public void Summary_renders_a_the_type_name_if_there_is_no_CreateFormat()
+ {
+ DbModelType dbType = new DbModelType("decimal", 26);
+ Assert.That(dbType.Summary, Is.EqualTo("decimal"));
+ }
+
+ /*
+ * consider nvarchar(MAX) for sql?
+ *
+ * */
+ }
+}
\ No newline at end of file
diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/MSAccess_DataType_Tests.cs b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/MSAccess_DataType_Tests.cs
new file mode 100644
index 0000000..d62266c
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/MSAccess_DataType_Tests.cs
@@ -0,0 +1,116 @@
+#region License
+// Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved.
+// This source code is made available under the terms of the GNU Lesser General Public License v3.0
+// https://github.com/paulkohler/minisqlquery/blob/master/LICENSE
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Data.Common;
+using MiniSqlQuery.Core.DbModel;
+using NUnit.Framework;
+
+namespace MiniSqlQuery.Tests.DbModel
+{
+ [TestFixture(Description = "Requires MS Access DB")]
+ [Category("Functional")]
+ [Ignore("Run this functional test manually after setup")]
+ public class MSAccess_DataType_Tests
+ {
+ #region Setup/Teardown
+
+ [SetUp]
+ public void TestSetup()
+ {
+ _service = new OleDbSchemaService();
+ DbConnection conn = DbProviderFactories.GetFactory(_providerName).CreateConnection();
+ conn.ConnectionString = _connStr;
+ conn.Open();
+ _dbTypes = _service.GetDbTypes(conn);
+ }
+
+ #endregion
+
+ private OleDbSchemaService _service;
+ private string _connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Projects\minisqlquery\trunk\TestDatabases\NorthWindDemo.mdb";
+ private string _providerName = "System.Data.OleDb";
+ Dictionary<string, DbModelType> _dbTypes;
+
+ [Test]
+ public void There_are_at_least_15_types_for_access()
+ {
+ Assert.That(_dbTypes.Count, Is.GreaterThanOrEqualTo(15));
+ /*
+Short (System.Int16)
+Long (System.Int32)
+Single (System.Single)
+Double (System.Double)
+Currency (System.Decimal)
+DateTime (System.DateTime)
+Bit (System.Boolean)
+Byte (System.Byte)
+GUID (System.Guid)
+BigBinary (System.Byte[])
+LongBinary (System.Byte[])
+VarBinary (System.Byte[])
+LongText (System.String)
+VarChar (System.String)
+Decimal (System.Decimal)
+ */
+ }
+
+ [Test]
+ public void VarChar_type()
+ {
+ DbModelType dbType = _dbTypes["varchar"];
+ Assert.That(dbType.Name, Is.EqualTo("VarChar").IgnoreCase);
+ Assert.That(dbType.Length, Is.EqualTo(255));
+ Assert.That(dbType.CreateFormat, Is.EqualTo("VarChar({0})"));
+ Assert.That(dbType.LiteralPrefix, Is.EqualTo("'"));
+ Assert.That(dbType.LiteralSuffix, Is.EqualTo("'"));
+ }
+
+ [Test]
+ public void VarBinary_type()
+ {
+ DbModelType dbType = _dbTypes["varbinary"];
+ Assert.That(dbType.Name, Is.EqualTo("VarBinary").IgnoreCase);
+ Assert.That(dbType.CreateFormat, Is.EqualTo("VarBinary({0})"));
+ Assert.That(dbType.LiteralPrefix, Is.EqualTo("0x"));
+ Assert.That(dbType.LiteralSuffix, Is.Empty);
+ }
+
+ [Test]
+ public void LongText_type()
+ {
+ DbModelType dbType = _dbTypes["longtext"];
+ Assert.That(dbType.Name, Is.EqualTo("LongText").IgnoreCase);
+ Assert.That(dbType.Summary, Is.EqualTo("LongText"));
+ Assert.That(dbType.LiteralPrefix, Is.EqualTo("'"));
+ Assert.That(dbType.LiteralSuffix, Is.EqualTo("'"));
+ }
+
+ [Test]
+ public void DateTime_type()
+ {
+ DbModelType dbType = _dbTypes["datetime"];
+ Assert.That(dbType.Name, Is.EqualTo("DateTime").IgnoreCase);
+ Assert.That(dbType.Summary, Is.EqualTo("DateTime"));
+ Assert.That(dbType.LiteralPrefix, Is.EqualTo("#"));
+ Assert.That(dbType.LiteralSuffix, Is.EqualTo("#"));
+ var copy = dbType.Copy();
+ copy.Value = new DateTime(2000, 12, 17);
+ Assert.That(copy.ToDDLValue(), Is.EqualTo("#17/12/2000 12:00:00 AM#"));
+ }
+
+ [Test]
+ [Ignore("run this manually")]
+ public void Show_all()
+ {
+ List<DbModelType> ary = new List<DbModelType>(_dbTypes.Values);
+ foreach (var dbModelType in ary)
+ {
+ Console.WriteLine("{0} ({1})", dbModelType.Summary, dbModelType.SystemType);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/SqlCeSchemaService_DataType_Tests.cs b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/SqlCeSchemaService_DataType_Tests.cs
new file mode 100644
index 0000000..84ec461
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/SqlCeSchemaService_DataType_Tests.cs
@@ -0,0 +1,84 @@
+#region License
+// Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved.
+// This source code is made available under the terms of the GNU Lesser General Public License v3.0
+// https://github.com/paulkohler/minisqlquery/blob/master/LICENSE
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Data.Common;
+using MiniSqlQuery.Core.DbModel;
+using NUnit.Framework;
+
+namespace MiniSqlQuery.Tests.DbModel
+{
+ [TestFixture(Description = "Requires SQLCE DB")]
+ [Category("Functional")]
+ public class SqlCeSchemaService_DataType_Tests
+ {
+ #region Setup/Teardown
+
+ [SetUp]
+ public void TestSetup()
+ {
+ _service = new SqlCeSchemaService();
+ DbConnection conn = DbProviderFactories.GetFactory(_providerName).CreateConnection();
+ conn.ConnectionString = _connStr;
+ conn.Open();
+ _dbTypes = _service.GetDbTypes(conn);
+ }
+
+ #endregion
+
+ private SqlCeSchemaService _service;
+ private string _connStr = @"data source=|DataDirectory|\sqlce-test.v4.sdf";
+ private string _providerName = "System.Data.SqlServerCe.4.0";
+ Dictionary<string, DbModelType> _dbTypes;
+
+ [Test]
+ public void There_are_at_least_18_types()
+ {
+ Assert.That(_dbTypes.Count, Is.GreaterThanOrEqualTo(18));
+ }
+
+ [Test]
+ public void NVarchar_type()
+ {
+ DbModelType dbType = _dbTypes["nvarchar"];
+ Assert.That(dbType.Name, Is.EqualTo("nvarchar").IgnoreCase);
+ Assert.That(dbType.Length, Is.EqualTo(4000));
+ Assert.That(dbType.CreateFormat, Is.EqualTo("nvarchar({0})"));
+ Assert.That(dbType.LiteralPrefix, Is.EqualTo("N'"));
+ Assert.That(dbType.LiteralSuffix, Is.EqualTo("'"));
+ Assert.That(dbType.SystemType, Is.EqualTo(typeof(string)));
+ }
+
+ [Test]
+ public void Money_type()
+ {
+ DbModelType dbType = _dbTypes["money"];
+ Assert.That(dbType.Name, Is.EqualTo("money").IgnoreCase);
+ Assert.That(dbType.Summary, Is.EqualTo("money"));
+ Assert.That(dbType.SystemType, Is.EqualTo(typeof(decimal)));
+ }
+
+ [Test]
+ public void Float_type()
+ {
+ DbModelType dbType = _dbTypes["float"];
+ Assert.That(dbType.Name, Is.EqualTo("float").IgnoreCase);
+ Assert.That(dbType.Summary, Is.EqualTo("float"));
+ Assert.That(dbType.SystemType, Is.EqualTo(typeof(double)));
+ }
+
+ [Test]
+ [Ignore("run this manually if needed, just a helper")]
+ public void Show_all()
+ {
+ List<DbModelType> ary = new List<DbModelType>(_dbTypes.Values);
+ foreach (var dbModelType in ary)
+ {
+ Console.WriteLine("{0} ({1})", dbModelType.Summary, dbModelType.SystemType);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/SqlCeSchemaService_DataType_ToDDL_Tests.cs b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/SqlCeSchemaService_DataType_ToDDL_Tests.cs
new file mode 100644
index 0000000..2f84c55
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/SqlCeSchemaService_DataType_ToDDL_Tests.cs
@@ -0,0 +1,103 @@
+#region License
+// Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved.
+// This source code is made available under the terms of the GNU Lesser General Public License v3.0
+// https://github.com/paulkohler/minisqlquery/blob/master/LICENSE
+#endregion
+using System.Collections.Generic;
+using System.Data.Common;
+using MiniSqlQuery.Core.DbModel;
+using NUnit.Framework;
+
+
+// ReSharper disable InconsistentNaming
+
+namespace MiniSqlQuery.Tests.DbModel
+{
+ [TestFixture(Description = "Requires SQLCE DB")]
+ [Category("Functional")]
+ public class SqlCeSchemaService_DataType_ToDDL_Tests
+ {
+ #region Setup/Teardown
+
+ [SetUp]
+ public void TestSetup()
+ {
+ _service = new SqlCeSchemaService();
+ DbConnection conn = DbProviderFactories.GetFactory(_providerName).CreateConnection();
+ conn.ConnectionString = _connStr;
+ conn.Open();
+ _dbTypes = _service.GetDbTypes(conn);
+ }
+
+ #endregion
+
+ private SqlCeSchemaService _service;
+ private string _connStr = @"data source=|DataDirectory|\sqlce-test.v4.sdf";
+ private string _providerName = "System.Data.SqlServerCe.4.0";
+ Dictionary<string, DbModelType> _dbTypes;
+
+ [Test]
+ public void nvarchar_with_value()
+ {
+ DbModelType str = _dbTypes["nvarchar"].Copy();
+ str.Value = "the quick brown fox...";
+ Assert.That(str.ToDDLValue(), Is.EqualTo("N'the quick brown fox...'"), "Should take the literals into account");
+ }
+
+ [Test]
+ public void int_with_value()
+ {
+ DbModelType num = _dbTypes["int"].Copy();
+ num.Value = 55;
+ Assert.That(num.ToDDLValue(), Is.EqualTo("55"));
+ }
+
+ [Test]
+ public void datetime_as_null()
+ {
+ DbModelType nullDate = _dbTypes["datetime"].Copy();
+ nullDate.Value = null;
+ Assert.That(nullDate.ToDDLValue(), Is.EqualTo("null"));
+ }
+
+ [Test]
+ public void nou_null_int_defaults_to_0()
+ {
+ DbModelType notNullNum = _dbTypes["int"].Copy();
+ notNullNum.Value = null;
+ Assert.That(notNullNum.ToDDLValue(false), Is.EqualTo("0"));
+ }
+
+ [Test]
+ public void not_null_nvarchar_defaults_to_empty_quotes()
+ {
+ DbModelType notNullNvarchar = _dbTypes["nvarchar"].Copy();
+ notNullNvarchar.Value = null;
+ Assert.That(notNullNvarchar.ToDDLValue(false), Is.EqualTo("N''"));
+ }
+
+ [Test]
+ public void nou_null_guid_defaults_to_empty_guid()
+ {
+ DbModelType uniqueidentifier = _dbTypes["uniqueidentifier"].Copy();
+ uniqueidentifier.Value = null;
+ Assert.That(uniqueidentifier.ToDDLValue(false), Is.EqualTo("'00000000-0000-0000-0000-000000000000'"));
+ }
+
+ [Test]
+ public void nou_null_VARBINARY_defaults_to_0()
+ {
+ DbModelType notNullVarbinary = _dbTypes["varbinary"].Copy();
+ notNullVarbinary.Value = null;
+ Assert.That(notNullVarbinary.ToDDLValue(false), Is.EqualTo("0"));
+ }
+
+ [Test]
+ public void nou_null_BIT_defaults_to_0()
+ {
+ DbModelType notNullBit = _dbTypes["bit"].Copy();
+ notNullBit.Value = null;
+ Assert.That(notNullBit.ToDDLValue(false), Is.EqualTo("0"));
+ }
+ }
+}
\ No newline at end of file
diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/SqlCeSchemaService_Tests.cs b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/SqlCeSchemaService_Tests.cs
new file mode 100644
index 0000000..4373388
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/SqlCeSchemaService_Tests.cs
@@ -0,0 +1,144 @@
+#region License
+// Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved.
+// This source code is made available under the terms of the GNU Lesser General Public License v3.0
+// https://github.com/paulkohler/minisqlquery/blob/master/LICENSE
+#endregion
+using System;
+using MiniSqlQuery.Core.DbModel;
+using NUnit.Framework;
+
+
+// ReSharper disable InconsistentNaming
+
+namespace MiniSqlQuery.Tests.DbModel
+{
+ [TestFixture(Description = "Requires SQLCE DB")]
+ [Category("Functional")]
+ public class SqlCeSchemaService_Tests
+ {
+ #region Setup/Teardown
+
+ [SetUp]
+ public void TestSetup()
+ {
+ _service = new SqlCeSchemaService { ProviderName = _providerName };
+ _model = _service.GetDbObjectModel(_connStr);
+ }
+
+ #endregion
+
+ private SqlCeSchemaService _service;
+ private string _connStr = @"data source=|DataDirectory|\Northwind.v4.sdf";
+ private string _providerName = "System.Data.SqlServerCe.4.0";
+ private DbModelInstance _model;
+
+ [Test]
+ public void Has_Customers_table()
+ {
+ Assert.That(_model.FindTable("[Customers]"), Is.Not.Null);
+ }
+
+ [Test]
+ public void Has_Categories_table()
+ {
+ Assert.That(_model.FindTable("[Categories]"), Is.Not.Null);
+ }
+
+ [Test]
+ public void Customers_table_has_columns()
+ {
+ var table = _model.FindTable("[Customers]");
+ Assert.That(table.Columns[0].Name, Is.EqualTo("Customer ID"));
+ Assert.That(table.Columns[0].DbType.Name, Is.EqualTo("nvarchar"));
+ Assert.That(table.Columns[0].DbType.Length, Is.EqualTo(5));
+
+ Assert.That(table.PrimaryKeyColumns.Count, Is.EqualTo(1));
+ }
+
+ [Test]
+ public void Check_FK_refs_for_Products()
+ {
+ var table = _model.FindTable("[Products]");
+ var supplierIdColumn = table.Columns[1];
+ var categoryIdColumn = table.Columns[2];
+ var productNameColumn = table.Columns[3];
+
+ Assert.That(table.Columns.Count, Is.EqualTo(11));
+ Assert.That(table.PrimaryKeyColumns.Count, Is.EqualTo(1));
+ Assert.That(table.ForeignKeyColumns.Count, Is.EqualTo(2));
+ Assert.That(table.NonKeyColumns.Count, Is.EqualTo(8));
+
+ Assert.That(supplierIdColumn.ForeignKeyReference, Is.Not.Null);
+ Assert.That(categoryIdColumn.ForeignKeyReference, Is.Not.Null);
+
+ Assert.That(supplierIdColumn.ForeignKeyReference.OwningColumn.Name, Is.EqualTo("Supplier ID"));
+ Assert.That(supplierIdColumn.ForeignKeyReference.ReferenceTable.Name, Is.EqualTo("Suppliers"));
+ Assert.That(supplierIdColumn.ForeignKeyReference.ReferenceColumn.Name, Is.EqualTo("Supplier ID"));
+ Assert.That(supplierIdColumn.ForeignKeyReference.UpdateRule, Is.EqualTo("CASCADE"));
+ Assert.That(supplierIdColumn.ForeignKeyReference.DeleteRule, Is.EqualTo("NO ACTION"));
+ Assert.That(supplierIdColumn.HasFK, Is.True);
+
+ Assert.That(categoryIdColumn.ForeignKeyReference.OwningColumn.Name, Is.EqualTo("Category ID"));
+ Assert.That(categoryIdColumn.ForeignKeyReference.ReferenceTable.Name, Is.EqualTo("Categories"));
+ Assert.That(categoryIdColumn.ForeignKeyReference.ReferenceColumn.Name, Is.EqualTo("Category ID"));
+ Assert.That(categoryIdColumn.ForeignKeyReference.UpdateRule, Is.EqualTo("CASCADE"));
+ Assert.That(categoryIdColumn.ForeignKeyReference.DeleteRule, Is.EqualTo("NO ACTION"));
+
+ Assert.That(productNameColumn.HasFK, Is.False);
+ Assert.That(productNameColumn.Name, Is.EqualTo("Product Name"));
+ }
+
+
+ [Test]
+ public void Build_dependency_tree_from_model()
+ {
+ DbModelDependencyWalker dependencyWalker = new DbModelDependencyWalker(_model);
+ var tables = dependencyWalker.SortTablesByForeignKeyReferences();
+
+ DisplayTableDetails(tables);
+ /*
+ Categories (fks:0)
+ Customers (fks:0)
+ Employees (fks:0)
+ Order Details_New (fks:0)
+ Shippers (fks:0)
+ Suppliers (fks:0)
+ Orders (fks:3)
+ (FK --> Customers.Customer ID)
+ (FK --> Employees.Employee ID)
+ (FK --> Shippers.Shipper ID)
+ Products (fks:2)
+ (FK --> Suppliers.Supplier ID)
+ (FK --> Categories.Category ID)
+ Order Details (fks:2)
+ (FK --> Orders.Order ID)
+ (FK --> Products.Product ID)
+ */
+
+ Assert.That(tables[0].Name, Is.EqualTo("Categories"));
+ Assert.That(tables[1].Name, Is.EqualTo("Customers"));
+ Assert.That(tables[2].Name, Is.EqualTo("Employees"));
+ Assert.That(tables[4].Name, Is.EqualTo("Shippers"));
+ Assert.That(tables[5].Name, Is.EqualTo("Suppliers"));
+ Assert.That(tables[6].Name, Is.EqualTo("Orders"), "Order is dependent on Customers, Employees, Shippers");
+ Assert.That(tables[7].Name, Is.EqualTo("Products"), "Products is dependent on Suppliers, Categories");
+ Assert.That(tables[8].Name, Is.EqualTo("Order Details"), "Order Details is dependent on Orders, Products");
+ }
+
+ private void DisplayTableDetails(DbModelTable[] tablesList)
+ {
+ foreach (DbModelTable table in tablesList)
+ {
+ Console.WriteLine(string.Format("{0} (fks:{1})", table.Name, table.ForeignKeyColumns.Count));
+ if (table.ForeignKeyColumns.Count > 0)
+ {
+ foreach (DbModelColumn fk in table.ForeignKeyColumns)
+ {
+ Console.WriteLine(" (FK --> {0}.{1})", fk.ForeignKeyReference.ReferenceTable.Name, fk.ForeignKeyReference.ReferenceColumn.Name);
+
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/SqlWriterTests.cs b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/SqlWriterTests.cs
new file mode 100644
index 0000000..446fb00
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/DbModel/SqlWriterTests.cs
@@ -0,0 +1,156 @@
+#region License
+// Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved.
+// This source code is made available under the terms of the GNU Lesser General Public License v3.0
+// https://github.com/paulkohler/minisqlquery/blob/master/LICENSE
+#endregion
+using System;
+using System.IO;
+using MiniSqlQuery.Core.DbModel;
+using NUnit.Framework;
+
+
+// ReSharper disable InconsistentNaming
+
+namespace MiniSqlQuery.Tests.DbModel
+{
+ [TestFixture(Description = "Requires SQLCE DB")]
+ [Category("Functional")] // todo - build db model manually for unit test to remove db dependency
+ public class SqlWriterTests
+ {
+ #region Setup/Teardown
+
+ [SetUp]
+ public void TestSetup()
+ {
+ _service = new SqlCeSchemaService { ProviderName = _providerName };
+ _model = _service.GetDbObjectModel(_connStr);
+ _sqlSW = new StringWriter();
+ _sqlWriter = new SqlWriter();
+ }
+
+ #endregion
+
+ private SqlCeSchemaService _service;
+ private string _connStr = @"data source=|DataDirectory|\sqlce-test.v4.sdf";
+ private string _providerName = "System.Data.SqlServerCe.4.0";
+ private DbModelInstance _model;
+ ISqlWriter _sqlWriter;
+ StringWriter _sqlSW;
+
+ [Test]
+ public void will_render_sql_with_types_and_nullability()
+ {
+ var table = _model.FindTable("[Person]");
+ // build sql sample...
+ _sqlWriter.WriteCreate(_sqlSW, table.Columns[0]);
+ _sqlSW.WriteLine(",");
+ _sqlWriter.WriteCreate(_sqlSW, table.Columns[2]);
+
+ Assert.That(_sqlSW.ToString(), Is.EqualTo("ID int not null,\r\nName nvarchar(100) not null"));
+ }
+
+ [Test]
+ public void will_render_sql_WriteSummary()
+ {
+ var table = _model.FindTable("[Person]");
+
+ _sqlWriter.WriteSummary(_sqlSW, table.Columns[0]);
+ Assert.That(_sqlSW.ToString(), Is.EqualTo("ID (int not null)"));
+
+ _sqlSW = new StringWriter();
+ _sqlWriter.WriteSummary(_sqlSW, table.Columns[2]);
+ Assert.That(_sqlSW.ToString(), Is.EqualTo("Name (nvarchar(100) not null)"));
+ }
+
+ [Test]
+ public void will_render_sql_select_for_Person()
+ {
+ var table = _model.FindTable("[Person]");
+ _sqlWriter.WriteSelect(_sqlSW, table);
+ Assert.That(_sqlSW.ToString(), Is.EqualTo(@"SELECT
+ ID,
+ StaffUnitID,
+ Name,
+ DOB
+FROM [Person]
+"));
+ }
+
+ [Test]
+ public void will_render_sql_select_COUNT_for_Person()
+ {
+ var table = _model.FindTable("[Person]");
+ _sqlWriter.WriteSelectCount(_sqlSW, table);
+ Assert.That(_sqlSW.ToString().Replace(Environment.NewLine, ""), Is.EqualTo(@"SELECT COUNT(*) FROM [Person]"));
+ }
+
+ [Test]
+ public void will_render_insert_sql_for_StaffUnit()
+ {
+ var table = _model.FindTable("[StaffUnit]");
+ _sqlWriter.WriteInsert(_sqlSW, table);
+
+ Console.WriteLine(_sqlSW.ToString());
+ Assert.That(_sqlSW.ToString(), Is.EqualTo(@"INSERT INTO [StaffUnit]
+ (Name,
+ Description)
+VALUES
+ (N'' /*Name,nvarchar(100)*/,
+ null /*Description,nvarchar(500)*/)
+"));
+ }
+
+
+ [Test]
+ public void will_render_insert_sql_for_StaffUnit_including_PK()
+ {
+ _sqlWriter.IncludeReadOnlyColumnsInExport = true;
+
+ var table = _model.FindTable("[StaffUnit]");
+ _sqlWriter.WriteInsert(_sqlSW, table);
+
+ Console.WriteLine(_sqlSW.ToString());
+ Assert.That(_sqlSW.ToString(), Is.EqualTo(@"INSERT INTO [StaffUnit]
+ (ID,
+ Name,
+ Description)
+VALUES
+ (0 /*ID,int*/,
+ N'' /*Name,nvarchar(100)*/,
+ null /*Description,nvarchar(500)*/)
+"));
+ }
+
+
+ [Test]
+ public void will_render_update_sql_for_StaffUnit()
+ {
+ var table = _model.FindTable("[StaffUnit]");
+ _sqlWriter.WriteUpdate(_sqlSW, table);
+
+ Console.WriteLine(_sqlSW.ToString());
+ Assert.That(_sqlSW.ToString(), Is.EqualTo(@"UPDATE [StaffUnit]
+SET
+ Name = N'',
+ Description = null
+WHERE
+ ID = /*value:ID,int*/
+"));
+ }
+
+ [Test]
+ public void will_render_delete_sql_for_StaffUnit()
+ {
+ var table = _model.FindTable("[StaffUnit]");
+ _sqlSW = new StringWriter();
+ _sqlWriter.WriteDelete(_sqlSW, table);
+ //Console.WriteLine(sql.ToString());
+ Assert.That(_sqlSW.ToString(), Is.EqualTo(@"DELETE FROM
+ [StaffUnit]
+WHERE
+ ID = /*value:ID*/
+"));
+
+ }
+ }
+}
\ No newline at end of file