-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.cs
More file actions
128 lines (117 loc) · 4.54 KB
/
Copy pathController.cs
File metadata and controls
128 lines (117 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utility.Core;
using Utility.Data;
using Utility.Generic;
using Utility.WebForm;
namespace UnitTest
{
/// <summary>
/// SQL 的摘要说明
/// </summary>
[TestClass]
public class Controller
{
public const string CONNECTION_STRING = "UnitTest";
public const string TABLE_NAME = "Profile";
public Controller()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
private TestContext testContextInstance;
/// <summary>
///获取或设置测试上下文,该上下文提供
///有关当前测试运行及其功能的信息。
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region 附加测试特性
//
// 编写测试时,可以使用以下附加特性:
//
// 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
[ClassInitialize()]
public static void MyClassInitialize(TestContext testContext)
{
testContext.AddResultFile("TestResult.txt");
}
//
// 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// 在运行每个测试之前,使用 TestInitialize 来运行代码
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// 在每个测试运行完之后,使用 TestCleanup 来运行代码
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
public void ExectueInsertSql()
{
using (var conn = Factory.CreateConnection())
{
Panel pnl = new Panel();
pnl.Controls.Add(CreateTextBox("FromName", "Tom", "FromName"));
pnl.Controls.Add(CreateTextBox("ToName", "Mary", "ToName"));
pnl.Controls.Add(CreateTextBox("Title", "Hi", "Title"));
pnl.Controls.Add(CreateTextBox("Contents", "最近过得怎么样?!", "Contents"));
pnl.Controls.Add(CreateTextBox("SendTime", DateTime.Now.ToString(), "SendTime"));
pnl.Controls.Add(CreateTextBox(null, "NULL", "ReadTime")); // 拼接SQL
pnl.Controls.Add(CreateTextBox("Category", "问候", "Category"));
var args = pnl.CreateParameters<SqlParameter>();
args.Add("@SNID", conn.MongoID(), "SNID");
string build_sql = conn.BuildInsertSql(Factory.LETTER_TABLE, args);
string get_sql = conn.GetInsertSql(Factory.LETTER_TABLE, args);
conn.ExecuteNonQuery(build_sql, args);
}
}
[TestMethod]
public void ExectueDeleteSql()
{
using (SqlConnection conn = new SqlConnection())
{
Panel pnl = new Panel();
pnl.Controls.Add(CreateTextBox("FromName", "Tom", "FromName LIKE"));
pnl.Controls.Add(CreateTextBox("ToName", "Mary", "ToName ="));
pnl.Controls.Add(CreateTextBox("Title", "", "Title LIKE"));
pnl.Controls.Add(CreateTextBox("Contents", "", "Contents LIKE"));
pnl.Controls.Add(CreateTextBox("SendTime", "", "SendTime LIKE"));
pnl.Controls.Add(CreateTextBox(null, "ReadTime IS NULL", " J")); // 拼接SQL
pnl.Controls.Add(CreateTextBox("Category", "", "Category Like"));
var args = pnl.CreateParameters<SqlParameter>();
string build_sql = conn.BuildDeleteSql(TABLE_NAME, args);
string get_sql = conn.GetDeleteSql(TABLE_NAME, args);
}
}
public TextBox CreateTextBox(string id, string text, string fieldname)
{
TextBox txt = new TextBox()
{
ID = id,
Text = text,
};
txt.Attributes["data-fieldname"] = fieldname;
return txt;
}
}
}