Skip to content

Commit 42ac99f

Browse files
authored
Merge pull request #4 from johnmwright/jwright/StaticAnalysisFixes
updated based on static analysis (ReSharper and SonarQube)
2 parents acc1688 + 0388ff3 commit 42ac99f

14 files changed

Lines changed: 31 additions & 45 deletions

File tree

‎Fakes.Contrib/Fakes.Contrib.Tests/StubBaseExtensionsTest.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public void WithObserverShouldThrowAnExceptionForNullStub()
1616
IStubObservable stub = null;
1717

1818
// Act
19+
// ReSharper disable once ExpressionIsAlwaysNull
1920
stub.AsObservable();
2021
}
2122

@@ -69,6 +70,7 @@ public void AssertWasCalledShouldThrowAnExceptionForNullStub()
6970
StubBase<object> stub = null;
7071

7172
// Act
73+
// ReSharper disable once ExpressionIsAlwaysNull
7274
stub.AssertWasCalled(mock => mock.ToString());
7375
}
7476

‎Fakes.Contrib/Fakes.Contrib/Collections/Generic/DeepArrayComparer.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DeepArrayComparer : IEqualityComparer<object>
1414

1515
if (x is WithProxyPlaceholder anyPlaceholder && y != null)
1616
{
17-
return anyPlaceholder.ArgType.IsAssignableFrom(y.GetType());
17+
return anyPlaceholder.ArgType.IsInstanceOfType(y);
1818
}
1919

2020
if (x is IEnumerable<object> && y is IEnumerable<object>)

‎Fakes.Contrib/Fakes.Contrib/DynamicProxy/Hooks/InterceptEqualsHook.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void NonProxyableMemberNotification(Type type, MemberInfo memberInfo)
1616

1717
public bool ShouldInterceptMethod(Type type, MethodInfo methodInfo)
1818
{
19-
if (methodInfo == null) throw new ArgumentNullException("methodInfo");
19+
if (methodInfo == null) throw new ArgumentNullException(nameof(methodInfo));
2020

2121
return methodInfo.Name == "Equals";
2222
}

‎Fakes.Contrib/Fakes.Contrib/DynamicProxy/Interceptors/CustomEqualsInterceptor.cs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ internal class CustomEqualsInterceptor<T> : IInterceptor
99

1010
public CustomEqualsInterceptor(Func<T, bool> equals)
1111
{
12-
if (equals == null) throw new ArgumentNullException("equals");
13-
_equals = equals;
12+
_equals = equals ?? throw new ArgumentNullException(nameof(equals));
1413
}
1514

1615
public void Intercept(IInvocation invocation)
1716
{
18-
if (invocation == null) throw new ArgumentNullException("invocation");
17+
if (invocation == null) throw new ArgumentNullException(nameof(invocation));
1918

2019
if (invocation.Method.Name == "Equals")
2120
{

‎Fakes.Contrib/Fakes.Contrib/EnumerableWith.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal class EnumerableWith<TValue> : IEnumerableWith<TValue>
1111

1212
public EnumerableWith(IEnumerable<TValue> source)
1313
{
14-
_source = source;
14+
_source = source;
1515
}
1616

1717
public IEnumerable<TOutput> Like<TOutput>(Func<TValue, TOutput, bool> predicate)

‎Fakes.Contrib/Fakes.Contrib/Extensions/ExpressionExtensions.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ internal static class ExpressionExtensions
77
{
88
public static MethodCallExpression AsMethodCallExpression<T>(this Expression<T> expression)
99
{
10-
if (expression == null) throw new ArgumentNullException("expression");
10+
if (expression == null) throw new ArgumentNullException(nameof(expression));
1111

1212
return expression.Body as MethodCallExpression;
1313
}
1414

1515
public static MemberExpression AsMemberExpression<T>(this Expression<T> expression)
1616
{
17-
if (expression == null) throw new ArgumentNullException("expression");
17+
if (expression == null) throw new ArgumentNullException(nameof(expression));
1818

1919
return expression.Body as MemberExpression;
2020
}

‎Fakes.Contrib/Fakes.Contrib/Extensions/MethodBaseExtensions.cs‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class MethodBaseExtensions
88
{
99
public static bool IsEquivalent(this MethodBase method, MemberExpression expression)
1010
{
11-
if (method == null) throw new ArgumentNullException("method");
11+
if (method == null) throw new ArgumentNullException(nameof(method));
1212

1313
var property = expression.Member as PropertyInfo;
1414

@@ -24,20 +24,12 @@ public static bool IsEquivalent(this MethodBase method, MemberExpression express
2424

2525
public static bool IsEquivalent(this MethodBase method, MethodCallExpression expression)
2626
{
27-
if (method == null) throw new ArgumentNullException("method");
27+
if (method == null) throw new ArgumentNullException(nameof(method));
2828

2929
var isEquivalent = expression.Method == method;
3030

3131
return isEquivalent;
3232
}
33-
34-
private static object GetArgumentValue(Expression expression)
35-
{
36-
var lambda = Expression.Lambda(expression);
37-
var compiledExpression = lambda.Compile();
38-
var value = compiledExpression.DynamicInvoke();
39-
40-
return value;
41-
}
33+
4234
}
4335
}

‎Fakes.Contrib/Fakes.Contrib/Extensions/StubObservedCallExtensions.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ internal static class StubObservedCallExtensions
1414

1515
public static bool IsEquivalent(this StubObservedCall call, MethodCallExpression methodCallExpression)
1616
{
17-
if (call == null) throw new ArgumentNullException("call");
18-
if (methodCallExpression == null) throw new ArgumentNullException("methodCallExpression");
17+
if (call == null) throw new ArgumentNullException(nameof(call));
18+
if (methodCallExpression == null) throw new ArgumentNullException(nameof(methodCallExpression));
1919

2020
if (call.StubbedMethod != methodCallExpression.Method)
2121
{

‎Fakes.Contrib/Fakes.Contrib/Fakes.Contrib.nuspec‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<metadata>
44
<id>Fakes.Contrib</id>
55
<version>$version$</version>
6-
<title>Fakes.Contrib</title>
6+
<title>$title$</title>
77
<authors>Fabian Vilers, John M. Wright</authors>
88
<owners>John M. Wright</owners>
99
<licenseUrl>https://github.com/johnmwright/Fakes.Contrib/blob/master/LICENSE</licenseUrl>
1010
<projectUrl>https://github.com/johnmwright/Fakes.Contrib</projectUrl>
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
12-
<description>This library is a contribution to Microsoft Fakes. It allows tests to verify expectations on mocks with an easy and fluent syntax.</description>
12+
<description>$description$</description>
1313
<releaseNotes>
1414
Version 0.7:
1515
* added support for interface types
@@ -21,7 +21,7 @@ Version 0.4: improved &quot;With&quot; to allow predicate of two different types
2121
Version 0.3: added more flexible ways to verify a mock
2222
Version 0.2: first usable version. Watch out, this is still apha code !
2323
</releaseNotes>
24-
<copyright>Copyright 2013-2018 Fabian Vilers/Dev One, John M. Wright</copyright>
24+
<copyright>$copyright$</copyright>
2525
<tags>fakes tdd mocking mocks unittesting agile contribution</tags>
2626
<dependencies>
2727
<dependency id="Castle.Core" version="3.2.1" />

‎Fakes.Contrib/Fakes.Contrib/Helpers/AssertHelper.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ internal static class AssertHelper
88
{
99
public static void HandleFail([CallerMemberName] string assertionName = null, string message = "", params object[] parameters)
1010
{
11-
var args = String.Format(message ?? "", parameters ?? new object[0]);
12-
var msg = String.Format("{0} failed. {1}", assertionName, args);
11+
var args = string.Format(message ?? "", parameters ?? new object[0]);
12+
var msg = $"{assertionName} failed. {args}";
1313

1414
throw new AssertFailedException(msg);
1515
}

0 commit comments

Comments
 (0)