Skip to content

Commit ba9a87e

Browse files
committed
Merge pull request #137 from TheTribe/release/3.10-beta.5
Release/3.10-beta.5
2 parents fc7f668 + 7c81348 commit ba9a87e

34 files changed

Lines changed: 785 additions & 230 deletions

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
The following log details the outward-facing changes made to code-patterns since its first migration to GitHub.
44

5+
## 3.10-beta.5 ##
6+
7+
- Dropped reference to Reactive Extensions ([issue 123](https://github.com/TheTribe/code-patterns/issues/123))
8+
- Updated MappingServices to use underlying types for collections ([issue 126](https://github.com/TheTribe/code-patterns/issues/126))
9+
- Added support for overriding mock behavior in `IMoqContainer` ([issue 125](https://github.com/TheTribe/code-patterns/issues/125))
10+
- Fixed TimeExtensions feature bug ([issue 129](https://github.com/TheTribe/code-patterns/issues/129))
11+
- Added new `Proceed` pointcut to `DelegateInterceptor` ([issue 135](https://github.com/TheTribe/code-patterns/issues/135))
12+
513
## 3.10-beta.4 ##
614

715
- Fixes for `IMoqContainer` ([issue 114](https://github.com/TheTribe/code-patterns/issues/114))

src/.nuget/packages.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="NuGetPowerTools" version="0.29" />
4-
<package id="Rx-Main" version="2.1.30214.0" />
54
</packages>

src/Patterns.Autofac/Logging/LoggingModule.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
using System;
2727
using System.Linq;
28-
using System.Reactive.Linq;
29-
3028
using Autofac;
3129
using Autofac.Core;
3230
using Autofac.Core.Registration;
@@ -82,16 +80,11 @@ protected override void Load(ContainerBuilder builder)
8280

8381
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
8482
{
85-
Observable.FromEventPattern<PreparingEventArgs>(handler => registration.Preparing += handler, handler => registration.Preparing -= handler)
86-
.Subscribe(@event =>
87-
{
88-
PreparingEventArgs args = @event.EventArgs;
89-
args.Parameters = args.Parameters.Concat(new[]
90-
{
91-
new ResolvedParameter((info, context) => info.ParameterType == typeof (ILog),
92-
(info, context) => _logFactory(info.Member.DeclaringType))
93-
});
94-
});
83+
registration.Preparing += (sender, args) => args.Parameters = args.Parameters.Concat(new[]
84+
{
85+
new ResolvedParameter((info, context) => info.ParameterType == typeof (ILog),
86+
(info, context) => _logFactory(info.Member.DeclaringType))
87+
});
9588
}
9689
}
9790
}

src/Patterns.Autofac/Patterns.Autofac.csproj

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@
3737
<ItemGroup>
3838
<Reference Include="Autofac, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
3939
<SpecificVersion>False</SpecificVersion>
40-
<HintPath>..\packages\Autofac.3.1.1\lib\net40\Autofac.dll</HintPath>
40+
<HintPath>..\packages\Autofac.3.1.5\lib\net40\Autofac.dll</HintPath>
4141
</Reference>
42-
<Reference Include="AutoMapper">
43-
<HintPath>..\packages\AutoMapper.2.2.1\lib\net40\AutoMapper.dll</HintPath>
42+
<Reference Include="AutoMapper, Version=3.1.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
43+
<SpecificVersion>False</SpecificVersion>
44+
<HintPath>..\packages\AutoMapper.3.1.0\lib\net40\AutoMapper.dll</HintPath>
45+
</Reference>
46+
<Reference Include="AutoMapper.Net4">
47+
<HintPath>..\packages\AutoMapper.3.1.0\lib\net40\AutoMapper.Net4.dll</HintPath>
4448
</Reference>
4549
<Reference Include="Castle.Core, Version=3.2.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
4650
<SpecificVersion>False</SpecificVersion>
47-
<HintPath>..\packages\Castle.Core.3.2.0\lib\net40-client\Castle.Core.dll</HintPath>
51+
<HintPath>..\packages\Castle.Core.3.2.2\lib\net40-client\Castle.Core.dll</HintPath>
4852
</Reference>
4953
<Reference Include="Common.Logging, Version=2.1.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
5054
<SpecificVersion>False</SpecificVersion>
@@ -53,22 +57,6 @@
5357
<Reference Include="System" />
5458
<Reference Include="System.configuration" />
5559
<Reference Include="System.Core" />
56-
<Reference Include="System.Reactive.Core, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
57-
<SpecificVersion>False</SpecificVersion>
58-
<HintPath>..\packages\Rx-Core.2.1.30214.0\lib\Net40\System.Reactive.Core.dll</HintPath>
59-
</Reference>
60-
<Reference Include="System.Reactive.Interfaces, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
61-
<SpecificVersion>False</SpecificVersion>
62-
<HintPath>..\packages\Rx-Interfaces.2.1.30214.0\lib\Net40\System.Reactive.Interfaces.dll</HintPath>
63-
</Reference>
64-
<Reference Include="System.Reactive.Linq, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
65-
<SpecificVersion>False</SpecificVersion>
66-
<HintPath>..\packages\Rx-Linq.2.1.30214.0\lib\Net40\System.Reactive.Linq.dll</HintPath>
67-
</Reference>
68-
<Reference Include="System.Reactive.PlatformServices, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
69-
<SpecificVersion>False</SpecificVersion>
70-
<HintPath>..\packages\Rx-PlatformServices.2.1.30214.0\lib\Net40\System.Reactive.PlatformServices.dll</HintPath>
71-
</Reference>
7260
<Reference Include="System.Xml.Linq" />
7361
<Reference Include="System.Data.DataSetExtensions" />
7462
<Reference Include="Microsoft.CSharp" />
@@ -129,6 +117,12 @@
129117
<LastGenOutput>ContainerResources.Designer.cs</LastGenOutput>
130118
</EmbeddedResource>
131119
</ItemGroup>
120+
<ItemGroup>
121+
<Content Include="..\packages\AutoMapper.3.1.0\lib\net40\AutoMapper.Net4.dll">
122+
<Link>AutoMapper.Net4.dll</Link>
123+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
124+
</Content>
125+
</ItemGroup>
132126
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
133127
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
134128
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Autofac" version="3.1.1" targetFramework="net40" />
4-
<package id="AutoMapper" version="2.2.1" targetFramework="net40" />
5-
<package id="Castle.Core" version="3.2.0" targetFramework="net40" />
3+
<package id="Autofac" version="3.1.5" targetFramework="net40" />
4+
<package id="AutoMapper" version="3.1.0" targetFramework="net40" />
5+
<package id="Castle.Core" version="3.2.2" targetFramework="net40" />
66
<package id="Common.Logging" version="2.1.2" targetFramework="net40" />
7-
<package id="Rx-Core" version="2.1.30214.0" targetFramework="net40" />
8-
<package id="Rx-Interfaces" version="2.1.30214.0" targetFramework="net40" />
9-
<package id="Rx-Linq" version="2.1.30214.0" targetFramework="net40" />
10-
<package id="Rx-Main" version="2.1.30214.0" targetFramework="net40" />
11-
<package id="Rx-PlatformServices" version="2.1.30214.0" targetFramework="net40" />
127
</packages>

src/Patterns.Testing.Autofac/Moq/AutofacMoqContainer.cs

Lines changed: 71 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,82 +20,118 @@
2020
#endregion
2121

2222
using System;
23-
23+
using System.Collections.Generic;
2424
using Autofac;
25+
using Autofac.Core;
2526
using Autofac.Extras.CommonServiceLocator;
26-
2727
using Microsoft.Practices.ServiceLocation;
28-
2928
using Moq;
30-
3129
using Patterns.Autofac;
3230
using Patterns.ExceptionHandling;
3331
using Patterns.Testing.Moq;
3432

3533
namespace Patterns.Testing.Autofac.Moq
3634
{
3735
/// <summary>
38-
/// Provides a default implementation of the <see cref="IAutofacMoqContainer" /> interface.
36+
/// Provides a default implementation of the <see cref="IAutofacMoqContainer" /> interface.
3937
/// </summary>
4038
public sealed class AutofacMoqContainer : AccessibleContainer, IAutofacMoqContainer
4139
{
40+
private readonly MockBehavior _defaultBehavior;
41+
private readonly MoqRegistrationSource _registrationSource;
42+
4243
/// <summary>
43-
/// Initializes a new instance of the <see cref="AutofacMoqContainer" /> class.
44+
/// Initializes a new instance of the <see cref="AutofacMoqContainer" /> class with
4445
/// </summary>
45-
/// <param name="container">The container.</param>
46-
public AutofacMoqContainer(IContainer container) : base(container)
46+
/// <param name="defaultBehavior">The default <see cref="MockBehavior"/>.</param>
47+
public AutofacMoqContainer(IContainer container, MockBehavior behavior) : base(container)
4748
{
49+
_defaultBehavior = behavior;
4850
Locator = new AutofacServiceLocator(this);
49-
ComponentRegistry.AddRegistrationSource(new MoqRegistrationSource());
51+
ComponentRegistry.AddRegistrationSource(_registrationSource = new MoqRegistrationSource(_defaultBehavior));
52+
}
53+
54+
/// <summary>
55+
/// Initializes a new instance of the <see cref="AutofacMoqContainer" /> class.
56+
/// </summary>
57+
/// <param name="container">The container.</param>
58+
/// <param name="defaultBehavior">The default <see cref="MockBehavior"/>.</param>
59+
public AutofacMoqContainer(IContainer container) : this(container, MockBehavior.Default)
60+
{
5061
}
5162

5263
/// <summary>
53-
/// Initializes a new instance of the <see cref="AutofacMoqContainer" /> class.
64+
/// Initializes a new instance of the <see cref="AutofacMoqContainer" /> class.
5465
/// </summary>
55-
public AutofacMoqContainer() : this(new ContainerBuilder().Build()) {}
66+
public AutofacMoqContainer() : this(new ContainerBuilder().Build())
67+
{
68+
}
5669

5770
/// <summary>
58-
/// Gets the locator.
71+
/// Gets the default <see cref="MockBehavior"/>.
5972
/// </summary>
6073
/// <value>
61-
/// The locator.
74+
/// The default <see cref="MockBehavior"/>.
75+
/// </value>
76+
public MockBehavior DefaultBehavior { get { return _defaultBehavior; } }
77+
78+
/// <summary>
79+
/// Gets the locator.
80+
/// </summary>
81+
/// <value>
82+
/// The locator.
6283
/// </value>
6384
public IServiceLocator Locator { get; private set; }
6485

6586
/// <summary>
66-
/// Retrieves the mock for the specified service type.
87+
/// Retrieves the mock for the specified service type.
6788
/// </summary>
6889
/// <typeparam name="TService">The type of the service.</typeparam>
6990
/// <returns>
70-
/// The service mock.
91+
/// The service mock.
7192
/// </returns>
7293
public Mock<TService> Mock<TService>() where TService : class
7394
{
74-
TService service = Try.Get(Create<TService>);
95+
return Mock<TService>(_defaultBehavior);
96+
}
97+
98+
/// <summary>
99+
/// Retrieves the mock for the specified service type.
100+
/// </summary>
101+
/// <typeparam name="TService">The type of the service.</typeparam>
102+
/// <param name="mockBehavior">
103+
/// The <see cref="MockBehavior" /> of the mock.
104+
/// </param>
105+
/// <returns>
106+
/// The service mock.
107+
/// </returns>
108+
public Mock<TService> Mock<TService>(MockBehavior mockBehavior) where TService : class
109+
{
110+
TService service = Try.Get<TService>(Create<TService>);
75111
var existingMock = service as IMocked<TService>;
76112
if (existingMock != null) return existingMock.Mock;
77113

78-
Mock<TService> mock = MoqRegistrationSource.Repository.Create<TService>();
114+
Mock<TService> mock = _registrationSource.Repository.Create<TService>(mockBehavior);
79115
Update(mock.Object);
80116
return mock;
81117
}
82118

83119
/// <summary>
84-
/// Creates an instance of the specified service, injecting mocked objects
85-
/// for all unregistered dependencies.
120+
/// Creates an instance of the specified service, injecting mocked objects
121+
/// for all unregistered dependencies.
86122
/// </summary>
87123
/// <typeparam name="TService">The type of the service.</typeparam>
88124
/// <returns>
89-
/// The service instance.
125+
/// The service instance.
90126
/// </returns>
91127
public TService Create<TService>() where TService : class
92128
{
93129
return Container.Resolve<TService>();
94130
}
95131

96132
/// <summary>
97-
/// Creates an instance of the specified implementation (as the specified service),
98-
/// injecting mocked objects for all unregistered dependencies.
133+
/// Creates an instance of the specified implementation (as the specified service),
134+
/// injecting mocked objects for all unregistered dependencies.
99135
/// </summary>
100136
/// <typeparam name="TService">The type of the service.</typeparam>
101137
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
@@ -107,59 +143,59 @@ public TService Create<TService, TImplementation>() where TService : class where
107143
}
108144

109145
/// <summary>
110-
/// Updates this instance by registering the implementation type as the service type.
146+
/// Updates this instance by registering the implementation type as the service type.
111147
/// </summary>
112148
/// <typeparam name="TService">The type of the service.</typeparam>
113149
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
114150
/// <returns>
115-
/// The container.
151+
/// The container.
116152
/// </returns>
117153
public IMoqContainer Update<TService, TImplementation>() where TService : class where TImplementation : TService
118154
{
119155
UpdateWithBuilder(builder => builder.RegisterType<TImplementation>().As<TService>()
120-
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));
156+
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));
121157

122158
return this;
123159
}
124160

125161
/// <summary>
126-
/// Updates this instance by registering an instance of the specified service.
162+
/// Updates this instance by registering an instance of the specified service.
127163
/// </summary>
128164
/// <typeparam name="TService">The type of the service.</typeparam>
129165
/// <param name="instance">The instance.</param>
130166
/// <returns>
131-
/// The container.
167+
/// The container.
132168
/// </returns>
133169
public IMoqContainer Update<TService>(TService instance) where TService : class
134170
{
135171
UpdateWithBuilder(builder => builder.RegisterInstance(instance).As<TService>()
136-
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));
172+
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));
137173

138174
return this;
139175
}
140176

141177
/// <summary>
142-
/// Updates this instance by registering the specified activator as the service type.
178+
/// Updates this instance by registering the specified activator as the service type.
143179
/// </summary>
144180
/// <typeparam name="TService">The type of the service.</typeparam>
145181
/// <param name="activator">The activator.</param>
146182
/// <returns>
147-
/// The container
183+
/// The container
148184
/// </returns>
149185
public IMoqContainer Update<TService>(Func<IMoqContainer, TService> activator) where TService : class
150186
{
151187
UpdateWithBuilder(builder => builder.Register(c => activator(this)).As<TService>()
152-
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));
188+
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));
153189

154190
return this;
155191
}
156192

157193
/// <summary>
158-
/// Updates the container using the specified module.
194+
/// Updates the container using the specified module.
159195
/// </summary>
160196
/// <param name="module">The module.</param>
161197
/// <returns>
162-
/// The container.
198+
/// The container.
163199
/// </returns>
164200
public IAutofacMoqContainer Update(Module module)
165201
{
@@ -168,11 +204,11 @@ public IAutofacMoqContainer Update(Module module)
168204
}
169205

170206
/// <summary>
171-
/// Updates the container using the specified registration.
207+
/// Updates the container using the specified registration.
172208
/// </summary>
173209
/// <param name="registration">The registration.</param>
174210
/// <returns>
175-
/// The container.
211+
/// The container.
176212
/// </returns>
177213
public IAutofacMoqContainer Update(Action<ContainerBuilder> registration)
178214
{

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,35 @@ namespace Patterns.Testing.Autofac.Moq
2020
public class MoqRegistrationSource : IRegistrationSource
2121
{
2222
private static readonly ILog _log = LogManager.GetLogger(typeof (MoqRegistrationSource));
23-
private static readonly MockRepository _repository = new MockRepository(MockBehavior.Default);
24-
private static readonly MethodInfo _createMethod = typeof(MoqRegistrationSource)
25-
.GetMethod("CreateUsingRepository", BindingFlags.NonPublic | BindingFlags.Instance)
26-
.GetGenericMethodDefinition();
23+
private static readonly MethodInfo _createMethod = typeof (MoqRegistrationSource)
24+
.GetMethod("CreateUsingRepository", BindingFlags.NonPublic | BindingFlags.Instance)
25+
.GetGenericMethodDefinition();
26+
27+
private readonly MockRepository _repository;
28+
29+
/// <summary>
30+
/// Initializes an instance of <see cref="MoqRegistrationSource" /> with the specified <see cref="MockBehavior"/> behavior.
31+
/// </summary>
32+
/// <param name="defaultBehavior">The default <see cref="MockBehavior"/>.</param>
33+
public MoqRegistrationSource(MockBehavior defaultBehavior)
34+
{
35+
_repository = new MockRepository(defaultBehavior);
36+
}
37+
38+
/// <summary>
39+
/// Initializes an instance of <see cref="MoqRegistrationSource" /> with the <see cref="MockBehavior.Default"/> behavior.
40+
/// </summary>
41+
public MoqRegistrationSource() : this(MockBehavior.Default)
42+
{
43+
}
2744

2845
/// <summary>
2946
/// Gets the repository.
3047
/// </summary>
3148
/// <value>
3249
/// The repository.
3350
/// </value>
34-
public static MockRepository Repository { get { return _repository; } }
51+
public MockRepository Repository { get { return _repository; } }
3552

3653
/// <summary>
3754
/// Retrieve registrations for an unregistered service, to be used

0 commit comments

Comments
 (0)