Esempio n. 1
0
 public GeoRegionViewModel(t030_geo_region geoRegion)
 {
     Code = geoRegion.t030_code;
     Name = geoRegion.t030_name;
     Level = geoRegion.t030_level_no;
     Parent = geoRegion.t030_parent_id;
     Children = new ObservableCollection<GeoRegionViewModel>();
     _originalObject = geoRegion;
     EditCode = Code;
     EditName = Name;
 }
Esempio n. 2
0
        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);
            }
        }