私のコードはファイルから入力を受け取ります。NUnit テスト ケースを作成する必要がある場合、コードを変更して、ファイルではなくテスト ケースから入力を取得する必要がありますか、それともコードを変更する必要がない可能性はありますか?
助けてください。
以下は、私がテストしなければならない機能の1つです。
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();
}
}
}