Skip to content

Commit

Permalink
Merge pull request #137 from TheTribe/release/3.10-beta.5
Browse files Browse the repository at this point in the history
Release/3.10-beta.5
  • Loading branch information
jbatte47 committed Dec 8, 2013
2 parents fc7f668 + 7c81348 commit ba9a87e
Show file tree
Hide file tree
Showing 34 changed files with 785 additions and 230 deletions.
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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

## 3.10-beta.5 ##

- Dropped reference to Reactive Extensions ([issue 123](https://github.com/TheTribe/code-patterns/issues/123))
- Updated MappingServices to use underlying types for collections ([issue 126](https://github.com/TheTribe/code-patterns/issues/126))
- Added support for overriding mock behavior in `IMoqContainer` ([issue 125](https://github.com/TheTribe/code-patterns/issues/125))
- Fixed TimeExtensions feature bug ([issue 129](https://github.com/TheTribe/code-patterns/issues/129))
- Added new `Proceed` pointcut to `DelegateInterceptor` ([issue 135](https://github.com/TheTribe/code-patterns/issues/135))

## 3.10-beta.4 ##

- Fixes for `IMoqContainer` ([issue 114](https://github.com/TheTribe/code-patterns/issues/114))
Expand Down
1 change: 0 additions & 1 deletion src/.nuget/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NuGetPowerTools" version="0.29" />
<package id="Rx-Main" version="2.1.30214.0" />
</packages>
17 changes: 5 additions & 12 deletions src/Patterns.Autofac/Logging/LoggingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

using System;
using System.Linq;
using System.Reactive.Linq;

using Autofac;
using Autofac.Core;
using Autofac.Core.Registration;
Expand Down Expand Up @@ -82,16 +80,11 @@ protected override void Load(ContainerBuilder builder)

protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
{
Observable.FromEventPattern<PreparingEventArgs>(handler => registration.Preparing += handler, handler => registration.Preparing -= handler)
.Subscribe(@event =>
{
PreparingEventArgs args = @event.EventArgs;
args.Parameters = args.Parameters.Concat(new[]
{
new ResolvedParameter((info, context) => info.ParameterType == typeof (ILog),
(info, context) => _logFactory(info.Member.DeclaringType))
});
});
registration.Preparing += (sender, args) => args.Parameters = args.Parameters.Concat(new[]
{
new ResolvedParameter((info, context) => info.ParameterType == typeof (ILog),
(info, context) => _logFactory(info.Member.DeclaringType))
});
}
}
}
34 changes: 14 additions & 20 deletions src/Patterns.Autofac/Patterns.Autofac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@
<ItemGroup>
<Reference Include="Autofac, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Autofac.3.1.1\lib\net40\Autofac.dll</HintPath>
<HintPath>..\packages\Autofac.3.1.5\lib\net40\Autofac.dll</HintPath>
</Reference>
<Reference Include="AutoMapper">
<HintPath>..\packages\AutoMapper.2.2.1\lib\net40\AutoMapper.dll</HintPath>
<Reference Include="AutoMapper, Version=3.1.0.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\AutoMapper.3.1.0\lib\net40\AutoMapper.dll</HintPath>
</Reference>
<Reference Include="AutoMapper.Net4">
<HintPath>..\packages\AutoMapper.3.1.0\lib\net40\AutoMapper.Net4.dll</HintPath>
</Reference>
<Reference Include="Castle.Core, Version=3.2.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Castle.Core.3.2.0\lib\net40-client\Castle.Core.dll</HintPath>
<HintPath>..\packages\Castle.Core.3.2.2\lib\net40-client\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Common.Logging, Version=2.1.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand All @@ -53,22 +57,6 @@
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Reactive.Core, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Rx-Core.2.1.30214.0\lib\Net40\System.Reactive.Core.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Interfaces, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Rx-Interfaces.2.1.30214.0\lib\Net40\System.Reactive.Interfaces.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.Linq, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Rx-Linq.2.1.30214.0\lib\Net40\System.Reactive.Linq.dll</HintPath>
</Reference>
<Reference Include="System.Reactive.PlatformServices, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Rx-PlatformServices.2.1.30214.0\lib\Net40\System.Reactive.PlatformServices.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -129,6 +117,12 @@
<LastGenOutput>ContainerResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="..\packages\AutoMapper.3.1.0\lib\net40\AutoMapper.Net4.dll">
<Link>AutoMapper.Net4.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
11 changes: 3 additions & 8 deletions src/Patterns.Autofac/packages.config
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.1.1" targetFramework="net40" />
<package id="AutoMapper" version="2.2.1" targetFramework="net40" />
<package id="Castle.Core" version="3.2.0" targetFramework="net40" />
<package id="Autofac" version="3.1.5" targetFramework="net40" />
<package id="AutoMapper" version="3.1.0" targetFramework="net40" />
<package id="Castle.Core" version="3.2.2" targetFramework="net40" />
<package id="Common.Logging" version="2.1.2" targetFramework="net40" />
<package id="Rx-Core" version="2.1.30214.0" targetFramework="net40" />
<package id="Rx-Interfaces" version="2.1.30214.0" targetFramework="net40" />
<package id="Rx-Linq" version="2.1.30214.0" targetFramework="net40" />
<package id="Rx-Main" version="2.1.30214.0" targetFramework="net40" />
<package id="Rx-PlatformServices" version="2.1.30214.0" targetFramework="net40" />
</packages>
106 changes: 71 additions & 35 deletions src/Patterns.Testing.Autofac/Moq/AutofacMoqContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,82 +20,118 @@
#endregion

using System;

using System.Collections.Generic;
using Autofac;
using Autofac.Core;
using Autofac.Extras.CommonServiceLocator;

using Microsoft.Practices.ServiceLocation;

using Moq;

using Patterns.Autofac;
using Patterns.ExceptionHandling;
using Patterns.Testing.Moq;

namespace Patterns.Testing.Autofac.Moq
{
/// <summary>
/// Provides a default implementation of the <see cref="IAutofacMoqContainer" /> interface.
/// Provides a default implementation of the <see cref="IAutofacMoqContainer" /> interface.
/// </summary>
public sealed class AutofacMoqContainer : AccessibleContainer, IAutofacMoqContainer
{
private readonly MockBehavior _defaultBehavior;
private readonly MoqRegistrationSource _registrationSource;

/// <summary>
/// Initializes a new instance of the <see cref="AutofacMoqContainer" /> class.
/// Initializes a new instance of the <see cref="AutofacMoqContainer" /> class with
/// </summary>
/// <param name="container">The container.</param>
public AutofacMoqContainer(IContainer container) : base(container)
/// <param name="defaultBehavior">The default <see cref="MockBehavior"/>.</param>
public AutofacMoqContainer(IContainer container, MockBehavior behavior) : base(container)
{
_defaultBehavior = behavior;
Locator = new AutofacServiceLocator(this);
ComponentRegistry.AddRegistrationSource(new MoqRegistrationSource());
ComponentRegistry.AddRegistrationSource(_registrationSource = new MoqRegistrationSource(_defaultBehavior));
}

/// <summary>
/// Initializes a new instance of the <see cref="AutofacMoqContainer" /> class.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="defaultBehavior">The default <see cref="MockBehavior"/>.</param>
public AutofacMoqContainer(IContainer container) : this(container, MockBehavior.Default)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="AutofacMoqContainer" /> class.
/// Initializes a new instance of the <see cref="AutofacMoqContainer" /> class.
/// </summary>
public AutofacMoqContainer() : this(new ContainerBuilder().Build()) {}
public AutofacMoqContainer() : this(new ContainerBuilder().Build())
{
}

/// <summary>
/// Gets the locator.
/// Gets the default <see cref="MockBehavior"/>.
/// </summary>
/// <value>
/// The locator.
/// The default <see cref="MockBehavior"/>.
/// </value>
public MockBehavior DefaultBehavior { get { return _defaultBehavior; } }

/// <summary>
/// Gets the locator.
/// </summary>
/// <value>
/// The locator.
/// </value>
public IServiceLocator Locator { get; private set; }

/// <summary>
/// Retrieves the mock for the specified service type.
/// Retrieves the mock for the specified service type.
/// </summary>
/// <typeparam name="TService">The type of the service.</typeparam>
/// <returns>
/// The service mock.
/// The service mock.
/// </returns>
public Mock<TService> Mock<TService>() where TService : class
{
TService service = Try.Get(Create<TService>);
return Mock<TService>(_defaultBehavior);
}

/// <summary>
/// Retrieves the mock for the specified service type.
/// </summary>
/// <typeparam name="TService">The type of the service.</typeparam>
/// <param name="mockBehavior">
/// The <see cref="MockBehavior" /> of the mock.
/// </param>
/// <returns>
/// The service mock.
/// </returns>
public Mock<TService> Mock<TService>(MockBehavior mockBehavior) where TService : class
{
TService service = Try.Get<TService>(Create<TService>);
var existingMock = service as IMocked<TService>;
if (existingMock != null) return existingMock.Mock;

Mock<TService> mock = MoqRegistrationSource.Repository.Create<TService>();
Mock<TService> mock = _registrationSource.Repository.Create<TService>(mockBehavior);
Update(mock.Object);
return mock;
}

/// <summary>
/// Creates an instance of the specified service, injecting mocked objects
/// for all unregistered dependencies.
/// Creates an instance of the specified service, injecting mocked objects
/// for all unregistered dependencies.
/// </summary>
/// <typeparam name="TService">The type of the service.</typeparam>
/// <returns>
/// The service instance.
/// The service instance.
/// </returns>
public TService Create<TService>() where TService : class
{
return Container.Resolve<TService>();
}

/// <summary>
/// Creates an instance of the specified implementation (as the specified service),
/// injecting mocked objects for all unregistered dependencies.
/// Creates an instance of the specified implementation (as the specified service),
/// injecting mocked objects for all unregistered dependencies.
/// </summary>
/// <typeparam name="TService">The type of the service.</typeparam>
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
Expand All @@ -107,59 +143,59 @@ public AutofacMoqContainer(IContainer container) : base(container)
}

/// <summary>
/// Updates this instance by registering the implementation type as the service type.
/// Updates this instance by registering the implementation type as the service type.
/// </summary>
/// <typeparam name="TService">The type of the service.</typeparam>
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
/// <returns>
/// The container.
/// The container.
/// </returns>
public IMoqContainer Update<TService, TImplementation>() where TService : class where TImplementation : TService
{
UpdateWithBuilder(builder => builder.RegisterType<TImplementation>().As<TService>()
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));

return this;
}

/// <summary>
/// Updates this instance by registering an instance of the specified service.
/// Updates this instance by registering an instance of the specified service.
/// </summary>
/// <typeparam name="TService">The type of the service.</typeparam>
/// <param name="instance">The instance.</param>
/// <returns>
/// The container.
/// The container.
/// </returns>
public IMoqContainer Update<TService>(TService instance) where TService : class
{
UpdateWithBuilder(builder => builder.RegisterInstance(instance).As<TService>()
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));

return this;
}

/// <summary>
/// Updates this instance by registering the specified activator as the service type.
/// Updates this instance by registering the specified activator as the service type.
/// </summary>
/// <typeparam name="TService">The type of the service.</typeparam>
/// <param name="activator">The activator.</param>
/// <returns>
/// The container
/// The container
/// </returns>
public IMoqContainer Update<TService>(Func<IMoqContainer, TService> activator) where TService : class
{
UpdateWithBuilder(builder => builder.Register(c => activator(this)).As<TService>()
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues));

return this;
}

/// <summary>
/// Updates the container using the specified module.
/// Updates the container using the specified module.
/// </summary>
/// <param name="module">The module.</param>
/// <returns>
/// The container.
/// The container.
/// </returns>
public IAutofacMoqContainer Update(Module module)
{
Expand All @@ -168,11 +204,11 @@ public IAutofacMoqContainer Update(Module module)
}

/// <summary>
/// Updates the container using the specified registration.
/// Updates the container using the specified registration.
/// </summary>
/// <param name="registration">The registration.</param>
/// <returns>
/// The container.
/// The container.
/// </returns>
public IAutofacMoqContainer Update(Action<ContainerBuilder> registration)
{
Expand Down
27 changes: 22 additions & 5 deletions src/Patterns.Testing.Autofac/Moq/MoqRegistrationSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,35 @@ namespace Patterns.Testing.Autofac.Moq
public class MoqRegistrationSource : IRegistrationSource
{
private static readonly ILog _log = LogManager.GetLogger(typeof (MoqRegistrationSource));
private static readonly MockRepository _repository = new MockRepository(MockBehavior.Default);
private static readonly MethodInfo _createMethod = typeof(MoqRegistrationSource)
.GetMethod("CreateUsingRepository", BindingFlags.NonPublic | BindingFlags.Instance)
.GetGenericMethodDefinition();
private static readonly MethodInfo _createMethod = typeof (MoqRegistrationSource)
.GetMethod("CreateUsingRepository", BindingFlags.NonPublic | BindingFlags.Instance)
.GetGenericMethodDefinition();

private readonly MockRepository _repository;

/// <summary>
/// Initializes an instance of <see cref="MoqRegistrationSource" /> with the specified <see cref="MockBehavior"/> behavior.
/// </summary>
/// <param name="defaultBehavior">The default <see cref="MockBehavior"/>.</param>
public MoqRegistrationSource(MockBehavior defaultBehavior)
{
_repository = new MockRepository(defaultBehavior);
}

/// <summary>
/// Initializes an instance of <see cref="MoqRegistrationSource" /> with the <see cref="MockBehavior.Default"/> behavior.
/// </summary>
public MoqRegistrationSource() : this(MockBehavior.Default)
{
}

/// <summary>
/// Gets the repository.
/// </summary>
/// <value>
/// The repository.
/// </value>
public static MockRepository Repository { get { return _repository; } }
public MockRepository Repository { get { return _repository; } }

/// <summary>
/// Retrieve registrations for an unregistered service, to be used
Expand Down
Loading

0 comments on commit ba9a87e

Please sign in to comment.