I have a block of code which has a security context.
Now my question is how do i go about unit testing this? This is a windows form. Written in C#. I have created a unit test project. I want to know what classes should i include and how to do them. Have used datagridview to display the items
private void btnsearch_Click(object sender, EventArgs e)
{
string lastname=null;
refreshgrid();
Regex pattern = new Regex("^[a-zA-Z'-]{1,30}$");
if (String.IsNullOrEmpty(txtlname.Text))
{
toolStripStatusLabel1.Text= "Last name Required";
}
else if (pattern.IsMatch(txtlname.Text))
{
lastname = txtlname.Text.ToUpper().Trim();
fetchPatientDetails(lastname);
}
else
{
toolStripStatusLabel1.Text = "Invalid Input";
}
}
private void GridOperations(object sender, DataGridViewCellEventArgs e)
{
int rowindex = e.RowIndex;
DataGridViewRow row = ((DataGridView)sender).Rows[rowindex];
string id = row.Cells[0].Value.ToString();
switch (((DataGridView)sender).Name)
{
case "dgvpatient":
hidereaction();
hideallergy();
lblencounter.Show();
string patientid = row.Cells[0].Value.ToString();
displayDetails(sender, id, 1, 2180508);
break;
case "dgvencounter":
hidereaction();
lblallergy.Show();
displayDetails(sender, id, 2, 2180509);
break;
case "dgvallergy":
lblreaction.Show();
displayDetails(sender, id, 3, 2180510);
break;
}
}
What I have tried:
I have no idea how to proceed.
Hence i have not tried anything