miniSql

创建
zgc123@gmail.com authored at 11/19/2023 1:40:15 AM
6136600
Tree
0 Parent(s)
Summary: 1 changed files with 114 additions and 0 deletions.
Added +114 -0
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