public int AddCity(City pCity) { const string q = "INSERT INTO [City] ([name], [district_id],[deleted]) VALUES (@name,@district_id,0) SELECT SCOPE_IDENTITY()"; using (SqlConnection conn = GetConnection()) using (OpenCbsCommand c = new OpenCbsCommand(q, conn)) { c.AddParam("@name", pCity.Name); c.AddParam("@district_id", pCity.DistrictId); c.AddParam("@deleted", pCity.Deleted); return int.Parse(c.ExecuteScalar().ToString()); } }
public void AddCity() { LocationsManager _locationManager = (LocationsManager)container["LocationsManager"]; Province province = new Province("France"); province.Id = _locationManager.AddProvince(province.Name); Assert.AreNotEqual(0, province.Id); District district = new District("Ile de France", province); district.Id = _locationManager.AddDistrict(district); Assert.AreNotEqual(0, district.Id); City city = new City {Name = "Paris", DistrictId = district.Id}; _locationManager.AddCity(city); }
public void TestDeleteCity() { List<City> cities = new List<City>(); City city = new City { Name = "New York", DistrictId = 12 }; DynamicMock dynamicMock = new DynamicMock(typeof(LocationsManager)); dynamicMock.ExpectAndReturn("AddCity", 3,city); dynamicMock.SetReturnValue("GetCities", cities); dynamicMock.Expect("DeleteCityById", 2); LocationsManager mocklocationManager = (LocationsManager)dynamicMock.MockInstance; LocationServices locationService = new LocationServices(mocklocationManager); locationService.DeleteCity(2); Assert.AreEqual(3, locationService.AddCity(city)); Assert.AreEqual(0, locationService.GetCities().Count); }
public void Get_Set_Id() { City city = new City { Id = 1 }; Assert.AreEqual(1, city.Id); }
public void Get_Set_District() { City city = new City {DistrictId = 1}; Assert.AreEqual(1,city.DistrictId); }
public void Get_Set_Deleted() { City city = new City { Deleted = true }; Assert.AreEqual(true, city.Deleted); }
public void TestUpdateCity() { LocationsManager _locationManager = (LocationsManager)container["LocationsManager"]; Province province = new Province("France"); province.Id = _locationManager.AddProvince(province.Name); Assert.AreNotEqual(0, province.Id); District district = new District("Ile de France", province); district.Id = _locationManager.AddDistrict(district); Assert.AreNotEqual(0, district.Id); City city = new City {Name = "Paris", DistrictId = district.Id}; city.Id=_locationManager.AddCity(city); city.Name = "qsd"; _locationManager.UpdateCity(city); List<City> cities = _locationManager.GetCities(); Assert.AreEqual("qsd", cities[0].Name); }
public void TestDeleteCity() { LocationsManager _locationManager = (LocationsManager)container["LocationsManager"]; Province province = new Province("France"); province.Id = _locationManager.AddProvince(province.Name); Assert.AreNotEqual(0, province.Id); District district = new District("Ile de France", province); district.Id = _locationManager.AddDistrict(district); Assert.AreNotEqual(0, district.Id); City city = new City { Name = "Paris", DistrictId = district.Id }; city.Id=_locationManager.AddCity(city); Assert.IsTrue(city.Id > 0); List<City> cities = _locationManager.GetCities(); Assert.AreEqual(1, cities.Count); _locationManager.DeleteCityById(city.Id); cities = _locationManager.GetCities(); Assert.AreEqual(0, cities.Count); }
private void buttonUpdate_Click(object sender, EventArgs e) { try { if (buttonUpdate.Text.Equals(GetString("buttonEdit"))) { try { node = treeViewLocations.SelectedNode; if (node == null) return; if ((node.Tag is Province)) { province = (Province) node.Tag; tbName.Text = province.Name; } else if ((node.Tag is District)) { district = (District) node.Tag; tbName.Text = district.Name; } else if ((node.Tag is City)) { city = (City) node.Tag; tbName.Text = city.Name; } } catch (Exception exception) { var exceptionStatus = CustomExceptionHandler.ShowExceptionText(exception); new frmShowError(exceptionStatus).ShowDialog(); return; } treeViewLocations.Enabled = false; buttonAdd.Enabled = false; buttonDelete.Enabled = false; buttonExit.Enabled = false; buttonUpdate.Text = GetString("buttonSave"); } else { try { if ((node.Tag is Province)) { province.Name = tbName.Text; ServicesProvider.GetInstance().GetLocationServices().UpdateProvince(province); } else if ((node.Tag is District)) { district.Name = tbName.Text; ServicesProvider.GetInstance().GetLocationServices().UpdateDistrict(district); } else if ((node.Tag is City)) { city.Name = tbName.Text; ServicesProvider.GetInstance().GetLocationServices().UpdateCity(city); } } catch (Exception exception) { var exceptionStatus = CustomExceptionHandler.ShowExceptionText(exception); new frmShowError(exceptionStatus).ShowDialog(); return; } node.Text = tbName.Text; buttonExit.Enabled = true; buttonAdd.Enabled = true; buttonDelete.Enabled = true; treeViewLocations.Enabled = true; buttonUpdate.Text = GetString("buttonEdit"); } } catch (Exception exception) { var exceptionStatus = CustomExceptionHandler.ShowExceptionText(exception); new frmShowError(exceptionStatus).ShowDialog(); return; } treeViewLocations.Sort(); }
public bool UpdateCity(City city) { CheckLocation(city.Name); return _locationsManager.UpdateCity(city); }
public void TestUpdateCity() { City city = new City {Name = "Pekin", DistrictId = 12}; List<City> cities = new List<City> {city}; DynamicMock mockLocationsManager = new DynamicMock(typeof(LocationsManager)); mockLocationsManager.ExpectAndReturn("AddCity", 3, city); mockLocationsManager.SetReturnValue("GetCities", cities); mockLocationsManager.ExpectAndReturn("UpdateCity", true, city); LocationsManager mocklocationManager = (LocationsManager)mockLocationsManager.MockInstance; LocationServices locationService = new LocationServices(mocklocationManager); Assert.AreEqual("Pekin", locationService.GetCities()[0].Name); Assert.AreEqual(true, locationService.UpdateCity(city)); }
public bool UpdateCity(City pCity) { bool updateOk = false; try { const string q = "UPDATE [City] SET [name]=@name WHERE id=@id"; using (SqlConnection conn = GetConnection()) using (OpenCbsCommand c = new OpenCbsCommand(q, conn)) { c.AddParam("@id", pCity.Id); c.AddParam("@name", pCity.Name); c.ExecuteNonQuery(); updateOk = true; } } catch (System.Exception ex) { throw ex; } return updateOk; }
public List<City> SelectCityByDistrictId(int pDistrictId) { List<City> cities = new List<City>(); const string q = "SELECT name, id FROM City WHERE district_id = @id and deleted = 0 ORDER BY name"; using (SqlConnection conn = GetConnection()) using (OpenCbsCommand c = new OpenCbsCommand(q, conn)) { c.AddParam("@id", pDistrictId); using (OpenCbsReader r = c.ExecuteReader()) { if (r != null) { while (r.Read()) { City city = new City { Name = r.GetString("name"), Id = r.GetInt("id"), DistrictId = pDistrictId }; cities.Add(city); } } } } return cities; }
public List<City> GetCities() { List<City> cities = new List<City>(); const string q = "SELECT [id], [name] ,[district_id]FROM [City] WHERE [deleted]=0 ORDER BY name "; using (SqlConnection conn = GetConnection()) using (OpenCbsCommand c = new OpenCbsCommand(q, conn)) using (OpenCbsReader r = c.ExecuteReader()) { if (r != null) { while (r.Read()) { City city = new City(); city.Id = r.GetInt("id"); city.Name = r.GetString("name"); city.DistrictId = r.GetInt("district_id"); cities.Add(city); } } } return cities; }
public void Get_Set_Name() { City city = new City { Name = "Paris" }; Assert.AreEqual("Paris", city.Name); }
public int AddCity(City city) { CheckLocation(city.Name); return _locationsManager.AddCity(city); }
public void Get_Set_ToString() { City city = new City { Name = "paris" }; Assert.AreEqual("paris", city.ToString()); }
private void buttonAdd_Click(object sender, EventArgs e) { TreeNode node = treeViewLocations.SelectedNode; try { if (node == null) { buttonAdd.Enabled = false; buttonDelete.Enabled = false; buttonUpdate.Enabled = false; return; } if (!string.IsNullOrEmpty(tbName.Text)) { var locationServices = ServicesProvider.GetInstance().GetLocationServices(); if (node.Tag == null) { // Add province int newId = locationServices.AddProvince(tbName.Text); Province p = new Province(newId, tbName.Text); TreeNode pnode = new TreeNode(tbName.Text) {Tag = p}; node.Nodes.Add(pnode); } else if ((node.Tag is Province)) { // Add district Province province = (Province) node.Tag; int newId = locationServices.AddDistrict(tbName.Text, province.Id); District d = new District(newId, tbName.Text, province); TreeNode dnode = new TreeNode(tbName.Text) {Tag = d}; node.Nodes.Add(dnode); } else if ((node.Tag is District)) { // Add city District district = (District) node.Tag; City city = new City {Name = tbName.Text, DistrictId = district.Id}; city.Id = locationServices.AddCity(city); TreeNode cnode = new TreeNode(tbName.Text) {Tag = city}; node.Nodes.Add(cnode); buttonAdd.Enabled = false; } tbName.Clear(); } } catch(Exception exception) { var exceptionStatus = CustomExceptionHandler.ShowExceptionText(exception); new frmShowError(exceptionStatus).ShowDialog(); return; } node.Expand(); treeViewLocations.Sort(); }