Example #1
0
        public virtual void TearDown()
        {
            var sessionFactory = NHConfigurator.SessionFactory;
            var session        = CurrentSessionContext.Unbind(sessionFactory);

            session.Close();
            TestConnectionProvider.CloseDatabase();
        }
Example #2
0
        public virtual void SetUp()
        {
            TestConnectionProvider.CloseDatabase();
            var cfg = NHConfigurator.Configuration;
            var conventionBuilder = new ConventionBuilder
            {
                DbSchemaOutputFile       = "schema.sql",
                DropTablesCreateDbSchema = true,
                OutputXmlMappingsFile    = "schema.hbm.xml",
                MappingsAssembly         = typeof(Entity).Assembly,
                ShowLogs       = true,
                FilterAssembly = t => t.IsSubclassOf(typeof(Entity)) && t.Namespace.EndsWith("Domain"),
                Conventions    = new List <IAmConvention> {
                    new VersionConvention(),
                    new BidirectionalManyToManyRelationsConvention
                    {
                        BaseEntityType = typeof(Entity),
                        TypeFilter     = p => p.Namespace.EndsWith("Domain")
                    },
                    new BidirectionalOneToManyConvention
                    {
                        BaseEntityType = typeof(Entity),
                        TypeFilter     = p => p.Namespace.EndsWith("Domain")
                    },
                    new DefineBaseClassConvention
                    {
                        BaseEntityToIgnore = typeof(Entity)
                    },
                    new EnumConvention(),
                    new NamingConvention(),
                    new UnidirectionalManyToOne
                    {
                        BaseEntityType = typeof(Entity),
                        TypeFilter     = p => p.Namespace.EndsWith("Domain")
                    },
                    new UnidirectionalOneToManyConvention
                    {
                        BaseEntityType = typeof(Entity),
                        TypeFilter     = p => p.Namespace.EndsWith("Domain")
                    }
                }
            };

            conventionBuilder.ProcessConfiguration(cfg);
            var session = SessionFactory.OpenSession();

            CurrentSessionContext.Bind(session);
            //var schemaExport = new SchemaExport(cfg);
            //schemaExport.Create(false, true);
        }