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(); } } }
public void DisposeWhenClosesContext() { var db = MemoryDBForTests.NewDB(); CurrentContext.NewContext(NewContext(db)); CurrentContext.CloseContext(); Assert.IsTrue(db.Ext().IsClosed()); }
public void CanSetContext() { var context = NewContext(); CurrentContext.NewContext(context); Assert.AreEqual(context, CurrentContext.GetCurrentContext()); CurrentContext.CloseContext(); }
public void DirectStore() { var context = NewContext(); CurrentContext.NewContext(context); CurrentContext.Store(new ClassWithIndexedFields()); Assert.AreEqual(1, CurrentContext.Query <ClassWithIndexedFields>().Count()); CurrentContext.CloseContext(); }
public void IsThreadLocal() { var task = new Task(() => CurrentContext.NewContext(NewContext())); task.Start(); task.Wait(); Assert.Throws(typeof(InvalidOperationException), () => CurrentContext.GetCurrentContext()); CurrentContext.CloseContext(); }
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(); }
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(); } }
public void ClosesContext() { CurrentContext.NewContext(NewContext()); CurrentContext.CloseContext(); Assert.Throws(typeof(InvalidOperationException), () => CurrentContext.GetCurrentContext()); }