How to create a unit testing for a function
protected void Finish_Click(object sender, EventArgs e)
{
bool status = yes_wk.Checked;
int score = 0;
if (Page.IsValid)
{
if (q5.SelectedItem.Value == "4")
{
score += 1;
}
}
// score = (score / 10) * 100;
score = score * 9;
lblScore1.Text = "The score is " + score.ToString() + " % of corrected answers";
if (score >= 70)
{
sqlConfigConnString1 = ConfigurationManager.ConnectionStrings["Citistaff"].ConnectionString;
DBaseConnection appConnect = new DBaseConnection(sqlConfigConnString1);
appConnect.Conn.ConnectionString = appConnect.ConnectionString;
sqlStatement1 = "INSERT INTO MathTestScore (MathTestScore, SignDateTime, Status, Emailsession)";
sqlStatement1 += "VALUES(@MathTestScore, @SignDateTime, @Status, @Emailsession)";
if (appConnect.Conn.State == ConnectionState.Closed)
{
appConnect.OpenConnection();
appConnect.ExecuteQuery(sqlStatement1);
}
appConnect.Comd.Parameters.AddWithValue("@MathTestScore", lblScore1.Text.Trim().ToString());
appConnect.Comd.Parameters.AddWithValue("@SignDateTime", System.DateTime.Now);
appConnect.Comd.Parameters.AddWithValue("@Status", status);
appConnect.Comd.Parameters.AddWithValue("@Emailsession", Session["userEmail"].ToString().Trim());
appConnect.DataAdapterConnection();
if (appConnect.Conn.State == ConnectionState.Open)
appConnect.CloseAll();
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Congrats, you just pass a test.');", true);
Response.Redirect("W4.aspx");
}
else
{
string message = "Oops, you have not passed a test, try it again.";
string url = "/MathTest.aspx";
string script = "{ alert('";
script += message;
script += "');";
script += "window.location = '";
script += url;
script += "'; }";
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "alert", script, true);
}
}