我有以下 NUnit 代码。我在 [SetUp] 中使用 switch case 语句
在测试运行之前,预计将数据插入数据库;但它没有插入数据。这里需要纠正什么?
参考:
代码
[SetUp]
public void TestSetUp()
{
switch (TestContext.CurrentContext.Test.FullName)
{
case "GetApplicationsTest":
GetApplicationsTestSETUPHElper();
break;
case "DeleteApplicationTest":
GetApplicationsTestSETUPHElper();
break;
}
}
private void GetApplicationsTestSETUPHElper()
{
SqlConnection connection = new SqlConnection(connectionString);
using (connection)
{
string commandText = "INSERT INTO Status_Type VALUES (889,'s2','UT s2')";
SqlCommand command = new SqlCommand(commandText, connection);
command.CommandType = System.Data.CommandType.Text;
connection.Open();
command.ExecuteNonQuery();
}
}
private void DeleteApplicationTestSETUPHElper()
{
SqlConnection connection = new SqlConnection(connectionString);
using (connection)
{
string commandText = "INSERT INTO Status_Type VALUES (890,'s3','UT s3')";
SqlCommand command = new SqlCommand(commandText, connection);
command.CommandType = System.Data.CommandType.Text;
connection.Open();
command.ExecuteNonQuery();
}
}
[Test]
public void GetApplicationsTest()
{
ApplicationBL application = new ApplicationBL(connectionString);
ApplicationSearch applicationSearch = new ApplicationSearch();
applicationSearch.ApplicationID = 1;
//applicationSearch.ApplicationName = "Test1";
//applicationSearch.ApplicationURL = "Test1";
//applicationSearch.StatusCode = 1;
Collection<Application> applications = application.GetApplications(applicationSearch);
}
[Test]
public void DeleteApplicationTest()
{
ApplicationBL application = new ApplicationBL(connectionString);
ApplicationSearch applicationSearch = new ApplicationSearch();
applicationSearch.ApplicationID = 1;
//applicationSearch.ApplicationName = "Test1";
//applicationSearch.ApplicationURL = "Test1";
//applicationSearch.StatusCode = 1;
Collection<Application> applications = application.GetApplications(applicationSearch);
}