|
我采用nunit工具测试,代码如下:
/*******************************************************/
public class DataList
{
protected DataSet datalist = new DataSet();
protected static SqlConnection myConnection = new SqlConnection("Server=local;DataBase=jwdw;uid=sa;pwd=");
protected static string sqlstring;
public string SqlString
{
get
{
return sqlstring;
}
set
{
sqlstring=value;
}
}
public DataSet DSList()
{
if(myConnection.State.ToString()!="Open")
{
ConnectionOpen();
}
SqlDataAdapter myAdapter = new SqlDataAdapter(sqlstring,myConnection);
myAdapter.Fill(datalist,"ds");
if(myConnection.State.ToString()!="Close")
{
ConnectionClose();
}
return datalist;
}
private void ConnectionOpen()
{
myConnection.Open();
}
private void ConnectionClose()
{
myConnection.Close();
}
}
/********************************************************/
我的测试代码如下:
/********************************************************/
[TestFixture]
public class TestDataList
{
protected DataSet datalist = new DataSet();
protected static SqlConnection myConnection = new SqlConnection("Server=192.168.42.93;DataBase=jwdw;uid=sa;pwd=");
protected static string sqlstring;
[Test]
public void ds()
{
SqlDataAdapter myAdapter = new SqlDataAdapter("select top 1 * from t_jwdwCheckUp",myConnection);
DataSet datalist = new DataSet();
myAdapter.Fill(datalist,"dl");
DataList dl = new DataList();
dl.SqlString="select * from t_jwdwCheckUp";
dl.DSList();
Assert.AreEqual(datalist,dl.DSList(),datalist.Tables[0].Rows.Count.ToString());
}
}
/********************************************************/
这样写并不能体现程序会有什么的问题和错误,请问应该怎么写? |
|