From efdeced25b4cfc90fee98351062dc543c85512ec Mon Sep 17 00:00:00 2001 From: Mark Cilia Vincenti Date: Fri, 29 Dec 2023 17:24:00 +0100 Subject: [PATCH] More coverage tests --- .../AsyncKeyedLocker/OriginalTests.cs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/AsyncKeyedLock.Tests/AsyncKeyedLocker/OriginalTests.cs b/AsyncKeyedLock.Tests/AsyncKeyedLocker/OriginalTests.cs index 47afe59..0a57ac3 100644 --- a/AsyncKeyedLock.Tests/AsyncKeyedLocker/OriginalTests.cs +++ b/AsyncKeyedLock.Tests/AsyncKeyedLocker/OriginalTests.cs @@ -133,11 +133,67 @@ public void TestDisposeDoesNotThrow() o.PoolSize = 20; o.PoolInitialFill = 1; }); + asyncKeyedLocker.Lock("test"); asyncKeyedLocker.Dispose(); }; action.Should().NotThrow(); } + [Fact] + public void TestIndexDoesNotThrow() + { + var asyncKeyedLocker = new AsyncKeyedLocker(); + asyncKeyedLocker.Lock("test"); + asyncKeyedLocker.Index.Count.Should().Be(1); + asyncKeyedLocker.Dispose(); + } + + [Fact] + public void TestReadingMaxCount() + { + var asyncKeyedLocker = new AsyncKeyedLocker(o => o.MaxCount = 2); + asyncKeyedLocker.MaxCount.Should().Be(2); + } + + [Fact] + public void TestReadingMaxCountViaParameter() + { + var asyncKeyedLocker = new AsyncKeyedLocker(new AsyncKeyedLockOptions(2)); + asyncKeyedLocker.MaxCount.Should().Be(2); + } + + [Fact] + public void TestReadingMaxCountViaParameterWithComparer() + { + var asyncKeyedLocker = new AsyncKeyedLocker(new AsyncKeyedLockOptions(2), EqualityComparer.Default); + asyncKeyedLocker.MaxCount.Should().Be(2); + } + + [Fact] + public void TestReadingMaxCountViaParameterWithConcurrencyLevelAndCapacity() + { + var asyncKeyedLocker = new AsyncKeyedLocker(new AsyncKeyedLockOptions(2), Environment.ProcessorCount, 100); + asyncKeyedLocker.MaxCount.Should().Be(2); + } + + [Fact] + public void TestReadingMaxCountViaParameterWithConcurrencyLevelAndCapacityAndComparer() + { + var asyncKeyedLocker = new AsyncKeyedLocker(new AsyncKeyedLockOptions(2), Environment.ProcessorCount, 100, EqualityComparer.Default); + asyncKeyedLocker.MaxCount.Should().Be(2); + } + + [Fact] + public void TestGetCurrentCount() + { + var asyncKeyedLocker = new AsyncKeyedLocker(); + asyncKeyedLocker.GetRemainingCount("test").Should().Be(0); + asyncKeyedLocker.GetCurrentCount("test").Should().Be(1); + asyncKeyedLocker.Lock("test"); + asyncKeyedLocker.GetRemainingCount("test").Should().Be(1); + asyncKeyedLocker.GetCurrentCount("test").Should().Be(0); + } + [Fact] public async Task TestTimeoutBasic() {