public void TestDataInsert() { using (var context = new InsuranceDataContext()) { var repository = new InsuranceRepository(context); var originalCount = repository.GetItems<t00001_event_set>().Count(); repository.InsertItem(new t00001_event_set { event_day = 1, event_simulation = 2, t010_id = 11 }); repository.Save(); var newCount = repository.GetItems<t00001_event_set>().Count(); Assert.AreEqual(originalCount + 1, newCount); } }
public void TestDataUpdate() { using (var context = new InsuranceDataContext()) { const string originalName = "OriginalName"; const string originalCode = "OC"; const string updatedName = "UpdatedName"; const string updatedCode = "UC"; var repository = new InsuranceRepository(context); var originalCount = repository.GetItems<t030_geo_region>().Count(); var parent = repository.GetItems<t030_geo_region>().FirstOrDefault(); Assert.IsNotNull(parent); var region = new t030_geo_region { t030_name = originalName, t030_code = originalCode, t030_parent_id = parent.t030_id, t030_level_no = parent.t030_level_no + 1 }; repository.InsertItem(region); repository.Save(); var newCount = repository.GetItems<t030_geo_region>().Count(); Assert.AreEqual(originalCount + 1, newCount); var item = repository.GetItems<t030_geo_region>().FirstOrDefault(g => g.t030_name == originalName && g.t030_code == originalCode); Assert.IsNotNull(item); item.t030_name = updatedName; item.t030_code = updatedCode; repository.UpdateItem(item, item.t030_id); repository.Save(); newCount = repository.GetItems<t030_geo_region>().Count(); Assert.AreEqual(originalCount + 1, newCount); item = repository.GetItems<t030_geo_region>().FirstOrDefault(g => g.t030_name == originalName && g.t030_code == originalCode); Assert.IsNull(item); item = repository.GetItems<t030_geo_region>().FirstOrDefault(g => g.t030_name == updatedName && g.t030_code == updatedCode); Assert.IsNotNull(item); repository.DeleteItem<t030_geo_region>(item.t030_id); repository.Save(); newCount = repository.GetItems<t030_geo_region>().Count(); Assert.AreEqual(originalCount, newCount); item = repository.GetItems<t030_geo_region>().FirstOrDefault(g => g.t030_name == originalName && g.t030_code == originalCode); Assert.IsNull(item); item = repository.GetItems<t030_geo_region>().FirstOrDefault(g => g.t030_name == updatedName && g.t030_code == updatedCode); Assert.IsNull(item); } }