Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Remove impls of uncallable SetupSet, VerifySet
Browse files Browse the repository at this point in the history
There used to be overloads of `SetupSet` and `VerifySet` that accepted
two `Expression`s (one selecting the property, the other specifiying a
value for it) instead of a single `Action`. These have since been
marked as `[Obsolete(..., error: true)]`, which means client code that
tries to call them triggers a compile-time error.

Since the methods are in fact no longer callable, we can remove their
implementations and all code that's exclusively used by them.
  • Loading branch information
stakx committed Aug 23, 2018
1 parent 631550c commit e4fa35f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/Moq/Linq/Mocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static IQueryable<T> Of<T>(Expression<Func<T, bool>> specification) where
[Obsolete("Moved to Mock.Of<T>, as it's a single one, so no reason to be on Mocks.", true)]
public static T OneOf<T>() where T : class
{
return Mock.Of<T>();
throw new NotSupportedException();
}

/// <summary>
Expand All @@ -108,7 +108,7 @@ public static T OneOf<T>() where T : class
[Obsolete("Moved to Mock.Of<T>, as it's a single one, so no reason to be on Mocks.", true)]
public static T OneOf<T>(Expression<Func<T, bool>> specification) where T : class
{
return Mock.Of<T>(specification);
throw new NotSupportedException();
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/Moq/Obsolete/Mock.Generic.Legacy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public ISetupSetter<T, TProperty> ExpectSet<TProperty>(Expression<Func<T, TPrope
[EditorBrowsable(EditorBrowsableState.Never)]
public ISetupSetter<T, TProperty> ExpectSet<TProperty>(Expression<Func<T, TProperty>> expression, TProperty value)
{
return Mock.SetupSet(this, expression, value);
throw new NotSupportedException();
}
}

Expand All @@ -120,7 +120,7 @@ public static class MockLegacyExtensions
public static ISetupSetter<T, TProperty> SetupSet<T, TProperty>(this Mock<T> mock, Expression<Func<T, TProperty>> expression, TProperty value)
where T : class
{
return Mock.SetupSet(mock, expression, value);
throw new NotSupportedException();
}

/// <summary>
Expand All @@ -131,7 +131,7 @@ public static ISetupSetter<T, TProperty> SetupSet<T, TProperty>(this Mock<T> moc
public static void VerifySet<T, TProperty>(this Mock<T> mock, Expression<Func<T, TProperty>> expression, TProperty value)
where T : class
{
Mock.VerifySet(mock, expression, value, Times.AtLeastOnce(), null);
throw new NotSupportedException();
}

/// <summary>
Expand All @@ -142,7 +142,7 @@ public static void VerifySet<T, TProperty>(this Mock<T> mock, Expression<Func<T,
public static void VerifySet<T, TProperty>(this Mock<T> mock, Expression<Func<T, TProperty>> expression, TProperty value, string failMessage)
where T : class
{
Mock.VerifySet(mock, expression, value, Times.AtLeastOnce(), failMessage);
throw new NotSupportedException();
}
}
}
38 changes: 0 additions & 38 deletions src/Moq/Obsolete/Mock.Legacy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,6 @@ namespace Moq
// Keeps legacy implementations.
public partial class Mock
{
[Obsolete]
internal static SetterMethodCall<T, TProperty> SetupSet<T, TProperty>(
Mock mock,
Expression<Func<T, TProperty>> expression, TProperty value)
where T : class
{
var prop = expression.ToPropertyInfo();
Guard.CanWrite(prop);

var setter = prop.SetMethod;
ThrowIfSetupExpressionInvolvesUnsupportedMember(expression, setter);

var setup = new SetterMethodCall<T, TProperty>(mock, expression, setter, value);
var targetMock = GetTargetMock(((MemberExpression)expression.Body).Expression, mock);
targetMock.Setups.Add(setup);

return setup;
}

[Obsolete]
internal static void VerifySet<T, TProperty>(
Mock mock,
Expand All @@ -82,24 +63,5 @@ internal static void VerifySet<T, TProperty>(
};
VerifyCalls(GetTargetMock(((MemberExpression)expression.Body).Expression, mock), expected, expression, times);
}

[Obsolete]
internal static void VerifySet<T, TProperty>(
Mock mock,
Expression<Func<T, TProperty>> expression,
TProperty value,
Times times,
string failMessage)
where T : class
{
var method = expression.ToPropertyInfo().SetMethod;
ThrowIfVerifyExpressionInvolvesUnsupportedMember(expression, method);

var expected = new SetterMethodCall<T, TProperty>(mock, expression, method, value)
{
FailMessage = failMessage
};
VerifyCalls(GetTargetMock(((MemberExpression)expression.Body).Expression, mock), expected, expression, times);
}
}
}
5 changes: 0 additions & 5 deletions src/Moq/SetterMethodCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ public SetterMethodCall(Mock mock, LambdaExpression originalExpression, MethodIn
{
}

public SetterMethodCall(Mock mock, LambdaExpression originalExpression, MethodInfo method, TProperty value)
: base(mock, null, originalExpression, method, new[] { ItExpr.Is<TProperty>(arg => Object.Equals(arg, value)) })
{
}

public SetterMethodCall(Mock mock, Condition condition, LambdaExpression originalExpression, MethodInfo method, Expression value)
: base(mock, condition, originalExpression, method, new[] { value })
{
Expand Down

0 comments on commit e4fa35f

Please sign in to comment.