Example #1
0
        public void Configure_with_addparameters()
        {
            var nhConfig = ConfigurationExtensions.GetNhConfig();
            var mapper   = new MReadOnlyMappingManager();

            mapper.getRegisteredTypes += () => new[] { typeof(Entity) };
            var solr = new MSolrOperations <Entity>();

            var provider = new MServiceProvider();

            provider.getService += MServiceLocator.Table(new Dictionary <System.Type, object> {
                { typeof(IReadOnlyMappingManager), mapper },
                { typeof(ISolrOperations <Entity>), solr },
            });

            var addParameters = new AddParameters {
                CommitWithin = 4343
            };
            var helper = new CfgHelper(provider);

            helper.Configure(nhConfig, true, addParameters);
            var listener = nhConfig.EventListeners.PostInsertEventListeners[0];

            Assert.IsType <SolrNetListener <Entity> >(listener);
            Assert.Equal(addParameters, ((IListenerSettings)listener).AddParameters);
        }
Example #2
0
        public void Configure_from_servicelocator()
        {
            var mapper = new MReadOnlyMappingManager();

            mapper.getRegisteredTypes += () => new[] { typeof(Entity) };

            var serviceLocator = new MServiceLocator();

            serviceLocator.getInstance += MServiceLocator.One <IReadOnlyMappingManager>(mapper);

            var solr = new MSolrOperations <Entity>();

            serviceLocator.getService += MServiceLocator.One <ISolrOperations <Entity> >(solr);
            ServiceLocator.SetLocatorProvider(() => serviceLocator);
            var nhConfig = ConfigurationExtensions.GetNhConfig();
            var helper   = new CfgHelper();

            helper.Configure(nhConfig, true);
            Assert.True(nhConfig.EventListeners.PostInsertEventListeners.Length > 0);
            Assert.True(nhConfig.EventListeners.PostUpdateEventListeners.Length > 0);
            Assert.True(nhConfig.EventListeners.PostDeleteEventListeners.Length > 0);
            var listener = nhConfig.EventListeners.PostInsertEventListeners[0];

            Assert.IsType <SolrNetListener <Entity> >(listener);
        }
Example #3
0
        public void Configure_from_serviceprovider()
        {
            var nhConfig = ConfigurationExtensions.GetNhConfig();

            var provider = new MServiceProvider();
            var mapper   = new MReadOnlyMappingManager();

            mapper.getRegisteredTypes += () => new[] { typeof(Entity) };

            var solr = new MSolrOperations <Entity>();

            provider.getService += MServiceLocator.Table(new Dictionary <System.Type, object> {
                { typeof(IReadOnlyMappingManager), mapper },
                { typeof(ISolrOperations <Entity>), solr },
            });
            var helper = new CfgHelper(provider);

            helper.Configure(nhConfig, true);
            Assert.True(nhConfig.EventListeners.PostInsertEventListeners.Length > 0);
            Assert.True(nhConfig.EventListeners.PostUpdateEventListeners.Length > 0);
            Assert.True(nhConfig.EventListeners.PostDeleteEventListeners.Length > 0);
            var listener = nhConfig.EventListeners.PostInsertEventListeners[0];

            Assert.IsType <SolrNetListener <Entity> >(listener);
        }
Example #4
0
        public void Does_not_override_existing_listeners()
        {
            var nhConfig = ConfigurationExtensions.GetNhConfig();

            var mockListener = new MPostInsertEventListener();

            nhConfig.SetListener(ListenerType.PostInsert, mockListener);

            var mapper = new MReadOnlyMappingManager();

            mapper.getRegisteredTypes += () => new[] { typeof(Entity) };

            var solr = new MSolrOperations <Entity>();

            var provider = new MServiceProvider();

            provider.getService += MServiceLocator.Table(new Dictionary <System.Type, object> {
                { typeof(IReadOnlyMappingManager), mapper },
                { typeof(ISolrOperations <Entity>), solr },
            });

            var helper = new CfgHelper(provider);

            helper.Configure(nhConfig, true);
            Assert.Equal(2, nhConfig.EventListeners.PostInsertEventListeners.Length);
        }
Example #5
0
        public void FixtureSetup()
        {
            var nhConfig = ConfigurationExtensions.GetNhConfig();

            mockSolr = MockRepository.GenerateMock <ISolrOperations <Entity> >();
            var provider = MockRepository.GenerateMock <IServiceProvider>();
            var mapper   = MockRepository.GenerateMock <IReadOnlyMappingManager>();

            provider.Expect(x => x.GetService(typeof(IReadOnlyMappingManager))).Return(mapper);
            NHHelper.SetListener(nhConfig, GetSolrNetListener(mockSolr));
            new SchemaExport(nhConfig).Execute(false, true, false);
            sessionFactory = nhConfig.BuildSessionFactory();
        }
Example #6
0
        public void FixtureSetup()
        {
            var nhConfig = ConfigurationExtensions.GetNhConfig();

            mockSolr = new MSolrOperations <Entity>();
            var mapper   = new MReadOnlyMappingManager();
            var provider = new MServiceProvider();

            provider.getService += t => {
                if (t == typeof(IReadOnlyMappingManager))
                {
                    return(mapper);
                }
                throw new ArgumentException("Unexpected");
            };
            NHHelper.SetListener(nhConfig, GetSolrNetListener(mockSolr));
            new SchemaExport(nhConfig).Execute(false, true, false);
            sessionFactory = nhConfig.BuildSessionFactory();
        }
Example #7
0
        public void Does_not_override_existing_listeners()
        {
            var nhConfig     = ConfigurationExtensions.GetNhConfig();
            var mockListener = MockRepository.GenerateMock <IPostInsertEventListener>();

            nhConfig.SetListener(ListenerType.PostInsert, mockListener);

            var provider = MockRepository.GenerateMock <IServiceProvider>();
            var mapper   = MockRepository.GenerateMock <IReadOnlyMappingManager>();

            mapper.Expect(x => x.GetRegisteredTypes()).Return(new[] { typeof(Entity) });
            provider.Expect(x => x.GetService(typeof(IReadOnlyMappingManager))).Return(mapper);
            var solr = MockRepository.GenerateMock <ISolrOperations <Entity> >();

            provider.Expect(x => x.GetService(typeof(ISolrOperations <Entity>))).Return(solr);

            var helper = new CfgHelper(provider);

            helper.Configure(nhConfig, true);
            Assert.AreEqual(2, nhConfig.EventListeners.PostInsertEventListeners.Length);
        }
Example #8
0
        public void Configure_from_serviceprovider()
        {
            var nhConfig = ConfigurationExtensions.GetNhConfig();
            var provider = MockRepository.GenerateMock <IServiceProvider>();
            var mapper   = MockRepository.GenerateMock <IReadOnlyMappingManager>();

            mapper.Expect(x => x.GetRegisteredTypes()).Return(new[] { typeof(Entity) });
            var solr = MockRepository.GenerateMock <ISolrOperations <Entity> >();

            provider.Expect(x => x.GetService(typeof(IReadOnlyMappingManager))).Return(mapper);
            provider.Expect(x => x.GetService(typeof(ISolrOperations <Entity>))).Return(solr);
            var helper = new CfgHelper(provider);

            helper.Configure(nhConfig, true);
            Assert.GreaterThan(nhConfig.EventListeners.PostInsertEventListeners.Length, 0);
            Assert.GreaterThan(nhConfig.EventListeners.PostUpdateEventListeners.Length, 0);
            Assert.GreaterThan(nhConfig.EventListeners.PostDeleteEventListeners.Length, 0);
            var listener = nhConfig.EventListeners.PostInsertEventListeners[0];

            Assert.IsInstanceOfType <SolrNetListener <Entity> >(listener);
        }
Example #9
0
        public void Configure_with_addparameters()
        {
            var nhConfig = ConfigurationExtensions.GetNhConfig();
            var provider = MockRepository.GenerateMock <IServiceProvider>();
            var mapper   = MockRepository.GenerateMock <IReadOnlyMappingManager>();

            mapper.Expect(x => x.GetRegisteredTypes()).Return(new[] { typeof(Entity) });
            var solr = MockRepository.GenerateMock <ISolrOperations <Entity> >();

            provider.Expect(x => x.GetService(typeof(IReadOnlyMappingManager))).Return(mapper);
            provider.Expect(x => x.GetService(typeof(ISolrOperations <Entity>))).Return(solr);
            var addParameters = new AddParameters {
                CommitWithin = 4343
            };
            var helper = new CfgHelper(provider);

            helper.Configure(nhConfig, true, addParameters);
            var listener = nhConfig.EventListeners.PostInsertEventListeners[0];

            Assert.IsInstanceOfType <SolrNetListener <Entity> >(listener);
            Assert.AreEqual(addParameters, ((IListenerSettings)listener).AddParameters);
        }