public void DictionaryDocument()
        {
            var cores = new SolrServers {
                new SolrServerElement {
                    Id           = "entity1dict",
                    DocumentType = typeof(Dictionary <string, object>).AssemblyQualifiedName,
                    Url          = "http://localhost:8983/solr/core1",
                }
            };

            Container.Configure(c => c.AddRegistry(SolrNetRegistry.Create(cores)));

            var solr    = Container.GetInstance <ISolrOperations <Dictionary <string, object> > >();
            var results = solr.Query(SolrQuery.All);

            Assert.True(results.Count > 0);
            foreach (var d in results)
            {
                Assert.True(d.Count > 0);
                foreach (var kv in d)
                {
                    Console.WriteLine("{0}: {1}", kv.Key, kv.Value);
                }
            }
        }
        public void RegistersSolrConnectionWithAppConfigServerUrl()
        {
            var solrConfig = (SolrConfigurationSection)ConfigurationManager.GetSection("solr");
            var container  = new Container(c => c.IncludeRegistry(SolrNetRegistry.Create(solrConfig.SolrServers)));

            var instanceKey = "entity" + typeof(SolrConnection);

            var solrConnection = (AutoSolrConnection)container.GetInstance <ISolrConnection>(instanceKey);

            Assert.Equal("http://localhost:8983/solr/collection1", solrConnection.ServerURL);
        }
        public StructureMapIntegrationFixture()
        {
            var servers = new List <SolrServer>
            {
                new SolrServer("entity", "http://localhost:8983/solr/collection1", "StructureMap.SolrNetIntegration.Tests.Entity, StructureMap.SolrNetIntegration.Tests"),
                new SolrServer("entity2", "http://localhost:8983/solr/core0", "StructureMap.SolrNetIntegration.Tests.Entity2, StructureMap.SolrNetIntegration.Tests"),
                new SolrServer("entity3", "http://localhost:8983/solr/core1", "StructureMap.SolrNetIntegration.Tests.Entity2, StructureMap.SolrNetIntegration.Tests")
            };

            Container = new Container(c => c.IncludeRegistry(SolrNetRegistry.Create(servers)));
        }
Exemple #4
0
        public StructureMapIntegrationFixture(ITestOutputHelper testOutputHelper)
        {
            this.testOutputHelper = testOutputHelper;
            var servers = new List <SolrServer>
            {
                new SolrServer("entity", "http://solr:8983/solr/collection1", "StructureMap.SolrNetIntegration.Tests.Entity, StructureMap.SolrNetIntegration.Tests"),
                new SolrServer("entity2", "http://solr:8983/solr/core0", "StructureMap.SolrNetIntegration.Tests.Entity2, StructureMap.SolrNetIntegration.Tests"),
                new SolrServer("entity3", "http://solr:8983/solr/core1", "StructureMap.SolrNetIntegration.Tests.Entity2, StructureMap.SolrNetIntegration.Tests")
            };

            Container = new Container(c => c.IncludeRegistry(SolrNetRegistry.Create(servers)));
        }
        public void RegistersSolrConnectionWithCoresJsonServerUrl()
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetParent("../../../").FullName)
                                .AddJsonFile("cores.json")
                                .Build()
                                .GetSection("solr:servers");

            var container = new Container(c => c.IncludeRegistry(SolrNetRegistry.Create(configuration.Get <List <SolrServer> >())));


            var instanceKey = "entity" + typeof(SolrConnection);

            var solrConnection = (AutoSolrConnection)container.GetInstance <ISolrConnection>(instanceKey);

            Assert.Equal("http://localhost:8983/solr/collection1", solrConnection.ServerURL);
        }
Exemple #6
0
        public StructureMapMultiCoreFixture()
        {
            var servers = new List <SolrServer>
            {
                new SolrServer("entity", "http://localhost:8983/solr/collection1", "StructureMap.SolrNetIntegration.Tests.Entity, StructureMap.SolrNetIntegration.Tests"),
                new SolrServer("entity2", "http://localhost:8983/solr/core0", "StructureMap.SolrNetIntegration.Tests.Entity2, StructureMap.SolrNetIntegration.Tests"),
                new SolrServer("entity3", "http://localhost:8983/solr/core1", "StructureMap.SolrNetIntegration.Tests.Entity2, StructureMap.SolrNetIntegration.Tests")
            };

            Container = new Container(c =>
            {
                c.Scan(s =>
                {
                    s.Assembly(typeof(SolrNetRegistry).Assembly);
                    s.Assembly(typeof(SolrConnection).Assembly);
                    s.WithDefaultConventions();
                });
                c.AddRegistry(SolrNetRegistry.Create(servers));
            });
        }
        public void DictionaryDocument_add()
        {
            var cores = new SolrServers {
                new SolrServerElement {
                    Id           = "entity1dict",
                    DocumentType = typeof(Dictionary <string, object>).AssemblyQualifiedName,
                    Url          = "http://localhost:8983/solr/core1",
                }
            };

            Container.Configure(c => c.AddRegistry(SolrNetRegistry.Create(cores)));

            var solr = Container.GetInstance <ISolrOperations <Dictionary <string, object> > >();

            solr.Add(new Dictionary <string, object>
            {
                { "id", "ababa" },
                { "manu", "who knows" },
                { "popularity", 55 },
                { "timestamp", DateTime.UtcNow },
            });
        }
 public void DictionaryDocument_and_multi_core()
 {
     var cores = new SolrServers {
         new SolrServerElement {
             Id           = "default",
             DocumentType = typeof(Entity).AssemblyQualifiedName,
             Url          = "http://localhost:8983/solr/entity1",
         },
         new SolrServerElement {
             Id           = "entity1dict",
             DocumentType = typeof(Dictionary <string, object>).AssemblyQualifiedName,
             Url          = "http://localhost:8983/solr/entity1",
         },
         new SolrServerElement {
             Id           = "another",
             DocumentType = typeof(Entity2).AssemblyQualifiedName,
             Url          = "http://localhost:8983/solr/entity2",
         },
     };
     var container = new Container(c => c.IncludeRegistry(SolrNetRegistry.Create(cores)));
     var solr1     = container.GetInstance <ISolrOperations <Entity> >();
     var solr2     = container.GetInstance <ISolrOperations <Entity2> >();
     var solrDict  = container.GetInstance <ISolrOperations <Dictionary <string, object> > >();
 }
        public void Should_throw_exception_for_invalid_url()
        {
            var solrServers = new SolrServers {
                new SolrServerElement {
                    Id           = "test",
                    Url          = "http:/localhost:8893",
                    DocumentType = typeof(Entity2).AssemblyQualifiedName,
                }
            };

            Assert.Throws <InvalidURLException>(() => new Container(c => c.IncludeRegistry(SolrNetRegistry.Create(solrServers))));
        }