-
-
Notifications
You must be signed in to change notification settings - Fork 832
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
13 changed files
with
212 additions
and
47 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
test/Autofac.Specification.Test/Lifetime/ExternallyOwned.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,27 @@ | ||
using System; | ||
using Autofac.Specification.Test.Util; | ||
using Xunit; | ||
|
||
namespace Autofac.Specification.Test.Lifetime | ||
{ | ||
public class ExternallyOwned | ||
{ | ||
[Fact] | ||
public void RootInstancesNotDisposedOnContainerDisposal() | ||
{ | ||
var cb = new ContainerBuilder(); | ||
cb.RegisterType<A>().ExternallyOwned(); | ||
var c = cb.Build(); | ||
var a1 = c.Resolve<A>(); | ||
var a2 = c.Resolve<A>(); | ||
c.Dispose(); | ||
|
||
Assert.False(a1.IsDisposed); | ||
Assert.False(a2.IsDisposed); | ||
} | ||
|
||
private class A : DisposeTracker | ||
{ | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
test/Autofac.Specification.Test/Resolution/ComplexGraph.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,38 @@ | ||
using System; | ||
using Autofac.Specification.Test.Resolution.Graph1; | ||
using Xunit; | ||
|
||
namespace Autofac.Specification.Test.Resolution | ||
{ | ||
public class ComplexGraph | ||
{ | ||
[Fact] | ||
public void CanCorrectlyBuildGraph1() | ||
{ | ||
var builder = new ContainerBuilder(); | ||
|
||
builder.RegisterType<A1>().SingleInstance(); | ||
builder.RegisterType<CD1>().As<IC1, ID1>().SingleInstance(); | ||
builder.RegisterType<E1>().SingleInstance(); | ||
builder.Register(ctr => new B1(ctr.Resolve<A1>())); | ||
|
||
var target = builder.Build(); | ||
|
||
var e = target.Resolve<E1>(); | ||
var a = target.Resolve<A1>(); | ||
var b = target.Resolve<B1>(); | ||
var c = target.Resolve<IC1>(); | ||
var d = target.Resolve<ID1>(); | ||
|
||
Assert.IsType<CD1>(c); | ||
var cd = (CD1)c; | ||
|
||
Assert.Same(a, b.A); | ||
Assert.Same(a, cd.A); | ||
Assert.NotSame(b, cd.B); | ||
Assert.Same(c, e.C); | ||
Assert.NotSame(b, e.B); | ||
Assert.NotSame(e.B, cd.B); | ||
} | ||
} | ||
} |
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,12 @@ | ||
using System; | ||
using System.Linq; | ||
using Autofac.Specification.Test.Util; | ||
|
||
namespace Autofac.Specification.Test.Resolution.Graph1 | ||
{ | ||
// In the below scenario, B1 depends on A1, CD depends on A1 and B1, | ||
// and E depends on IC1 and B1. | ||
public class A1 : DisposeTracker | ||
{ | ||
} | ||
} |
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,18 @@ | ||
using System; | ||
using System.Linq; | ||
using Autofac.Specification.Test.Util; | ||
|
||
namespace Autofac.Specification.Test.Resolution.Graph1 | ||
{ | ||
// In the below scenario, B1 depends on A1, CD depends on A1 and B1, | ||
// and E depends on IC1 and B1. | ||
public class B1 : DisposeTracker | ||
{ | ||
public B1(A1 a) | ||
{ | ||
this.A = a; | ||
} | ||
|
||
public A1 A { get; private set; } | ||
} | ||
} |
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,18 @@ | ||
using System; | ||
using System.Linq; | ||
using Autofac.Specification.Test.Util; | ||
|
||
namespace Autofac.Specification.Test.Resolution.Graph1 | ||
{ | ||
// In the below scenario, B1 depends on A1, CD depends on A1 and B1, | ||
// and E depends on IC1 and B1. | ||
public class C1 : DisposeTracker | ||
{ | ||
public C1(B1 b) | ||
{ | ||
this.B = b; | ||
} | ||
|
||
public B1 B { get; private set; } | ||
} | ||
} |
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,21 @@ | ||
using System; | ||
using System.Linq; | ||
using Autofac.Specification.Test.Util; | ||
|
||
namespace Autofac.Specification.Test.Resolution.Graph1 | ||
{ | ||
// In the below scenario, B1 depends on A1, CD depends on A1 and B1, | ||
// and E depends on IC1 and B1. | ||
public class CD1 : DisposeTracker, IC1, ID1 | ||
{ | ||
public CD1(A1 a, B1 b) | ||
{ | ||
this.A = a; | ||
this.B = b; | ||
} | ||
|
||
public A1 A { get; private set; } | ||
|
||
public B1 B { get; private set; } | ||
} | ||
} |
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,21 @@ | ||
using System; | ||
using System.Linq; | ||
using Autofac.Specification.Test.Util; | ||
|
||
namespace Autofac.Specification.Test.Resolution.Graph1 | ||
{ | ||
// In the below scenario, B1 depends on A1, CD depends on A1 and B1, | ||
// and E depends on IC1 and B1. | ||
public class E1 : DisposeTracker | ||
{ | ||
public E1(B1 b, IC1 c) | ||
{ | ||
this.B = b; | ||
this.C = c; | ||
} | ||
|
||
public B1 B { get; private set; } | ||
|
||
public IC1 C { get; private set; } | ||
} | ||
} |
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,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Autofac.Specification.Test.Resolution.Graph1 | ||
{ | ||
// In the below scenario, B1 depends on A1, CD depends on A1 and B1, | ||
// and E depends on IC1 and B1. | ||
public class F1 | ||
{ | ||
public F1(IList<A1> aList) | ||
{ | ||
this.AList = aList; | ||
} | ||
|
||
public IList<A1> AList { get; private set; } | ||
} | ||
} |
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,11 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Autofac.Specification.Test.Resolution.Graph1 | ||
{ | ||
// In the below scenario, B1 depends on A1, CD depends on A1 and B1, | ||
// and E depends on IC1 and B1. | ||
public interface IC1 | ||
{ | ||
} | ||
} |
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,11 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Autofac.Specification.Test.Resolution.Graph1 | ||
{ | ||
// In the below scenario, B1 depends on A1, CD depends on A1 and B1, | ||
// and E depends on IC1 and B1. | ||
public interface ID1 | ||
{ | ||
} | ||
} |
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,17 @@ | ||
using System; | ||
|
||
namespace Autofac.Specification.Test.Util | ||
{ | ||
public class DisposeTracker : IDisposable | ||
{ | ||
public event EventHandler<EventArgs> Disposing; | ||
|
||
public bool IsDisposed { get; set; } | ||
|
||
public void Dispose() | ||
{ | ||
this.IsDisposed = true; | ||
this.Disposing?.Invoke(this, EventArgs.Empty); | ||
} | ||
} | ||
} |
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
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