public void CreatingSchemaForStatedClassesInTempFile() { var types = new Types(typeof(FooRecord), typeof(BarRecord)); var fileName = "temp.sdf"; var persistenceConfigurer = new SqlCeDataServicesProvider(fileName).GetPersistenceConfigurer(true/*createDatabase*/); ((MsSqlCeConfiguration)persistenceConfigurer).ShowSql(); var sessionFactory = Fluently.Configure() .Database(persistenceConfigurer) .Mappings(m => m.AutoMappings.Add(AutoMap.Source(types))) .ExposeConfiguration(c => { // This is to work around what looks to be an issue in the NHibernate driver: // When inserting a row with IDENTITY column, the "SELET @@IDENTITY" statement // is issued as a separate command. By default, it is also issued in a separate // connection, which is not supported (returns NULL). c.SetProperty("connection.release_mode", "on_close"); new SchemaExport(c).Create(false, true); }) .BuildSessionFactory(); var session = sessionFactory.OpenSession(); session.Save(new FooRecord { Name = "Hello" }); session.Save(new BarRecord { Height = 3, Width = 4.5m }); session.Close(); session = sessionFactory.OpenSession(); var foos = session.CreateCriteria<FooRecord>().List(); Assert.That(foos.Count, Is.EqualTo(1)); Assert.That(foos, Has.All.Property("Name").EqualTo("Hello")); session.Close(); }
public void DatabaseExistsAfterConfiguration() { DeleteDatabase(); SqlCeDataServicesProvider provider = new SqlCeDataServicesProvider(CurrentDirectory, DbName) { AutomappingConfigurer = new MockAutomappingConfigurer() }; NHibernate.Cfg.Configuration cfg = provider.BuildConfiguration( new DataServiceParameters { CreateDatabase = true }); Assert.That(EnsureDatabase(), Is.True); }
public void CreatingSchemaForStatedClassesInTempFile() { var types = new Types(typeof(FooRecord), typeof(BarRecord)); var fileName = "temp.sdf"; var persistenceConfigurer = new SqlCeDataServicesProvider(fileName).GetPersistenceConfigurer(true /*createDatabase*/); // Uncomment to display SQL while running tests // ((MsSqlCeConfiguration)persistenceConfigurer).ShowSql(); var sessionFactory = Fluently.Configure() .Database(persistenceConfigurer) .Mappings(m => m.AutoMappings.Add(AutoMap.Source(types))) .ExposeConfiguration(c => { // This is to work around what looks to be an issue in the NHibernate driver: // When inserting a row with IDENTITY column, the "SELET @@IDENTITY" statement // is issued as a separate command. By default, it is also issued in a separate // connection, which is not supported (returns NULL). c.SetProperty("connection.release_mode", "on_close"); new SchemaExport(c).Create(false, true); }) .BuildSessionFactory(); var session = sessionFactory.OpenSession(); session.Save(new FooRecord { Name = "Hello" }); session.Save(new BarRecord { Height = 3, Width = 4.5m }); session.Close(); session = sessionFactory.OpenSession(); var foos = session.CreateCriteria <FooRecord>().List(); Assert.That(foos.Count, Is.EqualTo(1)); Assert.That(foos, Has.All.Property("Name").EqualTo("Hello")); session.Close(); }
public static ISessionFactory CreateSessionFactory(string fileName, params Type[] types) { //var persistenceModel = AutoMap.Source(new Types(types)) // .Alterations(alt => AddAlterations(alt, types)) // .Conventions.AddFromAssemblyOf<DataModule>(); var persistenceModel = AbstractDataServicesProvider.CreatePersistenceModel(types.Select(t => new RecordBlueprint { TableName = "Test_" + t.Name, Type = t }).ToList()); var persistenceConfigurer = new SqlCeDataServicesProvider(fileName).GetPersistenceConfigurer(true/*createDatabase*/); ((MsSqlCeConfiguration)persistenceConfigurer).ShowSql(); return Fluently.Configure() .Database(persistenceConfigurer) .Mappings(m => m.AutoMappings.Add(persistenceModel)) .ExposeConfiguration(c => { // This is to work around what looks to be an issue in the NHibernate driver: // When inserting a row with IDENTITY column, the "SELET @@IDENTITY" statement // is issued as a separate command. By default, it is also issued in a separate // connection, which is not supported (returns NULL). c.SetProperty("connection.release_mode", "on_close"); new SchemaExport(c).Create(false /*script*/, true /*export*/); }) .BuildSessionFactory(); }
public void ThrowForFileNameMissing() { SqlCeDataServicesProvider provider = new SqlCeDataServicesProvider(""); }
public void ThrowForDataFolderMissing() { SqlCeDataServicesProvider provider = new SqlCeDataServicesProvider("", "Null"); }
public void ThrowForDatabaseNameMissing() { SqlCeDataServicesProvider provider = new SqlCeDataServicesProvider("/", ""); }