Skip to content

Commit 835cefd

Browse files
committed
Address build warnings
1 parent 8c010b0 commit 835cefd

10 files changed

+154
-145
lines changed

src/Moq.Tests.VisualBasic/IssueReports.vb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,19 @@ Public Class IssueReports
5959
End Interface
6060

6161
Protected Sub Setup_NonGeneric(userManagerMock As Mock(Of IUserManager), expectedId As Integer)
62+
#Disable Warning BC42020 ' Variable declaration without an 'As' clause
63+
#Disable Warning BC42017 ' Late bound resolution
6264
userManagerMock.Setup(Sub(manager) manager.Create(It.IsAny(Of User))).Callback(Sub(user) user.Id = expectedId)
65+
#Enable Warning BC42017 ' Late bound resolution
66+
#Enable Warning BC42020 ' Variable declaration without an 'As' clause
6367
End Sub
6468

6569
Protected Sub Setup_Generic(Of TUser As User)(userManagerMock As Mock(Of IUserManager), expectedId As Integer)
70+
#Disable Warning BC42020 ' Variable declaration without an 'As' clause
71+
#Disable Warning BC42017 ' Late bound resolution
6672
userManagerMock.Setup(Sub(manager) manager.Create(It.IsAny(Of TUser))).Callback(Sub(user) user.Id = expectedId)
73+
#Enable Warning BC42017 ' Late bound resolution
74+
#Enable Warning BC42020 ' Variable declaration without an 'As' clause
6775
' ^
6876
' The use of generics will cause the VB.NET compiler to wrap the `It.IsAny<>` call with two `Convert` nodes.
6977
' The inner conversion will convert to `Object`, and the outer conversion will convert to `User` (i.e. the type that

src/Moq.Tests/EmptyDefaultValueProviderFixture.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,80 +104,80 @@ public void ProvidesDefaultTask()
104104
}
105105

106106
[Fact]
107-
public void ProvidesDefaultGenericTaskOfValueType()
107+
public async Task ProvidesDefaultGenericTaskOfValueType()
108108
{
109109
var value = GetDefaultValueForProperty(nameof(IFoo.GenericTaskOfValueType));
110110

111111
Assert.NotNull(value);
112112
Assert.True(((Task)value).IsCompleted);
113-
Assert.Equal(default(int), ((Task<int>)value).Result);
113+
Assert.Equal(default(int), await ((Task<int>)value));
114114
}
115115

116116
[Fact]
117-
public void ProvidesDefaultGenericTaskOfReferenceType()
117+
public async Task ProvidesDefaultGenericTaskOfReferenceType()
118118
{
119119
var value = GetDefaultValueForProperty(nameof(IFoo.GenericTaskOfReferenceType));
120120

121121
Assert.NotNull(value);
122122
Assert.True(((Task)value).IsCompleted);
123-
Assert.Equal(default(string), ((Task<string>)value).Result);
123+
Assert.Equal(default(string), await (Task<string>)value);
124124
}
125125

126126
[Fact]
127-
public void ProvidesDefaultTaskOfGenericTask()
127+
public async Task ProvidesDefaultTaskOfGenericTask()
128128
{
129129
var value = GetDefaultValueForProperty(nameof(IFoo.TaskOfGenericTaskOfValueType));
130130

131131
Assert.NotNull(value);
132132
Assert.True(((Task)value).IsCompleted);
133-
Assert.Equal(default(int), ((Task<Task<int>>)value).Result.Result);
133+
Assert.Equal(default(int), await (await (Task<Task<int>>)value));
134134
}
135135

136136
[Fact]
137-
public void ProvidesDefaultValueTaskOfValueType()
137+
public async Task ProvidesDefaultValueTaskOfValueType()
138138
{
139139
var value = GetDefaultValueForProperty(nameof(IFoo.ValueTaskOfValueType));
140140

141141
var result = (ValueTask<int>)value;
142142
Assert.True(result.IsCompleted);
143-
Assert.Equal(default(int), result.Result);
143+
Assert.Equal(default(int), await result);
144144
}
145145

146146
[Fact]
147-
public void ProvidesDefaultValueTaskOfValueTypeArray()
147+
public async Task ProvidesDefaultValueTaskOfValueTypeArray()
148148
{
149149
var value = GetDefaultValueForProperty(nameof(IFoo.ValueTaskOfValueTypeArray));
150150

151151
var result = (ValueTask<int[]>)value;
152152
Assert.True(result.IsCompleted);
153-
Assert.NotNull(result.Result);
154-
Assert.Empty(result.Result);
153+
Assert.NotNull(await result);
154+
Assert.Empty(await result);
155155
}
156156

157157
[Fact]
158-
public void ProvidesDefaultValueTaskOfReferenceType()
158+
public async Task ProvidesDefaultValueTaskOfReferenceType()
159159
{
160160
var value = GetDefaultValueForProperty(nameof(IFoo.ValueTaskOfReferenceType));
161161

162162
var result = (ValueTask<string>)value;
163163
Assert.True(result.IsCompleted);
164-
Assert.Equal(default(string), result.Result);
164+
Assert.Equal(default(string), await result);
165165
}
166166

167167
[Fact]
168-
public void ProvidesDefaultValueTaskOfTaskOfValueType()
168+
public async Task ProvidesDefaultValueTaskOfTaskOfValueType()
169169
{
170170
var value = GetDefaultValueForProperty(nameof(IFoo.ValueTaskOfTaskOfValueType));
171171

172172
var result = (ValueTask<Task<int>>)value;
173173
Assert.True(result.IsCompleted);
174-
Assert.NotNull(result.Result);
175-
Assert.True(result.Result.IsCompleted);
176-
Assert.Equal(default(int), result.Result.Result);
174+
Assert.NotNull(await result);
175+
Assert.True((await result).IsCompleted);
176+
Assert.Equal(default(int), await (await result));
177177
}
178178

179179
[Fact]
180-
public void ProvidesDefaultValueTupleOfReferenceTypeArrayAndTaskOfReferenceType()
180+
public async Task ProvidesDefaultValueTupleOfReferenceTypeArrayAndTaskOfReferenceType()
181181
{
182182
var value = GetDefaultValueForProperty(nameof(IFoo.ValueTupleOfReferenceTypeArrayAndTaskOfReferenceType));
183183

@@ -186,7 +186,7 @@ public void ProvidesDefaultValueTupleOfReferenceTypeArrayAndTaskOfReferenceType(
186186
Assert.Empty(bars);
187187
Assert.NotNull(barTask);
188188
Assert.True(barTask.IsCompleted);
189-
Assert.Equal(default(IBar), barTask.Result);
189+
Assert.Equal(default(IBar), await barTask);
190190
}
191191

192192
static object GetDefaultValueForProperty(string propertyName)

src/Moq.Tests/EventHandlersFixture.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public async Task Can_raise_parameterized_async_event_using_RaiseAsync()
181181

182182
public class HasAsyncEvent
183183
{
184+
#pragma warning disable CS0067 // Event never used
184185
public virtual event Func<Task> Event;
185186
public virtual event Func<int, Task> ParameterizedEvent;
186187
}

src/Moq.Tests/GeneratedReturnsExtensionsFixture.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,79 +19,79 @@ public interface IAsyncInterface
1919
}
2020

2121
[Fact]
22-
public void ReturnsAsync_onSingleParameter_ParameterUsedForCalculationOfTheResult()
22+
public async Task ReturnsAsync_onSingleParameter_ParameterUsedForCalculationOfTheResult()
2323
{
2424
var mock = new Mock<IAsyncInterface>();
2525
mock.Setup(x => x.WithSingleParameterAsync(It.IsAny<int>())).ReturnsAsync((int x) => x * x);
2626

27-
int evaluationResult = mock.Object.WithSingleParameterAsync(2).Result;
27+
int evaluationResult = await mock.Object.WithSingleParameterAsync(2);
2828

2929
Assert.Equal(4, evaluationResult);
3030
}
3131

3232
[Fact]
33-
public void ReturnsAsync_onSingleParameter_LazyEvaluationOfTheResult()
33+
public async Task ReturnsAsync_onSingleParameter_LazyEvaluationOfTheResult()
3434
{
3535
int coefficient = 5;
3636
var mock = new Mock<IAsyncInterface>();
3737
mock.Setup(x => x.WithSingleParameterAsync(It.IsAny<int>())).ReturnsAsync((int x) => x * coefficient);
3838

39-
int firstEvaluationResult = mock.Object.WithSingleParameterAsync(2).Result;
39+
int firstEvaluationResult = await mock.Object.WithSingleParameterAsync(2);
4040

4141
coefficient = 10;
42-
int secondEvaluationResult = mock.Object.WithSingleParameterAsync(2).Result;
42+
int secondEvaluationResult = await mock.Object.WithSingleParameterAsync(2);
4343

4444
Assert.NotEqual(firstEvaluationResult, secondEvaluationResult);
4545
}
4646

4747
[Fact]
48-
public void ReturnsAsync_onMultiParameter_ParametersUsedForCalculationOfTheResult()
48+
public async Task ReturnsAsync_onMultiParameter_ParametersUsedForCalculationOfTheResult()
4949
{
5050
var mock = new Mock<IAsyncInterface>();
5151
mock.Setup(x => x.WithMultiParameterAsync(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync((string first, string second) => first + second);
5252

53-
string evaluationResult = mock.Object.WithMultiParameterAsync("Moq", "4").Result;
53+
string evaluationResult = await mock.Object.WithMultiParameterAsync("Moq", "4");
5454

5555
Assert.Equal("Moq4", evaluationResult);
5656
}
5757

5858
[Fact]
59-
public void ReturnsAsync_onMultiParameter_LazyEvaluationOfTheResult()
59+
public async Task ReturnsAsync_onMultiParameter_LazyEvaluationOfTheResult()
6060
{
6161
var mock = new Mock<IAsyncInterface>();
6262
mock.Setup(x => x.WithMultiParameterAsync(It.IsAny<string>(), It.IsAny<string>())).ReturnsAsync((string first, string second) => first + second);
6363

64-
string firstEvaluationResult = mock.Object.WithMultiParameterAsync("Moq", "4").Result;
65-
string secondEvaluationResult = mock.Object.WithMultiParameterAsync("Moq", "4").Result;
64+
string firstEvaluationResult = await mock.Object.WithMultiParameterAsync("Moq", "4");
65+
string secondEvaluationResult = await mock.Object.WithMultiParameterAsync("Moq", "4");
6666

6767
Assert.NotSame(firstEvaluationResult, secondEvaluationResult);
6868
}
6969

7070
[Fact]
71-
public void ReturnsAsync_onParams_AllParametersUsedForCalculationOfTheResult()
71+
public async Task ReturnsAsync_onParams_AllParametersUsedForCalculationOfTheResult()
7272
{
7373
var mock = new Mock<IAsyncInterface>();
7474
mock.Setup(x => x.WithParamsAsync(It.IsAny<DateTime[]>()))
7575
.ReturnsAsync((DateTime[] dateTimes) => dateTimes.Max());
7676

77-
DateTime evaluationResult = mock.Object.WithParamsAsync(DateTime.MinValue, DateTime.Now, DateTime.MaxValue).Result;
77+
DateTime evaluationResult = await mock.Object.WithParamsAsync(DateTime.MinValue, DateTime.Now, DateTime.MaxValue);
7878

7979
Assert.Equal(DateTime.MaxValue, evaluationResult);
8080
}
8181

8282
[Fact]
83-
public void ReturnsAsync_onParams_LazyEvaluationOfTheResult()
83+
public async Task ReturnsAsync_onParams_LazyEvaluationOfTheResult()
8484
{
8585
DateTime comparedDateTime = DateTime.MinValue;
8686
var mock = new Mock<IAsyncInterface>();
8787
mock.Setup(x => x.WithParamsAsync(It.IsAny<DateTime[]>()))
8888
.ReturnsAsync((DateTime[] dateTimes) => dateTimes.Concat(new[] { comparedDateTime }).Max());
8989

9090
DateTime now = DateTime.Now;
91-
DateTime firstEvaluationResult = mock.Object.WithParamsAsync(DateTime.MinValue, now).Result;
91+
DateTime firstEvaluationResult = await mock.Object.WithParamsAsync(DateTime.MinValue, now);
9292

9393
comparedDateTime = DateTime.MaxValue;
94-
DateTime secondEvaluationResult = mock.Object.WithParamsAsync(DateTime.MinValue, now).Result;
94+
DateTime secondEvaluationResult = await mock.Object.WithParamsAsync(DateTime.MinValue, now);
9595

9696
Assert.NotEqual(firstEvaluationResult, secondEvaluationResult);
9797
}

src/Moq.Tests/LookupOrFallbackDefaultValueProviderFixture.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class LookupOrFallbackDefaultValueProviderFixture
1919
[InlineData(typeof(IEnumerable<>), null)] // emptyable
2020
[InlineData(typeof(string), default(string))] // primitive reference type
2121
[InlineData(typeof(Exception), default(Exception))] // reference type
22-
public void Produces_default_when_no_factory_registered(Type type, object expected)
22+
public void Produces_default_when_no_factory_registered(Type type, object? expected)
2323
{
2424
var provider = new Provider();
2525

@@ -105,7 +105,7 @@ public void Handling_of_Task_can_be_disabled()
105105
}
106106

107107
[Fact]
108-
public void Produces_completed_generic_Task()
108+
public async Task Produces_completed_generic_Task()
109109
{
110110
const int expected = 42;
111111
var provider = new Provider();
@@ -114,7 +114,7 @@ public void Produces_completed_generic_Task()
114114
var actual = (Task<int>)provider.GetDefaultValue(typeof(Task<int>));
115115

116116
Assert.True(actual.IsCompleted);
117-
Assert.Equal(42, actual.Result);
117+
Assert.Equal(42, await actual);
118118
}
119119

120120
[Fact]
@@ -129,7 +129,7 @@ public void Handling_of_generic_Task_can_be_disabled()
129129
}
130130

131131
[Fact]
132-
public void Produces_completed_ValueTask()
132+
public async Task Produces_completed_ValueTask()
133133
{
134134
const int expectedResult = 42;
135135
var provider = new Provider();
@@ -138,11 +138,11 @@ public void Produces_completed_ValueTask()
138138
var actual = (ValueTask<int>)provider.GetDefaultValue(typeof(ValueTask<int>));
139139

140140
Assert.True(actual.IsCompleted);
141-
Assert.Equal(42, actual.Result);
141+
Assert.Equal(42, await actual);
142142
}
143143

144144
[Fact]
145-
public void Handling_of_ValueTask_can_be_disabled()
145+
public async Task Handling_of_ValueTask_can_be_disabled()
146146
{
147147
// If deregistration of ValueTask<> handling really works, the fallback strategy will produce
148148
// `default(ValueTask<int>)`, which equals a completed task containing 0 as result. So this test
@@ -160,7 +160,7 @@ public void Handling_of_ValueTask_can_be_disabled()
160160
var actual = (ValueTask<int>)provider.GetDefaultValue(typeof(ValueTask<int>));
161161

162162
Assert.Equal(default(ValueTask<int>), actual);
163-
Assert.NotEqual(unexpected, actual.Result);
163+
Assert.NotEqual(unexpected, await actual);
164164
}
165165

166166
[Fact]

src/Moq.Tests/Matchers/ParamArrayMatcherFixture.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ParamArrayMatcherFixture
1717
[InlineData(42, null, true)]
1818
[InlineData(3.141f, "", false)]
1919
[InlineData(null, "", false)]
20-
public void Matches_several_matchers_from_params_array(object first, object second, bool shouldMatch)
20+
public void Matches_several_matchers_from_params_array(object? first, object? second, bool shouldMatch)
2121
{
2222
var seconds = new List<string>();
2323
var methodCallExpr = (MethodCallExpression)ToExpression<IX>(x => x.Method(It.IsAny<int>(), Capture.In(seconds))).Body;
@@ -42,10 +42,7 @@ public void SetupEvaluatedSuccessfully_succeeds_for_matching_values()
4242
matcher.SetupEvaluatedSuccessfully(new object[] { 42, "" }, typeof(object[]));
4343
}
4444

45-
LambdaExpression ToExpression<T>(Expression<Action<T>> expr)
46-
{
47-
return expr;
48-
}
45+
LambdaExpression ToExpression<T>(Expression<Action<T>> expr) => expr;
4946

5047
public interface IX
5148
{

0 commit comments

Comments
 (0)