Exemple #1
0
        public async Task SetUp()
        {
            var cfg = new Configuration()
                      .DataBaseIntegration(x =>
            {
                x.Dialect <MsSql2012Dialect>();
                x.ConnectionString = Consts.SqlConnectionString;
            });

            var metaModel = new SagaMetadataCollection();

            metaModel.Initialize(SagaTypes);

            var sagaDataTypes = new List <Type>();

            using (var enumerator = metaModel.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    sagaDataTypes.Add(enumerator.Current.SagaEntityType);
                }
            }

            sagaDataTypes.Add(typeof(ContainSagaData));

            SagaModelMapper.AddMappings(cfg, metaModel, sagaDataTypes);
            SessionFactory = cfg.BuildSessionFactory();

            schema = new SchemaExport(cfg);
            await schema.CreateAsync(false, true);

            SagaPersister = new SagaPersister();
        }
Exemple #2
0
        public async Task ShouldVerifySameTableTurkishAsync()
        {
            //NH-3063

            // Turkish have unusual casing rules for the letter 'i'. This test verifies that
            // code paths executed by the SchemaValidator correctly handles case insensitive
            // comparisons for this.

            // Just make sure that we have an int property in the mapped class. This is
            // the 'i' we rely on for the test.
            var v = new Version();

            Assert.That(v.Id, Is.TypeOf <int>());

            var cfg = BuildConfiguration(_version1Resource);

            var export = new SchemaExport(cfg);

            await(export.CreateAsync(true, true));
            try
            {
                var validator = new Tool.hbm2ddl.SchemaValidator(cfg);
                await(validator.ValidateAsync());
            }
            finally
            {
                await(export.DropAsync(true, true));
            }
        }
        public async Task SchemaExport_Export_CreatesExportScriptAsync()
        {
            Configuration configuration = GetConfiguration();
            SchemaExport  export        = new SchemaExport(configuration);
            TextWriter    tw            = new StringWriter();

            await(export.CreateAsync(tw, false));
            string s = tw.ToString();

            var dialect = Dialect.Dialect.GetDialect(configuration.Properties);

            if (dialect.SupportsIfExistsBeforeTableName)
            {
                Assert.IsTrue(s.Contains("drop table if exists Home_Drop"));
                Assert.IsTrue(s.Contains("drop table if exists Home_All"));
            }
            else
            {
                Assert.IsTrue(s.Contains("drop table Home_Drop"));
                Assert.IsTrue(s.Contains("drop table Home_All"));
            }

            Assert.IsTrue(s.Contains("create table Home_All"));
            Assert.IsTrue(s.Contains("create table Home_Export"));
        }
Exemple #4
0
        async Task <Configuration> CreateTimeoutManagerObjects()
        {
            var configuration = new Configuration()
                                .DataBaseIntegration(x =>
            {
                x.Dialect <MsSql2012Dialect>();
                x.ConnectionString = Consts.SqlConnectionString;
            });

            if (dbSchemaName != null)
            {
                await CreateDbSchema();

                configuration.SetProperty(Environment.DefaultSchema, dbSchemaNeedsQuoting ? $"[{dbSchemaName}]" : dbSchemaName);
            }

            var mapper = new ModelMapper();

            mapper.AddMapping <TimeoutEntityMap>();

            configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());

            schemaExport = new SchemaExport(configuration);
            await schemaExport.CreateAsync(false, true);

            return(configuration);
        }
Exemple #5
0
        public async Task CompileMappingForDynamicInMemoryAssemblyAsync()
        {
            const int assemblyGenerateCount = 10;
            var       code     = GenerateCode(assemblyGenerateCount);
            var       assembly = CompileAssembly(code);

            var config = TestConfigurationHelper.GetDefaultConfiguration();
            var mapper = new ModelMapper();

            mapper.AddMappings(assembly.GetExportedTypes());
            config.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());

            Assert.That(config.ClassMappings, Has.Count.EqualTo(assemblyGenerateCount), "Not all virtual assembly mapped");

            // Ascertain the mappings are usable.
            using (var sf = config.BuildSessionFactory())
            {
                var se = new SchemaExport(config);
                await(se.CreateAsync(false, true));
                try
                {
                    using (var s = sf.OpenSession())
                        using (var tx = s.BeginTransaction())
                        {
                            foreach (var entityClass in assembly.GetExportedTypes()
                                     .Where(t => !typeof(IConformistHoldersProvider).IsAssignableFrom(t)))
                            {
                                var ctor = entityClass.GetConstructor(Array.Empty <System.Type>());
                                Assert.That(ctor, Is.Not.Null, $"Default constructor for {entityClass} not found");
                                var entity = ctor.Invoke(Array.Empty <object>());
                                await(s.SaveAsync(entity));
                            }

                            await(tx.CommitAsync());
                        }

                    using (var s = sf.OpenSession())
                        using (var tx = s.BeginTransaction())
                        {
                            var entities = await(s.CreateQuery("from System.Object").ListAsync <object>());
                            Assert.That(entities, Has.Count.EqualTo(assemblyGenerateCount), "Not all expected entities were persisted");

                            await(tx.CommitAsync());
                        }
                }
                finally
                {
                    TestCase.DropSchema(false, se, (ISessionFactoryImplementor)sf);
                }
            }
        }
Exemple #6
0
        public async Task <ApiData> Create()
        {
            if (_env.IsDevelopment() == false)
            {
                throw new InvalidOperationException("只能在开发环境运行此工具");
            }
            _logger.Warning("正在导出数据库架构,当前是开发环境,所有表结构将重建");
            SchemaExport export = new SchemaExport(_nhConfiguration);
            await export.CreateAsync(true, true);

            _logger.Information("已导出数据库架构");

            return(this.Success());
        }
Exemple #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);
        }
        public async Task SetupContext()
        {
            var cfg = new Configuration()
                      .DataBaseIntegration(x =>
            {
                x.Dialect <MsSql2012Dialect>();
                x.ConnectionString = Consts.SqlConnectionString;
            });

            var mapper = new ModelMapper();

            mapper.AddMapping <TestEntity.Mapping>();
            cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());

            schema = new SchemaExport(cfg);
            await schema.CreateAsync(false, true);

            SessionFactory = cfg.BuildSessionFactory();
        }
Exemple #9
0
        public async Task Setup()
        {
            var mapper = new ModelMapper();

            mapper.AddMapping(typeof(TMapping));

            var cfg = new Configuration()
                      .DataBaseIntegration(x =>
            {
                x.Dialect <MsSql2012Dialect>();
                x.ConnectionString = Consts.SqlConnectionString;
            });

            cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());

            schema = new SchemaExport(cfg);
            await schema.CreateAsync(false, true);

            sessionFactory = cfg.BuildSessionFactory();

            persister = new OutboxPersister <TEntity>(sessionFactory, "TestEndpoint");
        }
Exemple #10
0
        public async Task Setup()
        {
            var cfg = new Configuration()
                      .DataBaseIntegration(x =>
            {
                x.Dialect <MsSql2012Dialect>();
                x.ConnectionString = Consts.SqlConnectionString;
            });

            var mapper = new ModelMapper();

            mapper.AddMapping <TimeoutEntityMap>();

            cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());

            schema = new SchemaExport(cfg);
            await schema.CreateAsync(false, true);

            sessionFactory = cfg.BuildSessionFactory();

            persister = new TimeoutPersister("MyTestEndpoint", sessionFactory, new NHibernateSynchronizedStorageAdapter(sessionFactory), new NHibernateSynchronizedStorage(sessionFactory), TimeSpan.FromMinutes(2));
        }
        public DatabaseFixture()
        {
            var databaseFileName = $"InstaLikeTestDb-{Guid.NewGuid()}.sqlite";

            SessionFactory = Fluently.Configure()
                             .Database(
                SQLiteConfiguration.Standard
                .ConnectionString(BuildTestDatabaseConnectionString(databaseFileName))
                .AdoNetBatchSize(20)
                .ShowSql()
                .FormatSql()
                .UseReflectionOptimizer()
                )
                             .Mappings(m =>
                                       m.FluentMappings
                                       .Conventions.Add(
                                           DefaultLazy.Always(),
                                           DynamicInsert.AlwaysTrue(),
                                           DynamicUpdate.AlwaysTrue(),
                                           new AssociationsMappingConvention(),
                                           new DateTimeOffsetTypeConvention()
                                           )
                                       .Add <UserMapping>()
                                       .Add <FollowMapping>()
                                       .Add <PostMapping>()
                                       .Add <CommentMapping>()
                                       .Add <LikeMapping>()
                                       .Add <NotificationMapping>()
                                       )
                             .ExposeConfiguration(async cfg =>
            {
                var schemaExport = new SchemaExport(cfg);
                schemaExport.SetOutputFile($"{databaseFileName}_Schema.sql");
                await schemaExport.DropAsync(true, true);
                await schemaExport.CreateAsync(true, true);
            })
                             .BuildSessionFactory();
        }