public void TestStorageLocationEvent() { //Arrange IRepositoryLocationEvent test = new RepositoryLocationEvent(); StorageLocationEvent ob = new StorageLocationEvent(); StorageLocationEvent ob2 = new StorageLocationEvent { IdLocationEvent=2, City="Sankt-Petersburg", Street="Nevsky Avenue", Home="34", GMap="https://www.google.ru/maps/@59.9352387,30.3272743,17z" }; //Act ob = test.GetSQlData(stringConnection, 2); //Assert Assert.AreEqual(ob2.GMap, ob.GMap); }
public StorageLocationEvent GetSQlData(string stringConnection, int _Id) { SqlConnection conn = new SqlConnection(stringConnection); conn.Open(); Logger logger = LogManager.GetCurrentClassLogger(); logger.Info("Inside"); string sqlGetCmd = @"select City,Street,Home,GMap from LocationEvent where IdLocationEvent = @_IdLocationEvent"; StorageLocationEvent locationEvent = new StorageLocationEvent(); SqlCommand cmd = new SqlCommand(sqlGetCmd, conn); cmd.Parameters.AddWithValue("_IdLocationEvent", _Id); SqlDataReader rdb = cmd.ExecuteReader(); rdb.Read(); locationEvent.IdLocationEvent=_Id; locationEvent.City = (string)GetUnoSQlValue(rdb, "City"); //if (rdb.IsDBNull(rdb.GetOrdinal("City"))) //{ // locationEvent.City = null; //} //else //{ // locationEvent.City = rdb.GetString(rdb.GetOrdinal("City")); //} locationEvent.Street = locationEvent.City = (string)GetUnoSQlValue(rdb, "Street"); locationEvent.Home = locationEvent.City = (string)GetUnoSQlValue(rdb, "Home"); locationEvent.GMap = locationEvent.City = (string)GetUnoSQlValue(rdb, "GMap"); if (conn != null) { conn.Close(); conn.Dispose(); } else { logger.Warn("SQlConnection not close"); } if (rdb != null) { rdb.Close(); rdb.Dispose(); } return locationEvent; }
public void SetSQlData(string stringConnection, StorageLocationEvent locationEvent) { SqlConnection conn = new SqlConnection(stringConnection); conn.Open(); Logger logger = LogManager.GetCurrentClassLogger(); logger.Info("Inside"); string strInsert = @"insert into LocationEvent (City,Street,Home,GMap) values('@_City','@_Street','@_Home','@_GMap')"; SqlCommand cmd = new SqlCommand(strInsert, conn); cmd.Parameters.AddWithValue("@_City", locationEvent.City); cmd.Parameters.AddWithValue("@_Street", locationEvent.Street); cmd.Parameters.AddWithValue("@_Home", locationEvent.Home); cmd.Parameters.AddWithValue("@_GMap", locationEvent.GMap); cmd.ExecuteNonQuery(); if (conn != null) { conn.Close(); conn.Dispose(); } else { logger.Warn("SQlConnection not close"); } }