forked from SolrNet/SolrNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SimpleInjector registration improvement
- Loading branch information
Showing
2 changed files
with
106 additions
and
21 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
SimpleInjector.SolrNet.Tests/SimpleInjectorLifestyleTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using SimpleInjector.Lifestyles; | ||
using SolrNet; | ||
using Xunit; | ||
|
||
namespace SimpleInjector.SolrNet.Tests | ||
{ | ||
public class SimpleInjectorLifestyleTests | ||
{ | ||
[Fact] | ||
public void ResolveDefaultTransient() | ||
{ | ||
var container = new Container(); | ||
container.Options.DefaultLifestyle = Lifestyle.Transient; | ||
|
||
container.AddSolrNet("http://localhost:8983/solr"); | ||
|
||
container.Verify(); | ||
|
||
container.GetInstance<ISolrOperations<Entity>>(); | ||
} | ||
|
||
[Fact] | ||
public void ResolveDefaultAsyncScoped() | ||
{ | ||
using (var container = new Container()) | ||
{ | ||
container.Options.DefaultLifestyle = Lifestyle.Scoped; | ||
container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle(); | ||
|
||
container.AddSolrNet("http://localhost:8983/solr"); | ||
|
||
container.Verify(); | ||
|
||
using (AsyncScopedLifestyle.BeginScope(container)) | ||
{ | ||
var uow1 = container.GetInstance<ISolrOperations<Entity>>(); | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ResolveDefaultThreadScoped() | ||
{ | ||
using (var container = new Container()) | ||
{ | ||
container.Options.DefaultLifestyle = Lifestyle.Scoped; | ||
container.Options.DefaultScopedLifestyle = new ThreadScopedLifestyle(); | ||
|
||
container.AddSolrNet("http://localhost:8983/solr"); | ||
|
||
container.Verify(); | ||
|
||
using (ThreadScopedLifestyle.BeginScope(container)) | ||
{ | ||
var uow1 = container.GetInstance<ISolrOperations<Entity>>(); | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ResolveDefaultSingleton() | ||
{ | ||
using (var container = new Container()) | ||
{ | ||
container.Options.DefaultLifestyle = Lifestyle.Singleton; | ||
|
||
container.AddSolrNet("http://localhost:8983/solr"); | ||
|
||
container.Verify(); | ||
|
||
using (ThreadScopedLifestyle.BeginScope(container)) | ||
{ | ||
var uow1 = container.GetInstance<ISolrOperations<Entity>>(); | ||
} | ||
} | ||
} | ||
|
||
public class Entity { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters