我的代码从文件中获取输入。如果我必须为它编写 NUnit 测试用例,我是否必须更改我的代码并从测试用例而不是文件中获取输入,或者我是否有可能不必更改我的代码。?
请帮忙。
下面给出的是我必须测试的功能之一。
public void CLEAN_Discipline(string disp)
{
//////////////////////////////////////////////////////SQL CONNECTION////////////////////////////////////////////////
string sqlconnectionString = "server=localhost;" + "database=fastdata;" + "uid=dwh;" + "password=dwh;";
MySqlConnection cnMySQL = new MySqlConnection(sqlconnectionString);
MySqlCommand cmdMySQL = cnMySQL.CreateCommand();
cmdMySQL.CommandText = "Select * from single";
MySqlDataReader reader;
String query;
MySqlCommand cmd2;
cnMySQL.Open();
reader = cmdMySQL.ExecuteReader();
while (reader.Read())
{
string disp = reader["Discipline"].ToString();
disp = disp.ToUpper();
disp = disp.Replace("MS", "");
disp = disp.Replace("-", "");
disp = disp.Replace(" ", "");
string roll = reader["RollNumber"].ToString();
MySqlConnection cnMySQL2 = new MySqlConnection(sqlconnectionString);
cnMySQL2.Open();
query = "UPDATE single SET Discipline = ('" + disp + "') where RollNumber = '" + roll + "' ";
cmd2 = new MySqlCommand(query, cnMySQL2);
cmd2.ExecuteNonQuery();
cnMySQL2.Close();
}
cnMySQL.Close();
cnMySQL.Open();
reader = cmdMySQL.ExecuteReader();
while (reader.Read())
{
string roll = reader["RollNumber"].ToString();
string disp = reader["Discipline"].ToString();
string degree = reader["Degree"].ToString();
if (degree == "MS")
{
if (roll[0] == 'I')
{
if (disp != "CS" && disp != "SPM" && disp != "")
{
disp = "UNKNOWN";
}
}
else if (roll[0] == 'K')
{
if (disp != "CS" && disp != "SPM" && disp != "TC" && disp != "NW")
{
disp = "UNKNOWN";
}
}
else if (roll[0] == 'P')
{
if (disp != "CS" && disp != "TC")
{
disp = "UNKNOWN";
}
}
else if (roll[0] == 'L')
{
if (disp != "CS" && disp != "SPM" && disp != "TC" && disp != "NW")
{
disp = "UNKNOWN";
}
}
}
if (disp == "UNKNOWN")
{
MySqlConnection cnMySQL2 = new MySqlConnection(sqlconnectionString);
cnMySQL2.Open();
query = "UPDATE single SET Discipline = ('" + disp + "') where RollNumber = '" + roll + "' ";
cmd2 = new MySqlCommand(query, cnMySQL2);
cmd2.ExecuteNonQuery();
cnMySQL2.Close();
}
}
}