public void DelegatesToNativeLoader() { var typeName = TypeName.Create("System.String", "mscorlib"); var type = TypeLoader.Create(new string[0])(typeName); Assert.AreEqual(typeof(string), type.Value); }
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 LoadsFromAssemblies() { var found = TypeLoader.Create(new[] { @"..\..\Gamlor.Db4oPad.ExternalAssemblyForTests.dll" }) (TypeNameParser.ParseString("Gamlor.Db4oPad.ExternalAssemblyForTests.AType, Gamlor.Db4oPad.ExternalAssemblyForTests")); Assert.IsNotNull(found.Value); }
public void ReturnsEmptyResultOnUnknownType() { var typeName = TypeName.Create("DoesNotExist.ClassName", "DoesNotExist"); var type = TypeLoader.Create(new string[0])(typeName); Assert.IsFalse(type.HasValue); }
public void CanLoadGenericTypeDefinition() { var genericArgument = TypeName.Create("DoesNotExist.ClassName", "DoesNotExist"); var listName = TypeName.Create("System.Collections.Generic.List`1", "mscorlib", new[] { genericArgument }); var type = TypeLoader.Create(new string[0])(listName.GetGenericTypeDefinition()); Assert.AreEqual(typeof(List <>), type.Value); }
public void LoadMixedGenericType() { var genericArgument = TypeName.Create("DoesNotExist.ClassName", "DoesNotExist"); var listName = TypeName.Create("System.Collections.Generic.List", "mscorlib", new[] { genericArgument }); var found = TypeLoader.Create(new[] { @"..\..\Gamlor.Db4oPad.ExternalAssemblyForTests.dll" })(listName); Assert.IsFalse(found.HasValue); }
public void LoadGenericType() { var found = TypeLoader.Create(new[] { @"..\..\Gamlor.Db4oPad.ExternalAssemblyForTests.dll" }) (TypeNameParser.ParseString("Gamlor.Db4oPad.ExternalAssemblyForTests.AGeneric`1[[System.Int32, mscorlib]], Gamlor.Db4oPad.ExternalAssemblyForTests")); Assert.IsTrue(found.HasValue); Assert.IsNotNull(found.Value.GetConstructors().Single().Invoke(new object[0])); }
public void GetsGenericTypeFromCurrentAssembly() { var dynamicType = new [] { TestMetaData.CreateGenericType() }; var dynamicAssembly = CodeGenerator.Create(dynamicType, TestUtils.NewName()); var typeToFind = dynamicAssembly.Types[dynamicType.Single(t => t.IsBusinessEntity)]; var found = TypeLoader.Create(new string[0])(TypeNameParser.ParseString(ReflectPlatform.FullyQualifiedName(typeToFind))); Assert.AreEqual(typeToFind, found.Value); }
private void RunTestWith(string dbName, Action <IEnumerable <ITypeDescription> > context) { TestUtils.CopyTestDB(dbName); using (var ctx = Db4oEmbedded.OpenFile(dbName)) { var metaData = MetaDataReader.Read(ctx, TypeLoader.Create(new string[0])); context(metaData); } }
public void HasWrittenAssembly() { var name = TestUtils.NewName(); name.CodeBase = Path.GetTempFileName(); var context = DatabaseContext.Create(DB, name, TypeLoader.Create(new string[0])); Assert.IsTrue(File.Exists(name.CodeBase)); Assert.IsTrue(new FileInfo(name.CodeBase).Length > 0); }
public void LoadsFromAssembly() { CopyTestDB(); using (var db = Db4oEmbedded.OpenFile(DataBaseFile)) { var ctx = DatabaseContext.Create(db, TestUtils.NewName(), TypeLoader.Create(new[] { @"..\..\Gamlor.Db4oPad.ExternalAssemblyForTests.dll" })); var type = ctx.MetaInfo.EntityTypes.Single(t => t.TypeName.NameAndNamespace == "Gamlor.Db4oPad.ExternalAssemblyForTests.AType"); Assert.IsTrue(type.TryResolveType(TestUtils.FindNothingTypeResolver).HasValue); } }
public void WorksWithArrayTypes() { DB.Store(new SystemTypeArrays()); var name = TestUtils.NewName(); name.CodeBase = Path.GetTempFileName(); var context = DatabaseContext.Create(DB, name, TypeLoader.Create(new string[0])); var type = context.MetaInfo .DyanmicTypesRepresentation .First(c => c.Key.Name.Equals(typeof(SystemTypeArrays).Name)); Assert.NotNull(type); }
private static Tuple <DatabaseConfigurator, DatabaseMetaInfo> GetConfig(string dbName) { var cfg = Db4oEmbedded.NewConfiguration(); cfg.File.ReadOnly = true; using (var metaInfoDB = Db4oEmbedded.OpenFile(cfg, dbName)) { var name = TestUtils.NewName(); var meta = DatabaseMetaInfo.Create(metaInfoDB, TypeLoader.Create(new string[0]), name); var config = DatabaseConfigurator.Create(meta); return(Tuple.Create(config, meta)); } }
public void CanOpenCarExample() { TestUtils.CopyTestDB(CarDatabase); var name = TestUtils.NewName(); DatabaseMetaInfo meta = null; using ( var ctx = DatabaseContext.Create(Db4oEmbedded.OpenFile(CarDatabase), name, TypeLoader.Create(new string[0]))) { meta = ctx.MetaInfo; Assert.NotNull(meta); } using (var ctx = DatabaseContext.Create(Db4oEmbedded.OpenFile(CarDatabase), meta)) { var meta2 = ctx.MetaInfo; Assert.NotNull(meta2); } }
public void DontCrashOnNonExistingFile() { var found = TypeLoader.Create(new[] { Path.GetRandomFileName() })(TypeName.Create("DoesNotExist.ClassName", "DoesNotExist")); Assert.IsFalse(found.HasValue); }
public void DontCrashOnBogusAssemblies() { var found = TypeLoader.Create(new[] { Path.GetTempFileName() })(TypeName.Create("DoesNotExist.ClassName", "DoesNotExist")); Assert.IsFalse(found.HasValue); }
private static TypeResolver CreateTypeLoader(IConnectionInfo cxInfo) { var assemblyProvider = UserAssembliesProvider.CreateForCurrentAssemblyContext(cxInfo.CustomTypeInfo.CustomAssemblyPath); return(TypeLoader.Create(assemblyProvider.GetAssemblies())); }