Exemplo n.º 1
0
        public void TestDataDelete()
        {
            using (var context = new InsuranceDataContext())
            {
                var repository = new InsuranceRepository(context);

                var originalCount = repository.GetItems<t00002_event_loss_footprint>().Count();
                var record = repository.GetItems<t00002_event_loss_footprint>().FirstOrDefault();

                Assert.IsNotNull(record);

                repository.DeleteItem<t00002_event_loss_footprint>(record.id);
                repository.Save();

                var newCount = repository.GetItems<t00002_event_loss_footprint>().Count();

                Assert.AreEqual(originalCount - 1, newCount);
            }
        }
Exemplo 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);
            }
        }