public bool CreateHealthFacility([FromBody] CreateHealthFacitityCommand request) { HealthFacilityContext context = HttpContext.RequestServices.GetService(typeof(HealthFacilityContext)) as HealthFacilityContext; CreateHealthFacilityHandler handler = new CreateHealthFacilityHandler(context); return(handler.Handle(request)); }
public void CreateFacilityTest() { // arrange List <MedicalHealthFacility> list = new List <MedicalHealthFacility>(); MedicalHealthFacility expected = new MedicalHealthFacility { Address = new Address { Street = "s", City = "c", Country = "c", House = 1 }, Name = "Facility#3" }; CreateHealthFacitityCommand command = new CreateHealthFacitityCommand { Address = new Address { Street = "s", City = "c", Country = "c", House = 1 }, Name = "Facility#3" }; //act HealthFacilityContext context = new HealthFacilityContext(connString); CreateHealthFacilityHandler handler = new CreateHealthFacilityHandler(context); handler.Handle(command); using (conn = new MySqlConnection(connString)) { conn.Open(); string query = string.Format("select * from health_facilities where address='улица s, дом 1, город c, страна c' and name='Facility#3'"); MySqlCommand cmd = new MySqlCommand(query, conn); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { string addressString = reader["address"].ToString(); Address address = Converter.ConvertToAddress(addressString); list.Add(new MedicalHealthFacility() { Id = Convert.ToInt32(reader["faculty_id"]), Name = reader["name"].ToString(), Address = address, }); } } } if (list[0].Name == expected.Name && list[0].Address == expected.Address) { Assert.IsTrue(true); } }