public void CancelBarelyLockAsync_Cancel() { // setup var semaphore = new SemaphoreSlim(0); var value = new List(); var subject = new AsyncSynchronized <List>(semaphore, value); // act and assert Should.Throw <OperationCanceledException>(() => subject.BarelyLockAsync(new CancellationTokenSource(0).Token)); }
public async Task BarelyLockAsync_Acquire() { // setup var semaphore = new SemaphoreSlim(1); var value = new List(); var subject = new AsyncSynchronized <List>(semaphore, value); // act and assert var result = await subject.BarelyLockAsync(); semaphore.CurrentCount.ShouldBe(0); result.ShouldBe(value); }