Skip to content

Commit d334dd8

Browse files
bank-account: use async Task for concurrency test
1 parent da5ed80 commit d334dd8

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

exercises/practice/bank-account/.meta/Generator.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class {{ testClass }}
2828
{
2929
{{- for test in tests }}
3030
[Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}]
31-
public void {{ test.testMethod }}()
31+
public {{ if test.scenarios | array.contains "concurrent" }}async Task{{ else }}void{{ end }} {{ test.testMethod }}()
3232
{
3333
var account = new {{ testedClass }}();
3434
{{- for op in test.input.operations }}
@@ -51,7 +51,7 @@ public class {{ testClass }}
5151
{{- end -}}
5252
}
5353
}));
54-
Task.WaitAll(tasks.ToArray());
54+
await Task.WaitAll(tasks.ToArray());
5555
}
5656
{{- else }}
5757
account.{{ op | to_call }};

exercises/practice/bank-account/BankAccountTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void Cannot_deposit_negative()
153153
}
154154

155155
[Fact(Skip = "Remove this Skip property to run this test")]
156-
public void Can_handle_concurrent_transactions()
156+
public async Task Can_handle_concurrent_transactions()
157157
{
158158
var account = new BankAccount();
159159
account.Open();
@@ -168,7 +168,7 @@ public void Can_handle_concurrent_transactions()
168168
account.Withdraw(1m);
169169
}
170170
}));
171-
Task.WaitAll(tasks.ToArray());
171+
await Task.WaitAll(tasks.ToArray());
172172
}
173173
Assert.Equal(0m, account.Balance);
174174
}

0 commit comments

Comments
 (0)