示例#1
0
        public void CompiledMappings_ShouldNotDependOnAddedOrdering_AddedBy_AddMapping()
        {
            var mapper = new ModelMapper();

            mapper.AddMapping <AMapping>();
            mapper.AddMapping <BMapping>();
            mapper.AddMapping <CMapping>();
            mapper.AddMapping <DMapping>();
            mapper.AddMapping <EMapping>();
            mapper.AddMapping <FMapping>();
            mapper.AddMapping <GMapping>();
            var config = TestConfigurationHelper.GetDefaultConfiguration();

            Assert.DoesNotThrow(() => config.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()));
        }
示例#2
0
        public void CompiledMappings_ShouldNotDependOnAddedOrdering_AddedBy_AddMappings()
        {
            var mappings =
                typeof(MappingByCodeTest)
                .Assembly
                .GetExportedTypes()
                //only add our test entities/mappings
                .Where(t => t.Namespace == typeof(MappingByCodeTest).Namespace && t.Name.EndsWith("Mapping"));
            var mapper = new ModelMapper();

            mapper.AddMappings(mappings);
            var config = TestConfigurationHelper.GetDefaultConfiguration();

            Assert.DoesNotThrow(() => config.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()));
        }
示例#3
0
        public void WhenMapEmptyEnumThenDoesNotThrowExplicitException()
        {
            var mapper = new ModelMapper();

            mapper.Class <MyClass>(rc =>
            {
                rc.Id(x => x.Id);
                rc.Property(x => x.MyEmptyEnum);
            });
            var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
            var conf     = TestConfigurationHelper.GetDefaultConfiguration();

            conf.AddMapping(mappings);
            Assert.That(() => conf.BuildSessionFactory(), Throws.Nothing);
        }
示例#4
0
        public async Task DefaultAsync()
        {
            Configuration cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.AddResource("NHibernate.DomainModel.Simple.hbm.xml", typeof(Simple).Assembly);
            cfg.SetProperty(Environment.Hbm2ddlAuto, "create-drop");
            ISessionFactory sf = cfg.BuildSessionFactory();

            using (ISession s = sf.OpenSession())
            {
                object count = await(s.CreateQuery("select count(*) from Simple").UniqueResultAsync());
                Assert.IsTrue(count is Int64);
            }
            await(sf.CloseAsync());
        }
示例#5
0
        public void GetTypeCastName()
        {
            var cfg = TestConfigurationHelper.GetDefaultConfiguration();

            cfg.SetProperty(Environment.QueryDefaultCastLength, "20");
            cfg.SetProperty(Environment.QueryDefaultCastPrecision, "10");
            cfg.SetProperty(Environment.QueryDefaultCastScale, "3");
            var dialect = Dialect.Dialect.GetDialect(cfg.Properties);

            // Those regex test wether the type is qualified with expected length/precision/scale or not qualified at all.
            Assert.That(dialect.GetCastTypeName(SqlTypeFactory.Decimal), Does.Match(@"^[^(]*(\(\s*10\s*,\s*3\s*\))?\s*$"), "decimal");
            Assert.That(dialect.GetCastTypeName(SqlTypeFactory.GetSqlType(DbType.Decimal, 12, 4)), Does.Match(@"^[^(]*(\(\s*12\s*,\s*4\s*\))?\s*$"), "decimal(12,4)");
            Assert.That(dialect.GetCastTypeName(new SqlType(DbType.String)), Does.Match(@"^[^(]*(\(\s*20\s*\))?\s*$"), "string");
            Assert.That(dialect.GetCastTypeName(SqlTypeFactory.GetString(25)), Does.Match(@"^[^(]*(\(\s*25\s*\))?\s*$"), "string(25)");
        }
示例#6
0
        public void ThrowsIfConfigurationSectionNotFound()
        {
            var ex = Assert.Throws <InvalidOperationException>(
                () => new RepositoryOptionsBuilder()
                .UseConfiguration("empty_repository.config"));

            Assert.Equal("Unable to find a 'repository' configuration section. For more information on DotNetToolkit.Repository configuration, visit the https://github.com/johelvisguzman/DotNetToolkit.Repository/wiki/Config-File-Setup.", ex.Message);

#if NETSTANDARD
            ex = Assert.Throws <InvalidOperationException>(
                () => new RepositoryOptionsBuilder()
                .UseConfiguration(TestConfigurationHelper.GetConfiguration("empty_repository.json")));

            Assert.Equal("Unable to find a 'repository' configuration section. For more information on DotNetToolkit.Repository configuration, visit the https://github.com/johelvisguzman/DotNetToolkit.Repository/wiki/Config-File-Setup.", ex.Message);
#endif
        }
示例#7
0
        public async Task ExportToFileUsingSetOutputFileAndCreateAsync()
        {
            var configuration = TestConfigurationHelper.GetDefaultConfiguration();

            configuration.AddResource("NHibernate.Test.Tools.hbm2ddl.SchemaMetadataUpdaterTest.HeavyEntity.hbm.xml",
                                      GetType().Assembly);

            var outputFileName = Path.GetTempFileName();
            var export         = new SchemaExport(configuration);

            export.SetOutputFile(outputFileName);

            await(export.CreateAsync(false, false));

            Assert.IsTrue(File.Exists(outputFileName));
            Assert.IsTrue(new FileInfo(outputFileName).Length > 0);
        }