-
我的两段代码
userLoginJudge()
1 public bool userLoginJudge()
2 {
3 SqlConnection conn = new SqlConnection(connstring);
4 SqlCommand cmd = new SqlCommand("select UserPass from users where username='" + _LoginName + "'",conn);
5 SqlDataReader passread;
6
7 conn.Open();
8 passread = cmd.ExecuteReader(CommandBehavior.SingleRow);
9 passread.Read();
10
11 if ((passread.HasRows) && (_LoginPass == passread.GetString(0)))
12 {
13 passread.Close();
14 conn.Close();
15 return true; }
16 else
17 {
18 passread.Close();
19 conn.Close();
20 return false; }
21
22 }
2 {
3 SqlConnection conn = new SqlConnection(connstring);
4 SqlCommand cmd = new SqlCommand("select UserPass from users where username='" + _LoginName + "'",conn);
5 SqlDataReader passread;
6
7 conn.Open();
8 passread = cmd.ExecuteReader(CommandBehavior.SingleRow);
9 passread.Read();
10
11 if ((passread.HasRows) && (_LoginPass == passread.GetString(0)))
12 {
13 passread.Close();
14 conn.Close();
15 return true; }
16 else
17 {
18 passread.Close();
19 conn.Close();
20 return false; }
21
22 }
userLogin()构造函数
1 public userLogin(string LoginName, string LoginPass)
2 {
3 this._LoginName = LoginName;
4 this._LoginPass = LoginPass;
5 }
6 #endregion
2 {
3 this._LoginName = LoginName;
4 this._LoginPass = LoginPass;
5 }
6 #endregion
生成的两段已修改的测试代码
1 /// <summary>
2 ///userLoginJudge 的测试
3 ///</summary>
4 [TestMethod()]
5 [HostType("ASP.NET")]
6 [AspNetDevelopmentServerHost("%PathToWebRoot%\\WebSite5", "/WebSite5")]
7 [UrlToTest("http://localhost/WebSite5")]
8 public void userLoginJudgeTest()
9 {
10 userLogin_Accessor target = new userLogin_Accessor(); // TODO: 初始化为适当的值
11 bool expected = true; // TODO: 初始化为适当的值
12 bool actual;
13 target._LoginName = "admin";
14 target._LoginPass = "888888";
15 actual = target.userLoginJudge();
16 Assert.AreEqual(expected, actual, "错误出现于userLoginJudgeTest");
17 }
18
19 /// <summary>
20 ///userLogin 构造函数 的测试
21 ///</summary>
22 [TestMethod()]
23 [HostType("ASP.NET")]
24 [AspNetDevelopmentServerHost("%PathToWebRoot%\\WebSite5", "/WebSite5")]
25 [UrlToTest("http://localhost/WebSite5")]
26 public void userLoginConstructorTest()
27 {
28 string LoginName = "admin"; // TODO: 初始化为适当的值
29 string LoginPass = "888888"; // TODO: 初始化为适当的值
30 userLogin_Accessor target = new userLogin_Accessor(LoginName, LoginPass);
31 bool expected = false; // TODO: 初始化为适当的值
32 bool actual;
33 actual = target.userLoginJudge();
34 Assert.AreEqual(expected,actual);
35 }
2 ///userLoginJudge 的测试
3 ///</summary>
4 [TestMethod()]
5 [HostType("ASP.NET")]
6 [AspNetDevelopmentServerHost("%PathToWebRoot%\\WebSite5", "/WebSite5")]
7 [UrlToTest("http://localhost/WebSite5")]
8 public void userLoginJudgeTest()
9 {
10 userLogin_Accessor target = new userLogin_Accessor(); // TODO: 初始化为适当的值
11 bool expected = true; // TODO: 初始化为适当的值
12 bool actual;
13 target._LoginName = "admin";
14 target._LoginPass = "888888";
15 actual = target.userLoginJudge();
16 Assert.AreEqual(expected, actual, "错误出现于userLoginJudgeTest");
17 }
18
19 /// <summary>
20 ///userLogin 构造函数 的测试
21 ///</summary>
22 [TestMethod()]
23 [HostType("ASP.NET")]
24 [AspNetDevelopmentServerHost("%PathToWebRoot%\\WebSite5", "/WebSite5")]
25 [UrlToTest("http://localhost/WebSite5")]
26 public void userLoginConstructorTest()
27 {
28 string LoginName = "admin"; // TODO: 初始化为适当的值
29 string LoginPass = "888888"; // TODO: 初始化为适当的值
30 userLogin_Accessor target = new userLogin_Accessor(LoginName, LoginPass);
31 bool expected = false; // TODO: 初始化为适当的值
32 bool actual;
33 actual = target.userLoginJudge();
34 Assert.AreEqual(expected,actual);
35 }