public void CanDealWithGenerics()
        {
            var containerStorage = MultiContainerMemoryDB.Create();

            using (var container = containerStorage.NewDB())
            {
                container.Store(new WithGenericDictionary());
            }
            using (var container = containerStorage.NewDB(c => { c.File.ReadOnly = true; }))
            {
                var ctx = DatabaseContext.Create(container, TestUtils.NewName(),
                                                 TypeLoader.Create(new string[0]));
                CurrentContext.NewContext(ctx);
                try
                {
                    var queryContext = (IQueryable <WithGenericDictionary>)ctx.MetaInfo.DataContext.
                                       GetProperty("ExampleDatabasesWithKnownTypesTests_WithGenericDictionary").GetValue(null, null);


                    Assert.AreEqual(1, queryContext.Count());
                }
                finally
                {
                    CurrentContext.CloseContext();
                }
            }
        }
示例#2
0
        public void DisposeWhenClosesContext()
        {
            var db = MemoryDBForTests.NewDB();

            CurrentContext.NewContext(NewContext(db));
            CurrentContext.CloseContext();
            Assert.IsTrue(db.Ext().IsClosed());
        }
示例#3
0
        public void CanSetContext()
        {
            var context = NewContext();

            CurrentContext.NewContext(context);
            Assert.AreEqual(context, CurrentContext.GetCurrentContext());
            CurrentContext.CloseContext();
        }
示例#4
0
        public void DirectStore()
        {
            var context = NewContext();

            CurrentContext.NewContext(context);
            CurrentContext.Store(new ClassWithIndexedFields());
            Assert.AreEqual(1, CurrentContext.Query <ClassWithIndexedFields>().Count());
            CurrentContext.CloseContext();
        }
示例#5
0
        public void IsThreadLocal()
        {
            var task = new Task(() => CurrentContext.NewContext(NewContext()));

            task.Start();
            task.Wait();
            Assert.Throws(typeof(InvalidOperationException), () => CurrentContext.GetCurrentContext());
            CurrentContext.CloseContext();
        }
示例#6
0
        public void DirectQuery()
        {
            var db = MemoryDBForTests.NewDB();

            db.Store(new ClassWithFields());
            CurrentContext.NewContext(NewContext(db));
            var query = CurrentContext.Query <ClassWithFields>();

            Assert.AreNotEqual(0, query.Count());
            CurrentContext.CloseContext();
        }
示例#7
0
        private void RunTestWith(string dbName, Action <DatabaseContext> context)
        {
            TestUtils.CopyTestDB(dbName);
            var metaInfo = GetConfig(dbName);
            var cfg      = Db4oEmbedded.NewConfiguration();

            cfg.File.ReadOnly = true;
            metaInfo.Item1.Configure(cfg);
            var ctx = DatabaseContext.Create(Db4oEmbedded.OpenFile(cfg, dbName), metaInfo.Item2);

            CurrentContext.NewContext(ctx);
            try
            {
                context(ctx);
            }
            finally
            {
                CurrentContext.CloseContext();
            }
        }
示例#8
0
 public void ClosesContext()
 {
     CurrentContext.NewContext(NewContext());
     CurrentContext.CloseContext();
     Assert.Throws(typeof(InvalidOperationException), () => CurrentContext.GetCurrentContext());
 }