public MedicalCourse GetCourseById(int id) { CourseContext context = HttpContext.RequestServices.GetService(typeof(CourseContext)) as CourseContext; GetCourseByIdHandler handler = new GetCourseByIdHandler(context); return(handler.Handle(id)); }
public void GetCourseByIdTest() { // arrange List <MedicalCourse> list = new List <MedicalCourse>(); int id = 2; MedicalCourse expected = new MedicalCourse { Name = "Ёндокринологи¤", Qualification = 2 }; //act Course.Data.CourseContext context = new Course.Data.CourseContext(connString); GetCourseByIdHandler handler = new GetCourseByIdHandler(context); handler.Handle(id); using (conn = new MySqlConnection(connString)) { conn.Open(); string query = string.Format("select * from Courses where course_id=2"); MySqlCommand cmd = new MySqlCommand(query, conn); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { list.Add(new MedicalCourse() { Id = Convert.ToInt32(reader["course_id"]), Name = reader["course_name"].ToString(), Qualification = Convert.ToInt32(reader["qualification"]) }); } } } if (list[0].Name == expected.Name && list[0].Qualification == expected.Qualification) { Assert.IsTrue(true); } }