-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Shuttle/async
Async
- Loading branch information
Showing
84 changed files
with
2,425 additions
and
2,083 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
|
||
namespace Shuttle.Core.Data.Tests; | ||
|
||
public class AsyncFixture : MappingFixture | ||
{ | ||
private readonly Query _rowsQuery = new(@" | ||
select | ||
Id, | ||
Name, | ||
Age | ||
from | ||
BasicMapping | ||
"); | ||
|
||
[Test] | ||
public void Should_be_able_to_use_the_same_database_context_across_tasks_async() | ||
{ | ||
var tasks = new List<Task>(); | ||
|
||
using (GetDatabaseContext()) | ||
{ | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
tasks.Add(GetDatabaseGateway().GetRowsAsync(_rowsQuery)); | ||
} | ||
|
||
Task.WaitAll(tasks.ToArray()); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task Should_be_able_to_use_the_same_database_context_across_synchronized_tasks_async() | ||
{ | ||
using (GetDatabaseContext()) | ||
{ | ||
await GetRowsAsync(0); | ||
} | ||
} | ||
|
||
private async Task GetRowsAsync(int depth) | ||
{ | ||
if (depth < 5) | ||
{ | ||
await GetRowsAsync(depth + 1); | ||
} | ||
|
||
_ = await GetDatabaseGateway().GetRowsAsync(_rowsQuery); | ||
} | ||
} |
Oops, something went wrong.