-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
15 deletions.
There are no files selected for viewing
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
55 changes: 55 additions & 0 deletions
55
...oc.IssuesTests/GHIssue434_ReturnDefaultIfNotRegistered_is_not_respected_between_scopes.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,55 @@ | ||
using NUnit.Framework; | ||
|
||
namespace DryIoc.IssuesTests | ||
{ | ||
[TestFixture] | ||
public class GHIssue434_ReturnDefaultIfNotRegistered_is_not_respected_between_scopes | ||
{ | ||
[Test] | ||
public void Test_UseInstance() | ||
{ | ||
var container = new Container(); | ||
|
||
using (var scope = container.OpenScope()) | ||
{ | ||
var foo = scope.Resolve<Foo>(IfUnresolved.ReturnDefaultIfNotRegistered); // Does not throw | ||
scope.UseInstance<Foo>(new Foo()); // Do a registration within the scope | ||
} | ||
|
||
using (var scope = container.OpenScope()) | ||
{ | ||
var foo = scope.Resolve<Foo>(IfUnresolved.ReturnDefaultIfNotRegistered); | ||
Assert.IsNull(foo); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Test_Use() | ||
{ | ||
var container = new Container(); | ||
|
||
using (var scope = container.OpenScope()) | ||
{ | ||
var foo = scope.Resolve<Foo>(IfUnresolved.ReturnDefaultIfNotRegistered); // Does not throw | ||
scope.Use<Foo>(new Foo()); // Do a registration within the scope | ||
} | ||
|
||
using (var scope = container.OpenScope()) | ||
{ | ||
var foo = scope.Resolve<Foo>(IfUnresolved.ReturnDefaultIfNotRegistered); | ||
Assert.IsNull(foo); | ||
|
||
var ex = Assert.Throws<ContainerException>(() => | ||
scope.Resolve<Foo>()); | ||
Assert.AreEqual(Error.NameOf(Error.UnableToResolveUnknownService), ex.ErrorName); | ||
|
||
foo = scope.Resolve<Foo>(IfUnresolved.ReturnDefault); | ||
Assert.IsNull(foo); | ||
} | ||
} | ||
|
||
class Foo | ||
{ | ||
} | ||
} | ||
} |