Skip to content

Commit acbbe61

Browse files
committed
Revert binary backward-incompatible changes
* bf19ad6: Make `Mock.Object` non-virtual * ccf9a02: Remove yet another superfluous extension method class * 49a2ccf: Rename extension method for `mock.Protected()` * 41ef023: Put async extension methods in `AsyncExtensions` * 8aacd8b: Remove superfluous extension methods * f605bfe: Fix name of class gen'd by `ReturnsExtensions.tt` * 6fadc8f: Merge `ObsoleteMockExtensions` into `MockExtensions` * 0cbdd87: Convert `Expect*` methods into extension methods * 0669d43: Remove redundant class `MockLegacyExtensions` * 85e0e7d: `MockFactory` <--> `MockRepository` Those would be completely fine for people relying on Moq directly, as they could simply recompile their code. However, for anyone using Moq through a 3rd-party library that was compiled against an earlier ver- sion, they break user code due to binary incompatibility. Forcing all 3rd-party libs to recompile and republish without protecting them with a semver major version increase is perhaps asking a bit much. :)
1 parent 3d7ac8c commit acbbe61

21 files changed

+869
-653
lines changed

src/Moq/AsInterface.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public override DefaultValueProvider DefaultValueProvider
5050

5151
internal override Type[] InheritedInterfaces => this.owner.InheritedInterfaces;
5252

53+
public override TInterface Object
54+
{
55+
get { return this.owner.Object as TInterface; }
56+
}
57+
5358
internal override SetupCollection Setups => this.owner.Setups;
5459

5560
public override Switches Switches
@@ -65,7 +70,10 @@ public override Mock<TNewInterface> As<TNewInterface>()
6570
return this.owner.As<TNewInterface>();
6671
}
6772

68-
protected internal override object OnGetObject() => this.owner.OnGetObject();
73+
protected override object OnGetObject()
74+
{
75+
return this.owner.Object;
76+
}
6977

7078
public override string ToString()
7179
{

src/Moq/DefaultValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public enum DefaultValue
3434
/// are represented by this enumeration value.
3535
/// </para>
3636
/// <para>
37-
/// Do not set <see cref="Mock.DefaultValue"/> (nor <see cref="MockRepository.DefaultValue"/>) to this value.
37+
/// Do not set <see cref="Mock.DefaultValue"/> (nor <see cref="MockFactory.DefaultValue"/>) to this value.
3838
/// If you want to set up a custom default value generation strategy, set <see cref="Mock.DefaultValueProvider"/>
39-
/// or <see cref="MockRepository.DefaultValueProvider"/> instead.
39+
/// or <see cref="MockFactory.DefaultValueProvider"/> instead.
4040
/// </para>
4141
/// </summary>
4242
/// <remarks>

src/Moq/Mock.Generic.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ public override DefaultValueProvider DefaultValueProvider
183183
/// <include file='Mock.Generic.xdoc' path='docs/doc[@for="Mock{T}.Object"]/*'/>
184184
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Object", Justification = "Exposes the mocked object instance, so it's appropriate.")]
185185
[SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods", Justification = "The public Object property is the only one visible to Moq consumers. The protected member is for internal use only.")]
186-
public new T Object => (T)this.OnGetObject();
186+
public virtual new T Object
187+
{
188+
get { return (T)base.Object; }
189+
}
187190

188191
/// <include file='Mock.Generic.xdoc' path='docs/doc[@for="Mock{T}.Name"]/*'/>
189192
public string Name
@@ -198,25 +201,30 @@ public override string ToString()
198201
return this.Name;
199202
}
200203

204+
private void InitializeInstance()
205+
{
206+
// Determine the set of interfaces that the proxy object should additionally implement.
207+
var additionalInterfaceCount = this.AdditionalInterfaces.Count;
208+
var interfaces = new Type[1 + additionalInterfaceCount];
209+
interfaces[0] = typeof(IMocked<T>);
210+
this.AdditionalInterfaces.CopyTo(0, interfaces, 1, additionalInterfaceCount);
211+
212+
this.instance = (T)ProxyFactory.Instance.CreateProxy(
213+
typeof(T),
214+
this,
215+
interfaces,
216+
this.constructorArguments);
217+
}
218+
201219
/// <summary>
202220
/// Returns the mocked object value.
203221
/// </summary>
204222
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "This is actually the protected virtual implementation of the property Object.")]
205-
protected internal override object OnGetObject()
223+
protected override object OnGetObject()
206224
{
207225
if (this.instance == null)
208226
{
209-
// Determine the set of interfaces that the proxy object should additionally implement.
210-
var additionalInterfaceCount = this.AdditionalInterfaces.Count;
211-
var interfaces = new Type[1 + additionalInterfaceCount];
212-
interfaces[0] = typeof(IMocked<T>);
213-
this.AdditionalInterfaces.CopyTo(0, interfaces, 1, additionalInterfaceCount);
214-
215-
this.instance = (T)ProxyFactory.Instance.CreateProxy(
216-
typeof(T),
217-
this,
218-
interfaces,
219-
this.constructorArguments);
227+
this.InitializeInstance();
220228
}
221229

222230
return this.instance;

src/Moq/Mock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public DefaultValue DefaultValue
163163

164164
/// <include file='Mock.xdoc' path='docs/doc[@for="Mock.OnGetObject"]/*'/>
165165
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "This is actually the protected virtual implementation of the property Object.")]
166-
protected internal abstract object OnGetObject();
166+
protected abstract object OnGetObject();
167167

168168
/// <summary>
169169
/// Retrieves the type of the mocked object, its generic type argument.

src/Moq/MockException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ internal static MockException FromInnerMockOf(Setup setup, MockException error)
189189
/// <summary>
190190
/// Returns an exception whose message is the concatenation of the given <paramref name="errors"/>' messages
191191
/// and whose reason(s) is the combination of the given <paramref name="errors"/>' reason(s).
192-
/// Used by <see cref="MockRepository.VerifyMocks(Action{Mock})"/> when it finds one or more mocks with verification errors.
192+
/// Used by <see cref="MockFactory.VerifyMocks(Action{Mock})"/> when it finds one or more mocks with verification errors.
193193
/// </summary>
194194
internal static MockException Combined(IEnumerable<MockException> errors, string preamble)
195195
{

src/Moq/MockExtensions.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
using System.ComponentModel;
55

6-
using Moq.Language;
7-
86
namespace Moq
97
{
108
/// <summary>
@@ -13,17 +11,6 @@ namespace Moq
1311
[EditorBrowsable(EditorBrowsableState.Never)]
1412
public static partial class MockExtensions
1513
{
16-
/// <summary>
17-
/// Perform an expectation in the trace.
18-
/// </summary>
19-
public static ISetupConditionResult<T> InSequence<T>(this Mock<T> mock, MockSequence sequence)
20-
where T : class
21-
{
22-
Guard.NotNull(sequence, nameof(sequence));
23-
24-
return sequence.For(mock);
25-
}
26-
2714
/// <summary>
2815
/// Resets this mock's state. This includes its setups, configured default return values, registered event handlers, and all recorded invocations.
2916
/// </summary>

0 commit comments

Comments
 (0)