Skip to content

Commit

Permalink
Merge v1.1.0: Convention based registration
Browse files Browse the repository at this point in the history
  • Loading branch information
florinc committed Mar 3, 2015
2 parents 5ac1058 + 0a8a370 commit 30210fc
Show file tree
Hide file tree
Showing 20 changed files with 770 additions and 36 deletions.
183 changes: 183 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/

# Roslyn cache directories
*.ide/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

#NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding addin-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# If using the old MSBuild-Integrated Package Restore, uncomment this:
#!**/packages/repositories.config

# Windows Azure Build Output
csx/
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/
16 changes: 12 additions & 4 deletions AppBoot/iQuarc.AppBoot.UnitTests/BootstrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void Run_RegistrationBehaviorReturnsOneService_TypeRegistered()
IRegistrationBehavior regBehaviorStub = GetRegBehaviorStub(testSi);

Mock<IDependencyContainer> containerMock = GetFakeContainer();

Bootstrapper bootstrapper = GetTargetWithAssembly(containerMock);
bootstrapper.AddRegistrationBehavior(regBehaviorStub);

Expand All @@ -51,12 +52,16 @@ public void Run_RegistrationBehaviorReturnsOneService_TypeRegistered()
containerMock.Verify(c => c.RegisterService(testSi), Times.AtLeastOnce);
}

private Bootstrapper GetTargetWithAssemblyAndFakeContainer()
[Fact]
public void Dispose_DisposableDependencyContainer_DisposesContainer()
{
Assembly[] assemblies = {typeof (BootstrapperTests).Assembly};
IDependencyContainer container = GetFakeContainer().Object;
Mock<IDependencyContainer> containerMock = GetFakeContainer();
Mock<IDisposable> disposable = containerMock.As<IDisposable>();

return new Bootstrapper(assemblies, container);
Bootstrapper bootstrapper = GetTargetWithAssembly(containerMock);

bootstrapper.Dispose();
disposable.Verify(c => c.Dispose(), Times.Once);
}

private static Bootstrapper GetTarget(Mock<IDependencyContainer> fakeContainer)
Expand Down Expand Up @@ -91,6 +96,9 @@ private static Mock<IDependencyContainer> GetFakeContainer(IServiceLocator servi

Mock<IDependencyContainer> containerStub = new Mock<IDependencyContainer>();
containerStub.Setup(c => c.AsServiceLocator).Returns(serviceLocator);

containerStub.As<IDisposable>();

return containerStub;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System.Linq;
using iQuarc.xUnitEx;
using Xunit;

namespace iQuarc.AppBoot.UnitTests
{
public class ConventionRegistrationBehaviorTests
{
private readonly ServiceEqualityComparer comparer = new ServiceEqualityComparer();

[Fact]
public void GetServicesFrom_TwoConventionsForType_BothExported()
{
ConventionRegistrationBehavior conventions = GetTarget();
conventions.ForType<MyService>().Export(b => b.AsContractName("Configuration 1"));
conventions.ForType<MyService>().Export(b => b.AsContractName("Configuration 2"));

conventions.GetServicesFrom(typeof (MyService));

var services = conventions.GetServicesFrom(typeof (MyService));

ServiceInfo[] expected =
{
new ServiceInfo(typeof (MyService), typeof (MyService), "Configuration 1", Lifetime.Instance),
new ServiceInfo(typeof (MyService), typeof (MyService), "Configuration 2", Lifetime.Instance)
};
AssertEx.AreEquivalent(services, comparer.Equals, expected);
}

[Fact]
public void GetServicesFrom_NoConventions_NothingExported()
{
ConventionRegistrationBehavior conventions = GetTarget();

conventions.GetServicesFrom(typeof (MyService));

ServiceInfo[] services = conventions.GetServicesFrom(typeof (MyService)).ToArray();
Assert.Equal(0, services.Length);
}

[Fact]
public void ForType_ConfigurationForMatchingType_OneMatches()
{
ConventionRegistrationBehavior behavior = GetTarget();

ServiceBuilder serviceBuilder = behavior.ForType<MyService>();

Assert.True(serviceBuilder.IsMatch(typeof (MyService)));
}

[Fact]
public void ForType_ConfigurationForNonMatchingType_MatchIsFalse()
{
ConventionRegistrationBehavior behavior = GetTarget();

ServiceBuilder serviceBuilder = behavior.ForType<MyService>();

Assert.False(serviceBuilder.IsMatch(typeof (MyOtherService)));
}

[Fact]
public void ForTypesDerivedFrom_ConfigurationWithBaseAndInheritedTypes_MatchIsTrue()
{
ConventionRegistrationBehavior behavior = GetTarget();

ServiceBuilder serviceBuilder = behavior.ForTypesDerivedFrom<MyBaseService>();

Assert.True(serviceBuilder.IsMatch(typeof (MyService)));
}

[Fact]
public void ForTypesDerivedFrom_ConfigurationUnrelatedTypes_MatchIsFalse()
{
ConventionRegistrationBehavior behavior = GetTarget();

ServiceBuilder serviceBuilder = behavior.ForTypesDerivedFrom<MyService>();

Assert.False(serviceBuilder.IsMatch(typeof (MyOtherService)));
}

[Fact]
public void ForTypesMatching_ConfigurationWithServiceSuffix_MatchIsTrue()
{
ConventionRegistrationBehavior behavior = GetTarget();

ServiceBuilder serviceBuilder = behavior.ForTypesMatching(t => t.Name.EndsWith("Service"));

Assert.True(serviceBuilder.IsMatch(typeof(MyService)));
}

[Fact]
public void ForTypesMatching_ConfigurationWithNoServiceSuffix_MatchIsFalse()
{
ConventionRegistrationBehavior behavior = GetTarget();

ServiceBuilder serviceBuilder = behavior.ForTypesMatching(t => t.Name.EndsWith("Service"));

Assert.False(serviceBuilder.IsMatch(typeof(Repository)));
}

private class MyService : MyBaseService
{
}

private class MyOtherService
{
}

private class MyBaseService
{
}

private class Repository
{
}

private static ConventionRegistrationBehavior GetTarget()
{
return new ConventionRegistrationBehavior();
}
}
}
Loading

0 comments on commit 30210fc

Please sign in to comment.