コード例 #1
0
        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>();
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
        }