Skip to content

Commit b958174

Browse files
committed
Resharper: Replace async method with Task return
1 parent 69ab6ce commit b958174

File tree

38 files changed

+161
-153
lines changed

38 files changed

+161
-153
lines changed

Diff for: src/JsonApiDotNetCore.MongoDb/AtomicOperations/MongoTransaction.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,24 @@ public Task AfterProcessOperationAsync(CancellationToken cancellationToken)
3535
}
3636

3737
/// <inheritdoc />
38-
public async Task CommitAsync(CancellationToken cancellationToken)
38+
public Task CommitAsync(CancellationToken cancellationToken)
3939
{
4040
if (_ownsTransaction && _mongoDataAccess.ActiveSession != null)
4141
{
42-
await _mongoDataAccess.ActiveSession.CommitTransactionAsync(cancellationToken);
42+
return _mongoDataAccess.ActiveSession.CommitTransactionAsync(cancellationToken);
4343
}
44+
45+
return Task.CompletedTask;
4446
}
4547

4648
/// <inheritdoc />
47-
public async ValueTask DisposeAsync()
49+
public ValueTask DisposeAsync()
4850
{
4951
if (_ownsTransaction)
5052
{
51-
await _mongoDataAccess.DisposeAsync();
53+
return _mongoDataAccess.DisposeAsync();
5254
}
55+
56+
return ValueTask.CompletedTask;
5357
}
5458
}

Diff for: src/JsonApiDotNetCore.MongoDb/Repositories/MongoRepository.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ public virtual async Task CreateAsync(TResource resourceFromRequest, TResource r
173173

174174
await _resourceDefinitionAccessor.OnWritingAsync(resourceForDatabase, WriteOperationKind.CreateResource, cancellationToken);
175175

176-
await SaveChangesAsync(async () =>
176+
await SaveChangesAsync(() =>
177177
{
178-
await (_mongoDataAccess.ActiveSession != null
178+
return _mongoDataAccess.ActiveSession != null
179179
? Collection.InsertOneAsync(_mongoDataAccess.ActiveSession, resourceForDatabase, cancellationToken: cancellationToken)
180-
: Collection.InsertOneAsync(resourceForDatabase, cancellationToken: cancellationToken));
180+
: Collection.InsertOneAsync(resourceForDatabase, cancellationToken: cancellationToken);
181181
}, cancellationToken);
182182

183183
await _resourceDefinitionAccessor.OnWriteSucceededAsync(resourceForDatabase, WriteOperationKind.CreateResource, cancellationToken);

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/AtomicOperationsFixture.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public Task InitializeAsync()
3232
return Task.CompletedTask;
3333
}
3434

35-
public async Task DisposeAsync()
35+
public Task DisposeAsync()
3636
{
37-
await TestContext.DisposeAsync();
37+
return TestContext.DisposeAsync();
3838
}
3939
}

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceWithClientGeneratedIdTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ public async Task Cannot_create_resource_for_existing_client_generated_ID()
132132

133133
string newIsoCode = _fakers.TextLanguage.Generate().IsoCode!;
134134

135-
await _testContext.RunOnDatabaseAsync(async dbContext =>
135+
await _testContext.RunOnDatabaseAsync(dbContext =>
136136
{
137137
dbContext.TextLanguages.Add(existingLanguage);
138-
await dbContext.SaveChangesAsync();
138+
return dbContext.SaveChangesAsync();
139139
});
140140

141141
var requestBody = new

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceWithToManyRelationshipTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public async Task Cannot_create_ToMany_relationship()
2525

2626
string newTitle = _fakers.MusicTrack.Generate().Title;
2727

28-
await _testContext.RunOnDatabaseAsync(async dbContext =>
28+
await _testContext.RunOnDatabaseAsync(dbContext =>
2929
{
3030
dbContext.Performers.Add(existingPerformer);
31-
await dbContext.SaveChangesAsync();
31+
return dbContext.SaveChangesAsync();
3232
});
3333

3434
var requestBody = new

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceWithToOneRelationshipTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public async Task Cannot_create_ToOne_relationship()
2525

2626
string newLyricText = _fakers.Lyric.Generate().Text;
2727

28-
await _testContext.RunOnDatabaseAsync(async dbContext =>
28+
await _testContext.RunOnDatabaseAsync(dbContext =>
2929
{
3030
dbContext.MusicTracks.Add(existingTrack);
31-
await dbContext.SaveChangesAsync();
31+
return dbContext.SaveChangesAsync();
3232
});
3333

3434
var requestBody = new

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Deleting/AtomicDeleteResourceTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public async Task Can_delete_existing_resource()
2323
// Arrange
2424
Performer existingPerformer = _fakers.Performer.Generate();
2525

26-
await _testContext.RunOnDatabaseAsync(async dbContext =>
26+
await _testContext.RunOnDatabaseAsync(dbContext =>
2727
{
2828
dbContext.Performers.Add(existingPerformer);
29-
await dbContext.SaveChangesAsync();
29+
return dbContext.SaveChangesAsync();
3030
});
3131

3232
var requestBody = new

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Meta/AtomicResourceMetaTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ public async Task Returns_resource_meta_in_update_resource_with_side_effects()
112112

113113
TextLanguage existingLanguage = _fakers.TextLanguage.Generate();
114114

115-
await _testContext.RunOnDatabaseAsync(async dbContext =>
115+
await _testContext.RunOnDatabaseAsync(dbContext =>
116116
{
117117
dbContext.TextLanguages.Add(existingLanguage);
118-
await dbContext.SaveChangesAsync();
118+
return dbContext.SaveChangesAsync();
119119
});
120120

121121
var requestBody = new

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Transactions/AtomicRollbackTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public async Task Can_rollback_created_resource_on_error()
2626
string newArtistName = _fakers.Performer.Generate().ArtistName!;
2727
DateTimeOffset newBornAt = _fakers.Performer.Generate().BornAt;
2828

29-
await _testContext.RunOnDatabaseAsync(async dbContext =>
29+
await _testContext.RunOnDatabaseAsync(dbContext =>
3030
{
31-
await dbContext.ClearTableAsync<Performer>();
31+
return dbContext.ClearTableAsync<Performer>();
3232
});
3333

3434
string unknownPerformerId = Unknown.StringId.For<Performer, string?>();
@@ -94,10 +94,10 @@ public async Task Can_rollback_updated_resource_on_error()
9494

9595
string newArtistName = _fakers.Performer.Generate().ArtistName!;
9696

97-
await _testContext.RunOnDatabaseAsync(async dbContext =>
97+
await _testContext.RunOnDatabaseAsync(dbContext =>
9898
{
9999
dbContext.Performers.Add(existingPerformer);
100-
await dbContext.SaveChangesAsync();
100+
return dbContext.SaveChangesAsync();
101101
});
102102

103103
string unknownPerformerId = Unknown.StringId.For<Performer, string?>();

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Transactions/LyricRepository.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public LyricRepository(IMongoDataAccess mongoDataAccess, ITargetedFields targete
2626
_transaction = factory.BeginTransactionAsync(CancellationToken.None).Result;
2727
}
2828

29-
public async ValueTask DisposeAsync()
29+
public ValueTask DisposeAsync()
3030
{
31-
await _transaction.DisposeAsync();
31+
return _transaction.DisposeAsync();
3232
}
3333
}

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Updating/Relationships/AtomicAddToToManyRelationshipTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public async Task Cannot_add_to_OneToMany_relationship()
2424
MusicTrack existingTrack = _fakers.MusicTrack.Generate();
2525
Performer existingPerformer = _fakers.Performer.Generate();
2626

27-
await _testContext.RunOnDatabaseAsync(async dbContext =>
27+
await _testContext.RunOnDatabaseAsync(dbContext =>
2828
{
2929
dbContext.Performers.Add(existingPerformer);
3030
dbContext.MusicTracks.Add(existingTrack);
31-
await dbContext.SaveChangesAsync();
31+
return dbContext.SaveChangesAsync();
3232
});
3333

3434
var requestBody = new
@@ -81,11 +81,11 @@ public async Task Cannot_add_to_ManyToMany_relationship()
8181
Playlist existingPlaylist = _fakers.Playlist.Generate();
8282
MusicTrack existingTrack = _fakers.MusicTrack.Generate();
8383

84-
await _testContext.RunOnDatabaseAsync(async dbContext =>
84+
await _testContext.RunOnDatabaseAsync(dbContext =>
8585
{
8686
dbContext.MusicTracks.Add(existingTrack);
8787
dbContext.Playlists.Add(existingPlaylist);
88-
await dbContext.SaveChangesAsync();
88+
return dbContext.SaveChangesAsync();
8989
});
9090

9191
var requestBody = new

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Updating/Relationships/AtomicRemoveFromToManyRelationshipTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public async Task Cannot_remove_from_OneToMany_relationship()
2424
MusicTrack existingTrack = _fakers.MusicTrack.Generate();
2525
existingTrack.Performers = _fakers.Performer.Generate(1);
2626

27-
await _testContext.RunOnDatabaseAsync(async dbContext =>
27+
await _testContext.RunOnDatabaseAsync(dbContext =>
2828
{
2929
dbContext.Performers.Add(existingTrack.Performers[0]);
3030
dbContext.MusicTracks.Add(existingTrack);
31-
await dbContext.SaveChangesAsync();
31+
return dbContext.SaveChangesAsync();
3232
});
3333

3434
var requestBody = new
@@ -81,11 +81,11 @@ public async Task Cannot_remove_from_ManyToMany_relationship()
8181
Playlist existingPlaylist = _fakers.Playlist.Generate();
8282
existingPlaylist.Tracks = _fakers.MusicTrack.Generate(1);
8383

84-
await _testContext.RunOnDatabaseAsync(async dbContext =>
84+
await _testContext.RunOnDatabaseAsync(dbContext =>
8585
{
8686
dbContext.MusicTracks.Add(existingPlaylist.Tracks[0]);
8787
dbContext.Playlists.Add(existingPlaylist);
88-
await dbContext.SaveChangesAsync();
88+
return dbContext.SaveChangesAsync();
8989
});
9090

9191
var requestBody = new

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Updating/Relationships/AtomicReplaceToManyRelationshipTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public async Task Cannot_replace_OneToMany_relationship()
2424
MusicTrack existingTrack = _fakers.MusicTrack.Generate();
2525
Performer existingPerformer = _fakers.Performer.Generate();
2626

27-
await _testContext.RunOnDatabaseAsync(async dbContext =>
27+
await _testContext.RunOnDatabaseAsync(dbContext =>
2828
{
2929
dbContext.Performers.Add(existingPerformer);
3030
dbContext.MusicTracks.Add(existingTrack);
31-
await dbContext.SaveChangesAsync();
31+
return dbContext.SaveChangesAsync();
3232
});
3333

3434
var requestBody = new
@@ -81,11 +81,11 @@ public async Task Cannot_replace_ManyToMany_relationship()
8181
Playlist existingPlaylist = _fakers.Playlist.Generate();
8282
MusicTrack existingTrack = _fakers.MusicTrack.Generate();
8383

84-
await _testContext.RunOnDatabaseAsync(async dbContext =>
84+
await _testContext.RunOnDatabaseAsync(dbContext =>
8585
{
8686
dbContext.MusicTracks.Add(existingTrack);
8787
dbContext.Playlists.Add(existingPlaylist);
88-
await dbContext.SaveChangesAsync();
88+
return dbContext.SaveChangesAsync();
8989
});
9090

9191
var requestBody = new

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Updating/Relationships/AtomicUpdateToOneRelationshipTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public async Task Cannot_create_ManyToOne_relationship()
2424
MusicTrack existingTrack = _fakers.MusicTrack.Generate();
2525
RecordCompany existingCompany = _fakers.RecordCompany.Generate();
2626

27-
await _testContext.RunOnDatabaseAsync(async dbContext =>
27+
await _testContext.RunOnDatabaseAsync(dbContext =>
2828
{
2929
dbContext.RecordCompanies.Add(existingCompany);
3030
dbContext.MusicTracks.Add(existingTrack);
31-
await dbContext.SaveChangesAsync();
31+
return dbContext.SaveChangesAsync();
3232
});
3333

3434
var requestBody = new

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Updating/Resources/AtomicReplaceToManyRelationshipTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public async Task Cannot_replace_ToMany_relationship()
2424
MusicTrack existingTrack = _fakers.MusicTrack.Generate();
2525
Performer existingPerformer = _fakers.Performer.Generate();
2626

27-
await _testContext.RunOnDatabaseAsync(async dbContext =>
27+
await _testContext.RunOnDatabaseAsync(dbContext =>
2828
{
2929
dbContext.Performers.Add(existingPerformer);
3030
dbContext.MusicTracks.Add(existingTrack);
31-
await dbContext.SaveChangesAsync();
31+
return dbContext.SaveChangesAsync();
3232
});
3333

3434
var requestBody = new

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Updating/Resources/AtomicUpdateResourceTests.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ public async Task Can_update_resource_without_attributes_or_relationships()
8989
// Arrange
9090
MusicTrack existingTrack = _fakers.MusicTrack.Generate();
9191

92-
await _testContext.RunOnDatabaseAsync(async dbContext =>
92+
await _testContext.RunOnDatabaseAsync(dbContext =>
9393
{
9494
dbContext.MusicTracks.Add(existingTrack);
95-
await dbContext.SaveChangesAsync();
95+
return dbContext.SaveChangesAsync();
9696
});
9797

9898
var requestBody = new
@@ -144,10 +144,10 @@ public async Task Can_partially_update_resource_without_side_effects()
144144

145145
string newGenre = _fakers.MusicTrack.Generate().Genre!;
146146

147-
await _testContext.RunOnDatabaseAsync(async dbContext =>
147+
await _testContext.RunOnDatabaseAsync(dbContext =>
148148
{
149149
dbContext.MusicTracks.Add(existingTrack);
150-
await dbContext.SaveChangesAsync();
150+
return dbContext.SaveChangesAsync();
151151
});
152152

153153
var requestBody = new
@@ -202,10 +202,10 @@ public async Task Can_completely_update_resource_without_side_effects()
202202
string newGenre = _fakers.MusicTrack.Generate().Genre!;
203203
DateTimeOffset newReleasedAt = _fakers.MusicTrack.Generate().ReleasedAt;
204204

205-
await _testContext.RunOnDatabaseAsync(async dbContext =>
205+
await _testContext.RunOnDatabaseAsync(dbContext =>
206206
{
207207
dbContext.MusicTracks.Add(existingTrack);
208-
await dbContext.SaveChangesAsync();
208+
return dbContext.SaveChangesAsync();
209209
});
210210

211211
var requestBody = new
@@ -259,10 +259,10 @@ public async Task Can_update_resource_with_side_effects()
259259
TextLanguage existingLanguage = _fakers.TextLanguage.Generate();
260260
string newIsoCode = _fakers.TextLanguage.Generate().IsoCode!;
261261

262-
await _testContext.RunOnDatabaseAsync(async dbContext =>
262+
await _testContext.RunOnDatabaseAsync(dbContext =>
263263
{
264264
dbContext.TextLanguages.Add(existingLanguage);
265-
await dbContext.SaveChangesAsync();
265+
return dbContext.SaveChangesAsync();
266266
});
267267

268268
var requestBody = new

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/AtomicOperations/Updating/Resources/AtomicUpdateToOneRelationshipTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public async Task Cannot_create_ToOne_relationship()
2424
Lyric existingLyric = _fakers.Lyric.Generate();
2525
MusicTrack existingTrack = _fakers.MusicTrack.Generate();
2626

27-
await _testContext.RunOnDatabaseAsync(async dbContext =>
27+
await _testContext.RunOnDatabaseAsync(dbContext =>
2828
{
2929
dbContext.MusicTracks.Add(existingTrack);
3030
dbContext.Lyrics.Add(existingLyric);
31-
await dbContext.SaveChangesAsync();
31+
return dbContext.SaveChangesAsync();
3232
});
3333

3434
var requestBody = new

Diff for: test/JsonApiDotNetCoreMongoDbTests/IntegrationTests/Meta/TopLevelCountTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
6262
public async Task Renders_resource_count_for_empty_collection()
6363
{
6464
// Arrange
65-
await _testContext.RunOnDatabaseAsync(async dbContext =>
65+
await _testContext.RunOnDatabaseAsync(dbContext =>
6666
{
67-
await dbContext.ClearTableAsync<SupportTicket>();
67+
return dbContext.ClearTableAsync<SupportTicket>();
6868
});
6969

7070
const string route = "/supportTickets";
@@ -117,10 +117,10 @@ public async Task Hides_resource_count_in_update_resource_response()
117117

118118
string newDescription = _fakers.SupportTicket.Generate().Description;
119119

120-
await _testContext.RunOnDatabaseAsync(async dbContext =>
120+
await _testContext.RunOnDatabaseAsync(dbContext =>
121121
{
122122
dbContext.SupportTickets.Add(existingTicket);
123-
await dbContext.SaveChangesAsync();
123+
return dbContext.SaveChangesAsync();
124124
});
125125

126126
var requestBody = new

0 commit comments

Comments
 (0)