forked from autofac/Autofac
-
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.
Started splitting tests up between API/Spec and internals/unit.
- Loading branch information
Showing
7 changed files
with
160 additions
and
65 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
38 changes: 38 additions & 0 deletions
38
test/Autofac.Specification.Test/Autofac.Specification.Test.csproj
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp2.1;net46</TargetFrameworks> | ||
<NoWarn>$(NoWarn);CS1591;SA1602;SA1611</NoWarn> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<CodeAnalysisRuleSet>../../build/Analyzers.ruleset</CodeAnalysisRuleSet> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Autofac\Autofac.csproj" /> | ||
<ProjectReference Include="..\Autofac.Test.Scenarios.ScannedAssembly\Autofac.Test.Scenarios.ScannedAssembly.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Remove="TestResults\**" /> | ||
<EmbeddedResource Remove="TestResults\**" /> | ||
<None Remove="TestResults\**" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta009"> | ||
<PrivateAssets>All</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> | ||
</ItemGroup> | ||
|
||
</Project> |
95 changes: 95 additions & 0 deletions
95
test/Autofac.Specification.Test/Registration/TypeRegistration.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,95 @@ | ||
using System; | ||
using Xunit; | ||
|
||
namespace Autofac.Specification.Test.Registration | ||
{ | ||
/// <summary> | ||
/// Tests for fairly simple/straightforward type-as-self or | ||
/// type-as-service registrations. | ||
/// </summary> | ||
public class TypeRegistration | ||
{ | ||
private interface IA | ||
{ | ||
} | ||
|
||
private interface IB | ||
{ | ||
} | ||
|
||
private interface IC | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void RegisterTypeAsSupportedAndUnsupportedService() | ||
{ | ||
var builder = new ContainerBuilder(); | ||
builder.RegisterType<A>().As<IA, IB>(); | ||
Assert.Throws<ArgumentException>(() => builder.Build()); | ||
} | ||
|
||
[Fact] | ||
public void RegisterTypeAsUnsupportedService() | ||
{ | ||
var builder = new ContainerBuilder(); | ||
builder.RegisterType<string>().As<IA>(); | ||
Assert.Throws<ArgumentException>(() => builder.Build()); | ||
} | ||
|
||
[Fact] | ||
public void TypeRegisteredOnlyWithServiceNotRegisteredAsSelf() | ||
{ | ||
var cb = new ContainerBuilder(); | ||
cb.RegisterType<A>().As<IA>(); | ||
var c = cb.Build(); | ||
Assert.False(c.IsRegistered<A>()); | ||
} | ||
|
||
[Fact] | ||
public void TypeRegisteredWithMultipleServicesCanBeResolved() | ||
{ | ||
var target = new ContainerBuilder(); | ||
target.RegisterType<ABC>() | ||
.As<IA, IB, IC>() | ||
.SingleInstance(); | ||
var container = target.Build(); | ||
var a = container.Resolve<IA>(); | ||
var b = container.Resolve<IB>(); | ||
var c = container.Resolve<IC>(); | ||
Assert.NotNull(a); | ||
Assert.Same(a, b); | ||
Assert.Same(b, c); | ||
} | ||
|
||
[Fact] | ||
public void TypeRegisteredWithoutServiceCanBeResolved() | ||
{ | ||
var cb = new ContainerBuilder(); | ||
cb.RegisterType<A>(); | ||
var c = cb.Build(); | ||
var a = c.Resolve<A>(); | ||
Assert.NotNull(a); | ||
Assert.IsType<A>(a); | ||
} | ||
|
||
[Fact] | ||
public void TypeRegisteredWithSingleServiceCanBeResolved() | ||
{ | ||
var cb = new ContainerBuilder(); | ||
cb.RegisterType<A>().As<IA>(); | ||
var c = cb.Build(); | ||
var a = c.Resolve<IA>(); | ||
Assert.NotNull(a); | ||
Assert.IsType<A>(a); | ||
} | ||
|
||
private class A : IA | ||
{ | ||
} | ||
|
||
private class ABC : IA, IB, IC | ||
{ | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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 @@ | ||
# Test Projects | ||
|
||
- `Autofac.Test` is for unit tests that likely access internals to check on boundary conditions and so on. As versions of Autofac change and grow, these may also change and grow. | ||
- `Autofac.Specification.Test` is for tests that access Autofac through the more standard public API - doing register and resolve calls, passing in parameters, that sort of thing. In general, if the "average user" wouldn't do it (e.g., follow the interfaces all the way down to count things like how many registration sources are there) or if it accesses internals, it shouldn't be there. This test suite is intended to stay pretty stable so we can ensure the 90% case is still working if we refactor internals and possibly make breaking changes. |