public void StudentAdd_Test() { StudentDTO stud = new StudentDTO(); stud.StudId = 101; stud.StudName = "Yash"; stud.StudBranch = "CSE"; stud.StudClass = "VIII-Sem-A"; bool flag = StudentCRUD.AddStudent(stud); Assert.AreEqual(true, flag); }
private void btnAdd_Click(object sender, EventArgs e) { try { Programs program = cbProgram.SelectedItem as Programs; StudentFactory student; MorningStudent morningStudent = null; EveningStudent eveningStudent = null; WeekendStudent weeklyStudent = null; bool insert = false; ClassSchedule classSchedule = cbClassesSchedule.SelectedItem as ClassSchedule; if (classSchedule.Id == 1) { student = new MorningStudentFactory(); morningStudent = (MorningStudent)student.GetStudent(); } else if (classSchedule.Id == 2) { student = new EveningStudentFactory(); eveningStudent = (EveningStudent)student.GetStudent(); } else if (classSchedule.Id == 3) { student = new WeekendStudentFactory(); weeklyStudent = (WeekendStudent)student.GetStudent(); } else { student = null; } if (student != null) { if (classSchedule.Id == 1) { morningStudent.Name = txtName.Text.Trim(); morningStudent.FatherName = txtFatherName.Text.Trim(); morningStudent.Address = txtAddress.Text.Trim(); morningStudent.DateOfBirth = dtpDoB.Value; morningStudent.DateOfAdmission = dtpDoAdmission.Value; morningStudent.ProgramID = program.ProgramsId; morningStudent.ClassScheduleID = classSchedule.Id; insert = studentCRUD.AddStudent(morningStudent); ClearTextBoxes(); } else if (classSchedule.Id == 2) { eveningStudent.Name = txtName.Text.Trim(); eveningStudent.FatherName = txtFatherName.Text.Trim(); eveningStudent.Address = txtAddress.Text.Trim(); eveningStudent.DateOfBirth = dtpDoB.Value; eveningStudent.DateOfAdmission = dtpDoAdmission.Value; eveningStudent.ProgramID = program.ProgramsId; eveningStudent.ClassScheduleID = classSchedule.Id; insert = studentCRUD.AddStudent(eveningStudent); ClearTextBoxes(); } else if (classSchedule.Id == 3) { weeklyStudent.Name = txtName.Text.Trim(); weeklyStudent.FatherName = txtFatherName.Text.Trim(); weeklyStudent.Address = txtAddress.Text.Trim(); weeklyStudent.DateOfBirth = dtpDoB.Value; weeklyStudent.DateOfAdmission = dtpDoAdmission.Value; weeklyStudent.ProgramID = program.ProgramsId; weeklyStudent.ClassScheduleID = classSchedule.Id; insert = studentCRUD.AddStudent(weeklyStudent); ClearTextBoxes(); } } else { MessageBox.Show("Error!"); } if (insert) { MessageBox.Show("New Student added successfully.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }