-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from JakeGinnivan/AutofacConventions2
Autofac conventions2
- Loading branch information
Showing
11 changed files
with
99 additions
and
6 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
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
23 changes: 23 additions & 0 deletions
23
TestStack.ConventionTests.Tests/Autofac/CanResolveAllRegisteredServicesTests.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,23 @@ | ||
namespace TestStack.ConventionTests.Tests.Autofac | ||
{ | ||
using global::Autofac; | ||
using NUnit.Framework; | ||
using TestStack.ConventionTests.Autofac; | ||
using TestStack.ConventionTests.Tests.Autofac.TestTypes; | ||
|
||
[TestFixture] | ||
public class CanResolveAllRegisteredServicesTests | ||
{ | ||
[Test] | ||
public void ConventionFailsWhenContainerRegistrationCannotBeResolved() | ||
{ | ||
var containerBuilder = new ContainerBuilder(); | ||
containerBuilder.RegisterType<Foo>().As<IFoo>(); | ||
var container = containerBuilder.Build(); | ||
|
||
var data = new AutofacRegistrations(container.ComponentRegistry); | ||
|
||
Assert.Throws<ConventionFailedException>(()=>Convention.Is(new CanResolveAllRegisteredServices(container), data)); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...onventionTests.Tests/Autofac/ServicesShouldOnlyHaveDependenciesWithLesserLifetimeTests.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,25 @@ | ||
namespace TestStack.ConventionTests.Tests.Autofac | ||
{ | ||
using global::Autofac; | ||
using NUnit.Framework; | ||
using TestStack.ConventionTests.Autofac; | ||
using TestStack.ConventionTests.Tests.Autofac.TestTypes; | ||
|
||
[TestFixture] | ||
public class ServicesShouldOnlyHaveDependenciesWithLesserLifetimeTests | ||
{ | ||
[Test] | ||
public void ConventionShouldFailForTransientInjectectedIntoSingleton() | ||
{ | ||
var containerBuilder = new ContainerBuilder(); | ||
containerBuilder.RegisterType<Foo>().As<IFoo>().SingleInstance(); | ||
containerBuilder.RegisterType<Bar>().As<IBar>(); | ||
|
||
var container = containerBuilder.Build(); | ||
|
||
var convention = new ServicesShouldOnlyHaveDependenciesWithLesserLifetime(); | ||
var autofacRegistrations = new AutofacRegistrations(container.ComponentRegistry); | ||
Assert.Throws<ConventionFailedException>(() => Convention.Is(convention, autofacRegistrations)); | ||
} | ||
} | ||
} |
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,7 @@ | ||
namespace TestStack.ConventionTests.Tests.Autofac.TestTypes | ||
{ | ||
public class Bar : IBar | ||
{ | ||
|
||
} | ||
} |
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,7 @@ | ||
namespace TestStack.ConventionTests.Tests.Autofac.TestTypes | ||
{ | ||
public class Foo : IFoo | ||
{ | ||
public Foo(IBar bar){} | ||
} | ||
} |
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,6 @@ | ||
namespace TestStack.ConventionTests.Tests.Autofac.TestTypes | ||
{ | ||
public interface IBar | ||
{ | ||
} | ||
} |
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,4 @@ | ||
namespace TestStack.ConventionTests.Tests.Autofac.TestTypes | ||
{ | ||
public interface IFoo {} | ||
} |
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