public void ShouldSearchStudentById(StudentEntity student) { var result = sut.SearchStudentById(student); Assert.That(result, Is.Not.Null); Assert.That(result, Is.InstanceOf <StudentEntity>()); }
/// <summary> /// To search a student record. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSearch_Click(object sender, EventArgs e) { StudentEntity student = new StudentEntity(); if (txtId.Text != string.Empty) { student.Id = Convert.ToInt32(txtId.Text); CheckStudentValidations studentValidations = new CheckStudentValidations(); StudentEntity studentResult = new StudentEntity(); studentResult = studentValidations.SearchStudentById(student); if (studentResult != null) { txtName.Text = studentResult.Name; txtAge.Text = studentResult.Age.ToString(); if (studentResult.Gender == 'M' || studentResult.Gender == 'm') { radioGender1.Checked = true; } else { radioGender2.Checked = true; } txtId.Enabled = false; } else { MessageBox.Show("No student with this id exists", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearFields(); txtId.Enabled = false; } } else if (txtName.Text != string.Empty) { student.Name = txtName.Text; CheckStudentValidations studentValidations = new CheckStudentValidations(); StudentEntity studentResult = new StudentEntity(); studentResult = studentValidations.SearchStudentByName(student); if (studentResult != null) { if (studentResult.IsMultipleRecordExist) { txtId.Text = studentResult.Id.ToString(); txtName.Text = studentResult.Name; txtAge.Text = studentResult.Age.ToString(); if (studentResult.Gender == 'M' || studentResult.Gender == 'm') { radioGender1.Checked = true; } else { radioGender2.Checked = true; } MessageBox.Show("Multiple Student Exists with name : " + studentResult.Name + ". If this is not the record you're looking for kindly search by student ID.", "Multiple Records", MessageBoxButtons.OK, MessageBoxIcon.Information); txtId.Enabled = true; } else { txtId.Text = studentResult.Id.ToString(); txtName.Text = studentResult.Name; txtAge.Text = studentResult.Age.ToString(); if (studentResult.Gender == 'M' || studentResult.Gender == 'm') { radioGender1.Checked = true; } else { radioGender2.Checked = true; } txtId.Enabled = false; } } else { MessageBox.Show("No student with this Name exists", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearFields(); txtId.Enabled = false; } } else { MessageBox.Show("Fill Name to search!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }