Skip to content

Commit c9e9178

Browse files
committed
Merge branch 'release/3.9.0'
2 parents b2a45c7 + 4301cd6 commit c9e9178

22 files changed

Lines changed: 1075 additions & 86 deletions

changelog.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
## Patterns Changelog ##
22

3+
**3.9.0**
4+
5+
- Added `Patterns.Collections.ConfigurableEqualityComparer<TValue>` (Issue #66)
6+
- Fixed type casting error in `Patterns.Testing.Autofac.Moq.AutofacMoqContainer` (Issue #67)
7+
- Fixed issue with up-front service type inspection in `Patterns.Testing.Autofac.Moq.MoqRegistrationSource` (Issue #68)
8+
- Added `IRegexEvaluator` and `RegexEvaluator` to the `Patterns.Text.RegularExpressions` namespace (Issue #69)
9+
- Added `Evaluator` and `EvaluatorAccessor` to `System.Text.RegularExpressions.CompiledRegex` (Issue #70)
10+
- Added `Patterns.Runtime.TemporaryScope`
11+
- Added `ActionValueStrategies<TValue>`
12+
- Added `FuncValueStrategies<TValue, TOut>`
13+
14+
**3.8.1** - Expanded capabilities of `Patterns.Mapping.IMappingServices` (issue #65)
15+
316
**3.8.0**
417

518
- Renamed `Patterns.Autofac.Sources.ResolveAnythingSource` to `Patterns.Autofac.Sources.ResolveCreatableSource` (issue #43)

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
namespace Patterns.Testing.Autofac.Moq
3535
{
3636
/// <summary>
37-
/// Provides a default implementation of the <see cref="IMoqContainer" /> interface.
37+
/// Provides a default implementation of the <see cref="IAutofacMoqContainer" /> interface.
3838
/// </summary>
3939
public sealed class AutofacMoqContainer : AccessibleContainer, IAutofacMoqContainer
4040
{
@@ -70,8 +70,13 @@ public AutofacMoqContainer() : this(new ContainerBuilder().Build()) {}
7070
/// </returns>
7171
public Mock<TService> Mock<TService>() where TService : class
7272
{
73-
var obj = (IMocked<TService>) Create<TService>();
74-
return obj.Mock;
73+
var service = Create<TService>();
74+
var existingMock = service as IMocked<TService>;
75+
if (existingMock != null) return existingMock.Mock;
76+
77+
var mock = MoqRegistrationSource.Repository.Create<TService>();
78+
Update(mock.Object);
79+
return mock;
7580
}
7681

7782
/// <summary>
@@ -85,13 +90,11 @@ public Mock<TService> Mock<TService>() where TService : class
8590
/// </returns>
8691
public TService Create<TService>(Func<IMoqContainer, TService> activator = null) where TService : class
8792
{
88-
Action<ContainerBuilder> defaultRegistration = builder => builder.RegisterType<TService>()
89-
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues);
90-
91-
Action<ContainerBuilder> activatorRegistration = builder => builder.Register(c => activator(this))
92-
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues);
93-
94-
return ResolveOrCreate<TService>(activator == null ? defaultRegistration : activatorRegistration);
93+
return ResolveOrCreate<TService>(activator == null
94+
? (builder => builder.RegisterType<TService>()
95+
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues))
96+
: (Action<ContainerBuilder>) (builder => builder.Register(c => activator(this))
97+
.PropertiesAutowired(PropertyWiringOptions.PreserveSetValues)));
9598
}
9699

97100
/// <summary>

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,33 @@
66
using Autofac.Builder;
77
using Autofac.Core;
88

9+
using Common.Logging;
10+
911
using Moq;
1012

13+
using Patterns.Testing.Autofac.Properties;
14+
1115
namespace Patterns.Testing.Autofac.Moq
1216
{
1317
/// <summary>
1418
/// Provides a registration source for Autofac using Moq's MockRepository as a service factory.
1519
/// </summary>
1620
public class MoqRegistrationSource : IRegistrationSource
1721
{
22+
private static readonly ILog _log = LogManager.GetLogger(typeof (MoqRegistrationSource));
1823
private static readonly MockRepository _repository = new MockRepository(MockBehavior.Default);
1924
private static readonly MethodInfo _createMethod = typeof(MoqRegistrationSource)
2025
.GetMethod("CreateUsingRepository", BindingFlags.NonPublic | BindingFlags.Instance)
2126
.GetGenericMethodDefinition();
2227

28+
/// <summary>
29+
/// Gets the repository.
30+
/// </summary>
31+
/// <value>
32+
/// The repository.
33+
/// </value>
34+
public static MockRepository Repository { get { return _repository; } }
35+
2336
/// <summary>
2437
/// Retrieve registrations for an unregistered service, to be used
2538
/// by the container.
@@ -41,13 +54,18 @@ public IEnumerable<IComponentRegistration> RegistrationsFor(Service service, Fun
4154
{
4255
if (service == null) throw new ArgumentNullException("service");
4356

57+
_log.Info(format => format(Resources.MoqRegistrationSource_RegistrationsFor_InfoFormat, service.Description));
58+
4459
IComponentRegistration[] existingRegistrations = registrationAccessor(service).ToArray();
4560
if (existingRegistrations.Length > 0) return existingRegistrations;
4661

4762
var typedService = service as TypedService;
48-
return typedService == null
49-
? Enumerable.Empty<IComponentRegistration>()
50-
: new[]
63+
bool canMock = typedService != null && (typedService.ServiceType.IsInterface || typedService.ServiceType.IsAbstract || !typedService.ServiceType.IsSealed);
64+
65+
if (canMock)
66+
{
67+
_log.Debug(format => format(Resources.MoqRegistrationSource_RegistrationsFor_PreMockCreateFormat, service.Description));
68+
return new[]
5169
{
5270
RegistrationBuilder
5371
.ForDelegate((context, parameters) =>
@@ -60,6 +78,9 @@ public IEnumerable<IComponentRegistration> RegistrationsFor(Service service, Fun
6078
.SingleInstance()
6179
.CreateRegistration()
6280
};
81+
}
82+
83+
return Enumerable.Empty<IComponentRegistration>();
6384
}
6485

6586
/// <summary>

src/Patterns.Testing.Autofac/Patterns.Testing.Autofac.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
<Reference Include="Autofac.Extras.CommonServiceLocator">
4545
<HintPath>..\packages\Autofac.Extras.CommonServiceLocator.3.0.0\lib\net40\Autofac.Extras.CommonServiceLocator.dll</HintPath>
4646
</Reference>
47+
<Reference Include="Common.Logging, Version=2.1.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
48+
<SpecificVersion>False</SpecificVersion>
49+
<HintPath>..\packages\Common.Logging.2.1.2\lib\net40\Common.Logging.dll</HintPath>
50+
</Reference>
4751
<Reference Include="Microsoft.Practices.ServiceLocation">
4852
<HintPath>..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
4953
</Reference>
@@ -66,6 +70,11 @@
6670
<Compile Include="Moq\IAutofacMoqContainer.cs" />
6771
<Compile Include="Moq\MoqRegistrationSource.cs" />
6872
<Compile Include="Properties\AssemblyInfo.cs" />
73+
<Compile Include="Properties\Resources.Designer.cs">
74+
<AutoGen>True</AutoGen>
75+
<DesignTime>True</DesignTime>
76+
<DependentUpon>Resources.resx</DependentUpon>
77+
</Compile>
6978
</ItemGroup>
7079
<ItemGroup>
7180
<None Include="packages.config" />
@@ -92,6 +101,12 @@
92101
<ItemGroup>
93102
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
94103
</ItemGroup>
104+
<ItemGroup>
105+
<EmbeddedResource Include="Properties\Resources.resx">
106+
<Generator>ResXFileCodeGenerator</Generator>
107+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
108+
</EmbeddedResource>
109+
</ItemGroup>
95110
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
96111
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
97112
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

src/Patterns.Testing.Autofac/Properties/Resources.Designer.cs

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 1.3
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">1.3</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1">this is my long string</data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
[base64 mime encoded serialized .NET Framework object]
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
[base64 mime encoded string representing a byte array form of the .NET Framework object]
27+
</data>
28+
29+
There are any number of "resheader" rows that contain simple
30+
name/value pairs.
31+
32+
Each data row contains a name, and value. The row also contains a
33+
type or mimetype. Type corresponds to a .NET class that support
34+
text/value conversion through the TypeConverter architecture.
35+
Classes that don't support this are serialized and stored with the
36+
mimetype set.
37+
38+
The mimetype is used for serialized objects, and tells the
39+
ResXResourceReader how to depersist the object. This is currently not
40+
extensible. For a given mimetype the value must be set accordingly:
41+
42+
Note - application/x-microsoft.net.object.binary.base64 is the format
43+
that the ResXResourceWriter will generate, however the reader can
44+
read any of the formats listed below.
45+
46+
mimetype: application/x-microsoft.net.object.binary.base64
47+
value : The object must be serialized with
48+
: System.Serialization.Formatters.Binary.BinaryFormatter
49+
: and then encoded with base64 encoding.
50+
51+
mimetype: application/x-microsoft.net.object.soap.base64
52+
value : The object must be serialized with
53+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
54+
: and then encoded with base64 encoding.
55+
56+
mimetype: application/x-microsoft.net.object.bytearray.base64
57+
value : The object must be serialized into a byte array
58+
: using a System.ComponentModel.TypeConverter
59+
: and then encoded with base64 encoding.
60+
-->
61+
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:element name="root" msdata:IsDataSet="true">
64+
<xsd:complexType>
65+
<xsd:choice maxOccurs="unbounded">
66+
<xsd:element name="data">
67+
<xsd:complexType>
68+
<xsd:sequence>
69+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
70+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
73+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
74+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
75+
</xsd:complexType>
76+
</xsd:element>
77+
<xsd:element name="resheader">
78+
<xsd:complexType>
79+
<xsd:sequence>
80+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
81+
</xsd:sequence>
82+
<xsd:attribute name="name" type="xsd:string" use="required" />
83+
</xsd:complexType>
84+
</xsd:element>
85+
</xsd:choice>
86+
</xsd:complexType>
87+
</xsd:element>
88+
</xsd:schema>
89+
<resheader name="resmimetype">
90+
<value>text/microsoft-resx</value>
91+
</resheader>
92+
<resheader name="version">
93+
<value>1.3</value>
94+
</resheader>
95+
<resheader name="reader">
96+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
97+
</resheader>
98+
<resheader name="writer">
99+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
100+
</resheader>
101+
<data name="MoqRegistrationSource_RegistrationsFor_InfoFormat" xml:space="preserve">
102+
<value>finding registrations for {0}</value>
103+
</data>
104+
<data name="MoqRegistrationSource_RegistrationsFor_PreMockCreateFormat" xml:space="preserve">
105+
<value>no existing registrations found for {0}; creating with MockRepository</value>
106+
</data>
107+
</root>

src/Patterns.Testing.Autofac/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<packages>
33
<package id="Autofac" version="3.0.1" targetFramework="net45" />
44
<package id="Autofac.Extras.CommonServiceLocator" version="3.0.0" targetFramework="net45" />
5+
<package id="Common.Logging" version="2.1.2" targetFramework="net40" />
56
<package id="CommonServiceLocator" version="1.0" targetFramework="net45" />
67
<package id="Moq" version="4.0.10827" targetFramework="net45" />
78
</packages>

0 commit comments

Comments
 (0)