Esempio n. 1
0
        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();
                }
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public void ReturnsEmptyResultOnUnknownType()
        {
            var typeName = TypeName.Create("DoesNotExist.ClassName", "DoesNotExist");
            var type     = TypeLoader.Create(new string[0])(typeName);

            Assert.IsFalse(type.HasValue);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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]));
        }
Esempio n. 8
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);
     }
 }
Esempio n. 10
0
        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);
        }
Esempio n. 11
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);
     }
 }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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));
            }
        }
Esempio n. 14
0
        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);
            }
        }
Esempio n. 15
0
        public void DontCrashOnNonExistingFile()
        {
            var found = TypeLoader.Create(new[] { Path.GetRandomFileName() })(TypeName.Create("DoesNotExist.ClassName", "DoesNotExist"));

            Assert.IsFalse(found.HasValue);
        }
Esempio n. 16
0
        public void DontCrashOnBogusAssemblies()
        {
            var found = TypeLoader.Create(new[] { Path.GetTempFileName() })(TypeName.Create("DoesNotExist.ClassName", "DoesNotExist"));

            Assert.IsFalse(found.HasValue);
        }
Esempio n. 17
0
        private static TypeResolver CreateTypeLoader(IConnectionInfo cxInfo)
        {
            var assemblyProvider = UserAssembliesProvider.CreateForCurrentAssemblyContext(cxInfo.CustomTypeInfo.CustomAssemblyPath);

            return(TypeLoader.Create(assemblyProvider.GetAssemblies()));
        }