Пример #1
0
        public void SingleRelationshipSavesAndDeletes()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var seed = new Seed32();
            List<MockClassE> objs = null;
            var ids = new List<int>();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new RelationalDatabase<int, MockClassD>(_testName + ".database", "Id"))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        objs = TestResourceFactory.GetMockClassDObjects(3, db).ToList();

                        objs.ToList().ForEach(o => o.Id = db.Add(o));

                        t.Commit();
                    }
                }

                using (var db = new RelationalDatabase<int, MockClassD>(_testName + ".database"))
                {
                    db.Load();

                    var first = db.Fetch(objs[0].Id);

                    using (var t = db.BeginTransaction())
                    {
                        first.LowBall = new List<MockClassD>();

                        db.Update(first, first.Id);

                        t.Commit();
                    }

                    first = db.Fetch(objs[0].Id);

                    Assert.AreEqual(0, first.LowBall.Count());
                }

                using (var db = new RelationalDatabase<int, MockClassD>(_testName + ".database"))
                {
                    db.Load();

                    var first = db.Fetch(objs.First().Id);

                    Assert.AreEqual(0, first.LowBall.Count());
                }
            }
        }
Пример #2
0
        public void SingleRelationshipSaves()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var seed = new Seed32();
            IList<MockClassE> objs = null;
            var ids = new List<int>();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new RelationalDatabase<int, MockClassD>(_testName + ".database", "Id"))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        objs = TestResourceFactory.GetMockClassDObjects(3, db).ToList();

                        objs.ToList().ForEach(o => o.Id = db.Add(o));

                        t.Commit();
                    }
                }

                using (var db = new RelationalDatabase<int, MockClassD>(_testName + ".database"))
                {
                    db.Load();

                    foreach (var obj in objs)
                    {
                        var orig = obj as MockClassE;
                        var item = db.Fetch(obj.Id) as MockClassE;

                        AssertMockClassE(item, orig, db);
                    }
                }
            }
        }
Пример #3
0
        public void SingleRelationshipSavesAndSelects()
        {
            _testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();

            var seed = new Seed32();
            List<MockClassE> objs = null;
            var ids = new List<int>();

            using (var fLock = new ManagedFileLock(_testName))
            {
                Cleanup();

                using (var db = new RelationalDatabase<int, MockClassD>(_testName + ".database", "Id"))
                {
                    db.Load();

                    using (var t = db.BeginTransaction())
                    {
                        objs = TestResourceFactory.GetMockClassDObjects(3, db).ToList();

                        objs.ToList().ForEach(o => o.Id = db.Add(o));

                        t.Commit();
                    }
                }

                using (var db = new RelationalDatabase<int, MockClassD>(_testName + ".database"))
                {
                    db.Load();

                    var first = db.SelectFirst(s => s.Value<int>("Id") > 0, 50);

                    foreach (var obj in objs)
                        AssertMockClassE((MockClassE)first.First(f => f.Id == obj.Id), obj as MockClassE, db);

                    var last = db.SelectLast(s => s.Value<int>("Id") > 0, 50);

                    foreach (var obj in objs)
                        AssertMockClassE((MockClassE)last.First(f => f.Id == obj.Id), obj as MockClassE, db);
                }
            }
        }