public override void Load() { // Provide the ISessionFactory for DI, someone will need to provide ISession with the proper scoping Kernel.Bind <NHibernate.ISessionFactory>() .ToMethod(c => SessionFactoryProvider.GetSessionFactory()) .InSingletonScope(); // Load all of the NHibernate based repositories into the kernel Kernel.Bind <IEntityRepository <Product> >().To <NHibernateProductsRepository>(); }
public void Persistence_test_passes_for_a_correctly_mapped_entity(SampleEntity entity, SessionFactoryProvider factoryProvider, SchemaCreator schemaCreator) { var factory = factoryProvider.GetSessionFactory(); var result = TestPersistence.UsingSessionFactory(factory) .WithSetup(s => { schemaCreator.CreateSchema(s.Connection); }) .WithEntity(entity) .WithEqualityRule(r => r.ForAllOtherProperties()); Assert.That(() => { Assert.That(result, Persisted.Successfully()); }, Throws.Nothing); }
public void Persistence_test_fails_for_an_entity_which_cannot_be_saved(EntityWithBadlyNamedProperty entity, SessionFactoryProvider factoryProvider, SchemaCreator schemaCreator) { var factory = factoryProvider.GetSessionFactory(); var result = TestPersistence.UsingSessionFactory(factory) .WithSetup(s => { schemaCreator.CreateSchema(s.Connection); }) .WithEntity(entity) .WithEqualityRule(r => r.ForAllOtherProperties()); Assert.That(() => { Assert.That(result, Persisted.Successfully()); }, Throws.InstanceOf <AssertionException>()); Assert.That(result?.SaveException, Is.Not.Null); }
public void Persistence_test_fails_for_an_incorrectly_mapped_entity(EntityWithUnmappedProperty entity, SessionFactoryProvider factoryProvider, SchemaCreator schemaCreator) { var factory = factoryProvider.GetSessionFactory(); var result = TestPersistence.UsingSessionFactory(factory) .WithSetup(s => { schemaCreator.CreateSchema(s.Connection); }) .WithEntity(entity) .WithEqualityRule(r => r.ForAllOtherProperties()); Assert.That(() => { Assert.That(result, Persisted.Successfully()); }, Throws.InstanceOf <AssertionException>()); Assert.That(result?.EqualityResult?.RuleResults?.Where(x => !x.Passed).Count(), Is.EqualTo(1)); }
public void Persistence_test_fails_when_the_setup_throws_an_exception(SampleEntity entity, SessionFactoryProvider factoryProvider, SchemaCreator schemaCreator) { var factory = factoryProvider.GetSessionFactory(); var result = TestPersistence.UsingSessionFactory(factory) .WithSetup(s => { schemaCreator.CreateSchema(s.Connection); throw new InvalidOperationException("Sample exception"); }) .WithEntity(entity) .WithEqualityRule(r => r.ForAllOtherProperties()); Assert.That(() => { Assert.That(result, Persisted.Successfully()); }, Throws.InstanceOf <AssertionException>()); Assert.That(result?.SetupException, Is.Not.Null); }