Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
See more:
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

C#
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)) //Checks if the textbox is empty or not
            {
                toolStripStatusLabel1.Text= "Last name Required";
            }
            else if (pattern.IsMatch(txtlname.Text)) //Regex pattern matching is done here
            {
                lastname = txtlname.Text.ToUpper().Trim(); //Trims the before and after spaces
                fetchPatientDetails(lastname);
            }
            else
            {
                toolStripStatusLabel1.Text = "Invalid Input";
            }
        }



C#
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
Posted
Updated 24-Apr-17 23:14pm

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900