miniSql

创建
zgc123@gmail.com authored at 11/19/2023 1:40:15 AM
6136600
Tree
0 Parent(s)
Summary: 5 changed files with 245 additions and 0 deletions.
Added +2 -0
Added +8 -0
Added +62 -0
Added +59 -0
Added +114 -0
Added +2 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/bar.mt b/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/bar.mt
new file mode 100644
index 0000000..672c4a4
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/bar.mt
@@ -0,0 +1,2 @@
+// gen at {$Host.Date("d/M/yy")}
+BAR
\ No newline at end of file
Added +8 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/foo.cs.mt b/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/foo.cs.mt
new file mode 100644
index 0000000..420dad2
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/foo.cs.mt
@@ -0,0 +1,8 @@
+// gen at {$Host.Date("d/M/yy")}
+public class foo
+{
+	public string baa()
+	{
+		return "baa";
+	}
+}
\ No newline at end of file
Added +62 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/TemplateHost_tests.cs b/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/TemplateHost_tests.cs
new file mode 100644
index 0000000..405b45b
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/TemplateHost_tests.cs
@@ -0,0 +1,62 @@
+#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;
+using MiniSqlQuery.PlugIns.TemplateViewer;
+using NUnit.Framework;
+
+using Rhino.Mocks;
+
+namespace MiniSqlQuery.Tests.Templates
+{
+    [TestFixture]
+    public class TemplateHost_tests
+    {
+        private TemplateHost _host;
+        IApplicationServices _services;
+        IDatabaseInspector _databaseInspector;
+
+        [SetUp]
+        public void TestSetUp()
+        {
+            _services = MockRepository.GenerateStub<IApplicationServices>();
+            _databaseInspector = MockRepository.GenerateStub<IDatabaseInspector>();
+            _host = new TemplateHost(_services, _databaseInspector);
+        }
+
+        [Test]
+        public void UserName()
+        {
+            Assert.That(_host.UserName, Is.Not.Null);
+        }
+
+        [Test]
+        public void ToPascalCase()
+        {
+            Assert.That(_host.ToPascalCase(null), Is.EqualTo(""));
+            Assert.That(_host.ToPascalCase("name"), Is.EqualTo("Name"));
+            Assert.That(_host.ToPascalCase("foo baa"), Is.EqualTo("FooBaa"));
+            Assert.That(_host.ToPascalCase("user_id"), Is.EqualTo("UserId"));
+            Assert.That(_host.ToPascalCase("firstName"), Is.EqualTo("FirstName"));
+            Assert.That(_host.ToPascalCase("FirstName"), Is.EqualTo("FirstName"));
+            Assert.That(_host.ToPascalCase("id"), Is.EqualTo("Id"));
+            Assert.That(_host.ToPascalCase("ID"), Is.EqualTo("ID"));
+        }
+
+        [Test]
+        public void ToCamelCase()
+        {
+            Assert.That(_host.ToCamelCase(null), Is.EqualTo(""));
+            Assert.That(_host.ToCamelCase("name"), Is.EqualTo("name"));
+            Assert.That(_host.ToCamelCase("Foo"), Is.EqualTo("foo"));
+            Assert.That(_host.ToCamelCase("bat man"), Is.EqualTo("batMan"));
+            Assert.That(_host.ToCamelCase("bat_man"), Is.EqualTo("batMan"));
+            Assert.That(_host.ToCamelCase("XYZCodeThing"), Is.EqualTo("xyzCodeThing"));
+            Assert.That(_host.ToCamelCase("XYZ Code Thing"), Is.EqualTo("xyzCodeThing"));
+            Assert.That(_host.ToCamelCase("user_name"), Is.EqualTo("userName"));
+            Assert.That(_host.ToCamelCase("id"), Is.EqualTo("id"));
+        }
+    }
+}
\ No newline at end of file
Added +59 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/TemplateModel_tests.cs b/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/TemplateModel_tests.cs
new file mode 100644
index 0000000..620c3c7
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/TemplateModel_tests.cs
@@ -0,0 +1,59 @@
+#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.IO;
+using MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Template;
+using MiniSqlQuery.PlugIns.TemplateViewer;
+using NUnit.Framework;
+using Rhino.Mocks;
+
+// ReSharper disable InconsistentNaming
+
+namespace MiniSqlQuery.Tests.Templates
+{
+    [TestFixture]
+    public class TemplateModel_tests
+    {
+        TemplateModel _model;
+        IApplicationServices _services;
+        IDatabaseInspector _databaseInspector;
+
+        [SetUp]
+        public void TestSetUp()
+        {
+            _services = MockRepository.GenerateStub<IApplicationServices>();
+            _databaseInspector = MockRepository.GenerateStub<IDatabaseInspector>();
+            _services.Expect(x => x.Resolve<TemplateHost>()).Return(new TemplateHost(_services, _databaseInspector));
+            _model = new TemplateModel(_services, new NVelocityWrapper());
+        }
+
+        [Test]
+        public void ModelData_parameters_are_precessed()
+        {
+            var items = new Dictionary<string, object>();
+            string processedtext = _model.ProcessTemplate("create new ${Host.Date(\"yyyy\")}", items).Text;
+            Assert.That(processedtext, Is.EqualTo("create new " + DateTime.Now.Year));
+        }
+
+        [Test]
+        public void If_a_file_extension_is_set_this_defaults_the_TemplateResult()
+        {
+            var filename = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Templates\foo.cs.mt");
+            var result = _model.ProcessTemplateFile(filename, null);
+            Assert.That(result.Extension, Is.EqualTo("cs"));
+        }
+
+        [Test]
+        public void If_no_file_extension_is_set_this_defaults_the_TemplateResult_to_SQL()
+        {
+            var filename = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Templates\bar.mt");
+            var result = _model.ProcessTemplateFile(filename, null);
+            Assert.That(result.Extension, Is.EqualTo("sql"));
+        }
+    }
+}
\ No newline at end of file
Added +114 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/TextFormater_tests.cs b/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/TextFormater_tests.cs
new file mode 100644
index 0000000..9e6af7d
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Tests/Templates/TextFormater_tests.cs
@@ -0,0 +1,114 @@
+#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 MiniSqlQuery.Core.DbModel;
+using MiniSqlQuery.Core.Template;
+using NUnit.Framework;
+
+
+namespace MiniSqlQuery.Tests.Templates
+{
+    [TestFixture]
+    public class TextFormater_tests
+    {
+        #region Setup/Teardown
+
+        [SetUp]
+        public void TestSetUp()
+        {
+            _formatter = new NVelocityWrapper();
+        }
+
+        #endregion
+
+        private class MyClass
+        {
+            public string Name { get; set; }
+            public DateTime Time { get; set; }
+            public int Age { get; set; }
+        }
+
+        private ITextFormatter _formatter;
+
+        public class Something
+        {
+            private string firstName = "hammett";
+            private string middleNameInitial = "V";
+
+            public string FirstName
+            {
+                get { return firstName; }
+                set { firstName = value; }
+            }
+
+            public string MiddleNameInitial
+            {
+                get { return middleNameInitial; }
+                set { middleNameInitial = value; }
+            }
+
+            public String Print(String arg)
+            {
+                return arg;
+            }
+
+            public String Contents(params String[] args)
+            {
+                return String.Join(",", args);
+            }
+        }
+
+        [Test]
+        public void Accepts_values()
+        {
+            MyClass o = new MyClass { Name = "Blue", Age = 32 };
+            Dictionary<string, object> items = new Dictionary<string, object>();
+            items.Add("data", o);
+            string text = _formatter.Format("Mr $data.Name arrived, aged $data.Age.", items);
+            Assert.That(text, Is.EqualTo("Mr Blue arrived, aged 32."));
+        }
+
+        [Test]
+        public void nvelocity_with_dbmodel2()
+        {
+            DbModelInstance model = new DbModelInstance();
+            model.ConnectionString = "conn str";
+            model.ProviderName = "sql.foo";
+            DbModelTable table = new DbModelTable { Name = "MyTable" };
+            model.Add(table);
+            table.Add(new DbModelColumn { Name = "ID" });
+            table.Add(new DbModelColumn { Name = "FirstName" });
+
+            Dictionary<string, object> items = new Dictionary<string, object>();
+            items.Add("model", model);
+
+            string template =
+                @"Template Test ($num):
+ConnectionString: ""$model.ConnectionString""
+ProviderName: ""$model.ProviderName""
+
+#foreach ($table in $model.Tables)
+$table.Name
+#foreach ($c in $table.Columns)
+  * $c.Name
+#end
+#end
+";
+            string s = _formatter.Format(template, items);
+
+            Console.WriteLine(s);
+            Assert.That(s.Length, Is.GreaterThan(0));
+        }
+
+        [Test]
+        public void Unchanged()
+        {
+            string text = _formatter.Format("nothing", null);
+            Assert.That(text, Is.EqualTo("nothing"));
+        }
+    }
+}
\ No newline at end of file