Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCiliaVincenti committed Jan 14, 2024
1 parent 6585036 commit 7d180ae
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion AsyncKeyedLock.Tests/AsyncNonKeyedLockerTests/OriginalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,39 @@ namespace AsyncKeyedLock.Tests.AsyncNonKeyedLockerTests
{
public class OriginalTests
{
[Fact]
public void TestMaxCount()
{
using var asyncNonKeyedLocker = new AsyncNonKeyedLocker(2);
Assert.Equal(0, asyncNonKeyedLocker.GetRemainingCount());
Assert.Equal(2, asyncNonKeyedLocker.GetCurrentCount());
using (var myLock = (AsyncNonKeyedLockReleaser)asyncNonKeyedLocker.Lock())
{
Assert.Equal(1, asyncNonKeyedLocker.GetRemainingCount());
Assert.Equal(1, asyncNonKeyedLocker.GetCurrentCount());
Assert.Equal(1, myLock.SemaphoreSlim.CurrentCount);
using (var myLock2 = (AsyncNonKeyedLockReleaser)asyncNonKeyedLocker.Lock())
{
Assert.Equal(2, asyncNonKeyedLocker.GetRemainingCount());
Assert.Equal(0, asyncNonKeyedLocker.GetCurrentCount());
Assert.Equal(0, myLock2.SemaphoreSlim.CurrentCount);
}
}
Assert.Equal(0, asyncNonKeyedLocker.GetRemainingCount());
Assert.Equal(1, asyncNonKeyedLocker.GetCurrentCount());
}

[Fact]
public void TestLock()
{
var asyncNonKeyedLocker = new AsyncNonKeyedLocker();
Assert.Equal(0, asyncNonKeyedLocker.GetRemainingCount());
Assert.Equal(1, asyncNonKeyedLocker.GetCurrentCount());
using (asyncNonKeyedLocker.Lock())
using (var myLock = (AsyncNonKeyedLockReleaser)asyncNonKeyedLocker.Lock())
{
Assert.Equal(1, asyncNonKeyedLocker.GetRemainingCount());
Assert.Equal(0, asyncNonKeyedLocker.GetCurrentCount());
Assert.Equal(0, myLock.SemaphoreSlim.CurrentCount);
}
Assert.Equal(0, asyncNonKeyedLocker.GetRemainingCount());
Assert.Equal(1, asyncNonKeyedLocker.GetCurrentCount());
Expand Down Expand Up @@ -59,6 +82,7 @@ public void TestLockAndMillisecondsTimeout()
Assert.True(myLock.EnteredSemaphore);
Assert.Equal(1, asyncNonKeyedLocker.GetRemainingCount());
Assert.Equal(0, asyncNonKeyedLocker.GetCurrentCount());
Assert.Equal(0, myLock.SemaphoreSlim.CurrentCount);
using (var myLock2 = asyncNonKeyedLocker.Lock(0, out entered))
{
Assert.False(entered);
Expand Down

0 comments on commit 7d180ae

Please sign in to comment.