forked from SolrNet/SolrNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStructureMapFixture.cs
142 lines (127 loc) · 5.24 KB
/
StructureMapFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Collections.Generic;
using System.Configuration;
using MbUnit.Framework;
using SolrNet;
using SolrNet.Exceptions;
using SolrNet.Impl;
using System.Reflection;
using StructureMap.SolrNetIntegration.Config;
namespace StructureMap.SolrNetIntegration.Tests
{
[TestFixture]
public class StructureMapFixture
{
[Test]
public void ResolveSolrOperations()
{
SetupContainer();
var m = ObjectFactory.GetInstance<ISolrOperations<Entity>>();
Assert.IsNotNull(m);
}
[Test]
public void RegistersSolrConnectionWithAppConfigServerUrl() {
SetupContainer();
var instanceKey = "entity" + typeof(SolrConnection);
var solrConnection = (SolrConnection)ObjectFactory.Container.GetInstance<ISolrConnection>(instanceKey);
Assert.AreEqual("http://localhost:8983/solr/entity", solrConnection.ServerURL);
}
[Test, ExpectedException(typeof(InvalidURLException))]
public void Should_throw_exception_for_invalid_protocol_on_url()
{
var solrServers = new SolrServers {
new SolrServerElement {
Id = "test",
Url = "htp://localhost:8893",
DocumentType = typeof(Entity2).AssemblyQualifiedName,
}
};
ObjectFactory.Initialize(c => c.IncludeRegistry(new SolrNetRegistry(solrServers)));
ObjectFactory.GetInstance<SolrConnection>();
}
[Test, ExpectedException(typeof(InvalidURLException))]
public void Should_throw_exception_for_invalid_url()
{
var solrServers = new SolrServers {
new SolrServerElement {
Id = "test",
Url = "http:/localhost:8893",
DocumentType = typeof(Entity2).AssemblyQualifiedName,
}
};
ObjectFactory.Initialize(c => c.IncludeRegistry(new SolrNetRegistry(solrServers)));
ObjectFactory.GetInstance<SolrConnection>();
}
[Test]
public void Container_has_ISolrFieldParser()
{
SetupContainer();
var parser = ObjectFactory.GetInstance<ISolrFieldParser>();
Assert.IsNotNull(parser);
}
[Test]
public void Container_has_ISolrFieldSerializer()
{
SetupContainer();
ObjectFactory.GetInstance<ISolrFieldSerializer>();
}
[Test]
public void Container_has_ISolrDocumentPropertyVisitor()
{
SetupContainer();
ObjectFactory.GetInstance<ISolrDocumentPropertyVisitor>();
}
[Test]
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",
},
};
ObjectFactory.Initialize(c => c.IncludeRegistry(new SolrNetRegistry(cores)));
var solr1 = ObjectFactory.GetInstance<ISolrOperations<Entity>>();
var solr2 = ObjectFactory.GetInstance<ISolrOperations<Entity2>>();
var solrDict = ObjectFactory.GetInstance<ISolrOperations<Dictionary<string, object>>>();
}
[Test]
public void DictionaryDocument_ResponseParser()
{
SetupContainer();
var parser = ObjectFactory.GetInstance<ISolrDocumentResponseParser<Dictionary<string, object>>>();
Assert.IsInstanceOfType<SolrDictionaryDocumentResponseParser>(parser);
}
[Test]
public void DictionaryDocument_Serializer()
{
SetupContainer();
var serializer = ObjectFactory.GetInstance<ISolrDocumentSerializer<Dictionary<string, object>>>();
Assert.IsInstanceOfType<SolrDictionarySerializer>(serializer);
}
[Test]
public void Cache() {
SetupContainer();
ObjectFactory.Configure(cfg => cfg.For<ISolrCache>().Use<HttpRuntimeCache>());
var connectionId = "entity" + typeof (SolrConnection);
var connection = (SolrConnection) ObjectFactory.GetNamedInstance<ISolrConnection>(connectionId);
Assert.IsNotNull(connection.Cache);
Assert.IsInstanceOfType<HttpRuntimeCache>(connection.Cache);
}
private static void SetupContainer()
{
var solrConfig = (SolrConfigurationSection)ConfigurationManager.GetSection("solr");
ObjectFactory.Initialize(c => c.IncludeRegistry(new SolrNetRegistry(solrConfig.SolrServers)));
}
}
}