public IEnumerable <MedicalSpecialist> GetAllMedicalSpecialists() { SpecialistContext context = HttpContext.RequestServices.GetService(typeof(SpecialistContext)) as SpecialistContext; GetAllSpecialistsHandler handler = new GetAllSpecialistsHandler(context); return(handler.Handle()); }
public void GetAllCourses() { // arrange List <MedicalSpecialist> list = new List <MedicalSpecialist>(); List <MedicalSpecialist> expected = new List <MedicalSpecialist>(2); expected.Add(new MedicalSpecialist { LastName = "newlastname", FirstName = "newname", MiddleName = "mnewiddlename", Email = "*****@*****.**", PasswordHash = "password", HealthFacilitiesFacultyId = 1, }); expected.Add(new MedicalSpecialist { LastName = "lastname", FirstName = "name", MiddleName = "middlename", Email = "*****@*****.**", PasswordHash = "password", HealthFacilitiesFacultyId = 1, }); //act SpecialistContext context = new SpecialistContext(connString); GetAllSpecialistsHandler handler = new GetAllSpecialistsHandler(context); handler.Handle(); using (conn = new MySqlConnection(connString)) { conn.Open(); string query = string.Format("select * from specialists"); MySqlCommand cmd = new MySqlCommand(query, conn); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { list.Add(new MedicalSpecialist() { Id = Convert.ToInt32(reader["specialist_id"]), LastName = reader["last_name"].ToString(), FirstName = reader["first_name"].ToString(), MiddleName = reader["middle_name"].ToString(), Email = reader["email"].ToString(), HealthFacilitiesFacultyId = Convert.ToInt32(reader["Health_Facilities_faculty_id"]), }); } } } if (list[0].HealthFacilitiesFacultyId == expected[0].HealthFacilitiesFacultyId && list[0].LastName == expected[0].LastName && list[0].Email == expected[0].Email && list[1].HealthFacilitiesFacultyId == expected[1].HealthFacilitiesFacultyId && list[1].LastName == expected[1].LastName && list[1].Email == expected[1].Email) { Assert.IsTrue(true); } }