Skip to content

Commit c6be927

Browse files
committed
Merge branch 'release/3.7.1'
2 parents 7eea654 + 00c7560 commit c6be927

19 files changed

Lines changed: 315 additions & 61 deletions

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
code-patterns
1+
Code Patterns for .NET
22
=============
33

4-
Code Patterns: lots of reusable goodies for your C# project
4+
# Welcome! #
5+
## You've found my .NET utility belt. ##
6+
## It's constantly growing. ##
7+
## Its entire goal is to make life easier. ##
8+
9+
Here are the highlights:
10+
11+
* This is the official codebase used for [NuGet distributions of Patterns](https://nuget.org/packages?q=id%3A+Patterns%3B+author%3A+%22John+Batte%22).
12+
* Check the [official code patterns site](http://jbatte47.github.io/code-patterns/) for API documenation and additional information.
13+
* Head over to [the wiki](https://github.com/jbatte47/code-patterns/wiki) for user-contributed content.
14+
* You can also check out [the license file](https://github.com/jbatte47/code-patterns/blob/master/license.txt "FreeBSD (2-Clause)") if you're wondering about that.
15+
16+
Hopefully you'll find these libraries as useful as I do. Cheers!

src/Patterns.Testing/Moq/MoqContainer.cs renamed to src/Patterns.Testing.Autofac/AutofacMoqContainer.cs

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,29 @@
2929
using Moq;
3030

3131
using Patterns.Autofac;
32+
using Patterns.Testing.Moq;
3233

33-
namespace Patterns.Testing.Moq
34+
namespace Patterns.Testing.Autofac
3435
{
3536
/// <summary>
3637
/// Provides a default implementation of the <see cref="IMoqContainer" /> interface.
3738
/// </summary>
38-
public sealed class MoqContainer : AccessibleContainer, IMoqContainer
39+
public sealed class AutofacMoqContainer : AccessibleContainer, IAutofacMoqContainer
3940
{
4041
/// <summary>
41-
/// Initializes a new instance of the <see cref="MoqContainer" /> class.
42+
/// Initializes a new instance of the <see cref="AutofacMoqContainer" /> class.
4243
/// </summary>
4344
/// <param name="container">The container.</param>
44-
public MoqContainer(IContainer container) : base(container)
45+
public AutofacMoqContainer(IContainer container) : base(container)
4546
{
4647
Locator = new AutofacServiceLocator(this);
4748
ComponentRegistry.AddRegistrationSource(new MoqRegistrationSource());
4849
}
4950

5051
/// <summary>
51-
/// Initializes a new instance of the <see cref="MoqContainer" /> class.
52+
/// Initializes a new instance of the <see cref="AutofacMoqContainer" /> class.
5253
/// </summary>
53-
public MoqContainer() : this(new ContainerBuilder().Build()) {}
54+
public AutofacMoqContainer() : this(new ContainerBuilder().Build()) {}
5455

5556
/// <summary>
5657
/// Gets the locator.
@@ -103,7 +104,7 @@ public TService Create<TService>(Func<IMoqContainer, TService> activator = null)
103104
/// </returns>
104105
public IMoqContainer Update<TService, TImplementation>() where TService : class where TImplementation : TService
105106
{
106-
Update(builder => builder.RegisterType<TImplementation>().As<TService>()
107+
UpdateWithBuilder(builder => builder.RegisterType<TImplementation>().As<TService>()
107108
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));
108109

109110
return this;
@@ -119,7 +120,7 @@ public IMoqContainer Update<TService, TImplementation>() where TService : class
119120
/// </returns>
120121
public IMoqContainer Update<TService>(TService instance) where TService : class
121122
{
122-
Update(builder => builder.RegisterInstance(instance).As<TService>()
123+
UpdateWithBuilder(builder => builder.RegisterInstance(instance).As<TService>()
123124
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));
124125

125126
return this;
@@ -135,13 +136,39 @@ public IMoqContainer Update<TService>(TService instance) where TService : class
135136
/// </returns>
136137
public IMoqContainer Update<TService>(Func<IMoqContainer, TService> activator) where TService : class
137138
{
138-
Update(builder => builder.Register(c => activator(this)).As<TService>()
139+
UpdateWithBuilder(builder => builder.Register(c => activator(this)).As<TService>()
139140
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));
140141

141142
return this;
142143
}
143144

144-
private void Update(Action<ContainerBuilder> registration)
145+
/// <summary>
146+
/// Updates the container using the specified module.
147+
/// </summary>
148+
/// <param name="module">The module.</param>
149+
/// <returns>
150+
/// The container.
151+
/// </returns>
152+
public IAutofacMoqContainer Update(Module module)
153+
{
154+
UpdateWithBuilder(builder => builder.RegisterModule(module));
155+
return this;
156+
}
157+
158+
/// <summary>
159+
/// Updates the container using the specified registration.
160+
/// </summary>
161+
/// <param name="registration">The registration.</param>
162+
/// <returns>
163+
/// The container.
164+
/// </returns>
165+
public IAutofacMoqContainer Update(Action<ContainerBuilder> registration)
166+
{
167+
UpdateWithBuilder(registration);
168+
return this;
169+
}
170+
171+
private void UpdateWithBuilder(Action<ContainerBuilder> registration)
145172
{
146173
var builder = new ContainerBuilder();
147174
registration(builder);
@@ -150,7 +177,7 @@ private void Update(Action<ContainerBuilder> registration)
150177

151178
private T ResolveOrCreate<T>(Action<ContainerBuilder> registration)
152179
{
153-
if (!Container.IsRegistered<T>()) Update(registration);
180+
if (!Container.IsRegistered<T>()) UpdateWithBuilder(registration);
154181
return Container.Resolve<T>();
155182
}
156183
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#region FreeBSD
2+
3+
// Copyright (c) 2013, John Batte
4+
// All rights reserved.
5+
//
6+
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7+
//
8+
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9+
//
10+
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
11+
// documentation and/or other materials provided with the distribution.
12+
//
13+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
14+
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
15+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
17+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
18+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19+
20+
#endregion
21+
22+
using System;
23+
24+
using Autofac;
25+
26+
using Patterns.Testing.Moq;
27+
28+
namespace Patterns.Testing.Autofac
29+
{
30+
/// <summary>
31+
/// Augments <see cref="IMoqContainer"/> with Autofac-specific functionality.
32+
/// Use this when you are using Autofac as your IoC in a test project, and
33+
/// you need to load a Module or run a ContainerBuilder-specific method.
34+
/// </summary>
35+
public interface IAutofacMoqContainer : IMoqContainer, IContainer
36+
{
37+
/// <summary>
38+
/// Updates the container using the specified module.
39+
/// </summary>
40+
/// <param name="module">The module.</param>
41+
/// <returns>The container.</returns>
42+
IAutofacMoqContainer Update(Module module);
43+
44+
/// <summary>
45+
/// Updates the container using the specified registration.
46+
/// </summary>
47+
/// <param name="registration">The registration.</param>
48+
/// <returns>The container.</returns>
49+
IAutofacMoqContainer Update(Action<ContainerBuilder> registration);
50+
}
51+
}

src/Patterns.Testing/Moq/MoqRegistrationSource.cs renamed to src/Patterns.Testing.Autofac/MoqRegistrationSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
using Moq;
1010

11-
namespace Patterns.Testing.Moq
11+
namespace Patterns.Testing.Autofac
1212
{
1313
/// <summary>
1414
/// Provides a registration source for Autofac using Moq's MockRepository as a service factory.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{88379560-EFAE-4296-BF81-D1809B0F7BD3}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Patterns.Testing.Autofac</RootNamespace>
11+
<AssemblyName>Patterns.Testing.Autofac</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
15+
<RestorePackages>true</RestorePackages>
16+
<BuildPackage>true</BuildPackage>
17+
<TargetFrameworkProfile />
18+
</PropertyGroup>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
<DocumentationFile>bin\Debug\Patterns.Testing.Autofac.XML</DocumentationFile>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="Autofac">
39+
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.dll</HintPath>
40+
</Reference>
41+
<Reference Include="Autofac.Configuration">
42+
<HintPath>..\packages\Autofac.3.0.1\lib\net40\Autofac.Configuration.dll</HintPath>
43+
</Reference>
44+
<Reference Include="Autofac.Extras.CommonServiceLocator">
45+
<HintPath>..\packages\Autofac.Extras.CommonServiceLocator.3.0.0\lib\net40\Autofac.Extras.CommonServiceLocator.dll</HintPath>
46+
</Reference>
47+
<Reference Include="Microsoft.Practices.ServiceLocation">
48+
<HintPath>..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
49+
</Reference>
50+
<Reference Include="Moq">
51+
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
52+
</Reference>
53+
<Reference Include="System" />
54+
<Reference Include="System.Core" />
55+
<Reference Include="System.Xml.Linq" />
56+
<Reference Include="System.Data.DataSetExtensions" />
57+
<Reference Include="Microsoft.CSharp" />
58+
<Reference Include="System.Data" />
59+
<Reference Include="System.Xml" />
60+
</ItemGroup>
61+
<ItemGroup>
62+
<Compile Include="..\Patterns\SolutionAssemblyInfo.cs">
63+
<Link>Properties\SolutionAssemblyInfo.cs</Link>
64+
</Compile>
65+
<Compile Include="IAutofacMoqContainer.cs" />
66+
<Compile Include="AutofacMoqContainer.cs" />
67+
<Compile Include="MoqRegistrationSource.cs" />
68+
<Compile Include="Properties\AssemblyInfo.cs" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<None Include="packages.config" />
72+
<None Include="Patterns.Testing.Autofac.nuspec">
73+
<AutoGen>True</AutoGen>
74+
<DesignTime>True</DesignTime>
75+
<DependentUpon>Patterns.Testing.Autofac.tt</DependentUpon>
76+
</None>
77+
<None Include="Patterns.Testing.Autofac.tt">
78+
<Generator>TextTemplatingFileGenerator</Generator>
79+
<LastGenOutput>Patterns.Testing.Autofac.nuspec</LastGenOutput>
80+
</None>
81+
</ItemGroup>
82+
<ItemGroup>
83+
<ProjectReference Include="..\Patterns.Autofac\Patterns.Autofac.csproj">
84+
<Project>{97728D2C-BDD1-4DE5-A478-3ED86B3F091B}</Project>
85+
<Name>Patterns.Autofac</Name>
86+
</ProjectReference>
87+
<ProjectReference Include="..\Patterns.Testing\Patterns.Testing.csproj">
88+
<Project>{367EAA3A-FABB-4CFB-AF01-AD0A4F0499FD}</Project>
89+
<Name>Patterns.Testing</Name>
90+
</ProjectReference>
91+
</ItemGroup>
92+
<ItemGroup>
93+
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
94+
</ItemGroup>
95+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
96+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
97+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
98+
Other similar extension points exist, see Microsoft.Common.targets.
99+
<Target Name="BeforeBuild">
100+
</Target>
101+
<Target Name="AfterBuild">
102+
</Target>
103+
-->
104+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
3+
<metadata>
4+
<version>$version$</version>
5+
<authors>$author$</authors>
6+
<owners>$author$</owners>
7+
<projectUrl>https://github.com/jbatte47/code-patterns</projectUrl>
8+
<dependencies>
9+
<dependency id="Patterns.Autofac" version="$version$" />
10+
<dependency id="Patterns.Testing" version="$version$" />
11+
</dependencies>
12+
<id>$id$</id>
13+
<title>$id$</title>
14+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
15+
<description>$description$</description>
16+
<copyright>Copyright © 2013</copyright>
17+
</metadata>
18+
</package>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<#@ template debug="false" hostspecific="false" language="C#" #><#@
2+
assembly name="System.Core" #><#@
3+
output extension=".nuspec" #><?xml version="1.0"?>
4+
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
5+
<metadata>
6+
<version>$version$</version>
7+
<authors>$author$</authors>
8+
<owners>$author$</owners>
9+
<projectUrl>https://github.com/jbatte47/code-patterns</projectUrl>
10+
<dependencies>
11+
<dependency id="Patterns.Autofac" version="$version$" />
12+
<dependency id="Patterns.Testing" version="$version$" />
13+
</dependencies>
14+
<id>$id$</id>
15+
<title>$id$</title>
16+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
17+
<description>$description$</description>
18+
<copyright>Copyright © <#= DateTime.Now.Year #></copyright>
19+
</metadata>
20+
</package>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#region FreeBSD
2+
3+
// Copyright (c) 2013, John Batte
4+
// All rights reserved.
5+
//
6+
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7+
//
8+
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9+
//
10+
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
11+
// documentation and/or other materials provided with the distribution.
12+
//
13+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
14+
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
15+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
17+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
18+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19+
20+
#endregion
21+
22+
using System.Reflection;
23+
using System.Runtime.InteropServices;
24+
25+
[assembly: AssemblyTitle("Patterns.Testing.Autofac")]
26+
[assembly: AssemblyDescription("The Autofac Implementation of Patterns.Testing")]
27+
[assembly: Guid("5353bb55-9865-4b72-8e52-eb5ba03c0834")]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Autofac" version="3.0.1" targetFramework="net45" />
4+
<package id="Autofac.Extras.CommonServiceLocator" version="3.0.0" targetFramework="net45" />
5+
<package id="CommonServiceLocator" version="1.0" targetFramework="net45" />
6+
<package id="Moq" version="4.0.10827" targetFramework="net45" />
7+
</packages>

src/Patterns.Testing/Moq/IMoqContainer.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,17 @@
2121

2222
using System;
2323

24-
using Autofac;
25-
2624
using Microsoft.Practices.ServiceLocation;
2725

2826
using Moq;
2927

3028
namespace Patterns.Testing.Moq
3129
{
3230
/// <summary>
33-
/// Combines the Autofac IContainer interface with
34-
/// additional features for added configurability during tests,
35-
/// and for tighter integration with Moq.
31+
/// Provides an IoC container designed for maximum configurability
32+
/// during tests, and for tight integration with Moq.
3633
/// </summary>
37-
public interface IMoqContainer : IContainer
34+
public interface IMoqContainer
3835
{
3936
/// <summary>
4037
/// Gets the locator.

0 commit comments

Comments
 (0)