示例#1
0
        public bool CreateMedicalSpecialist([FromBody] CreateSpecialistCommand request)
        {
            SpecialistContext       context = HttpContext.RequestServices.GetService(typeof(SpecialistContext)) as SpecialistContext;
            CreateSpecialistHandler handler = new CreateSpecialistHandler(context);

            return(handler.Handle(request));
        }
        public void CreateCourseTest()
        {
            // arrange
            List <MedicalSpecialist> list = new List <MedicalSpecialist>();

            MedicalSpecialist expected = new MedicalSpecialist
            {
                LastName     = "lastname",
                FirstName    = "name",
                MiddleName   = "middlename",
                Email        = "*****@*****.**",
                PasswordHash = "password",
                HealthFacilitiesFacultyId = 1,
            };

            CreateSpecialistCommand command = new CreateSpecialistCommand
            {
                LastName     = "lastname",
                FirstName    = "name",
                MiddleName   = "middlename",
                Email        = "*****@*****.**",
                PasswordHash = "password",
                HealthFacilitiesFacultyId = 1,
            };

            //act
            SpecialistContext       context = new SpecialistContext(connString);
            CreateSpecialistHandler handler = new CreateSpecialistHandler(context);

            handler.Handle(command);


            using (conn = new MySqlConnection(connString))
            {
                conn.Open();
                string query = string.Format("select * from specialists where email='*****@*****.**' and last_name='lastname'");

                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.HealthFacilitiesFacultyId &&
                list[0].LastName == expected.LastName && list[0].Email == expected.Email)
            {
                Assert.IsTrue(true);
            }
        }