Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ exclude-labels:
- 'internal'

template: |
## Summary

SUMMARY_GOES_HERE

## Changes

$CHANGES
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
<PackageVersion Include="Microsoft.Extensions.Options" Version="[11.0.0-preview.5.26302.115, 12.0.0-a)" />
</ItemGroup>
<ItemGroup Label="Testing">
<PackageVersion Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
<PackageVersion Include="AutoFixture.Xunit3" Version="4.19.0" />
<PackageVersion Include="AwesomeAssertions" Version="9.5.0" />
<PackageVersion Include="Compono" Version="0.9.0-preview.88" />
<PackageVersion Include="Compono.XunitV3" Version="0.9.0-preview.88" />
<PackageVersion Include="Compono.TestDoubles" Version="0.9.0-preview.88" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.Testing" Version="10.9.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.10.0" />
<PackageVersion Include="NSubstitute" Version="5.3.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
<PackageVersion Include="xunit.v3.mtp-v2" Version="3.2.2" />
</ItemGroup>
Expand Down
48 changes: 26 additions & 22 deletions test/DynamoDb.DistributedLock.Tests/DistributedLockHandleTests.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using AutoFixture.Xunit3;
using DynamoDb.DistributedLock.Tests.TestKit.Attributes;
using AwesomeAssertions;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
using Compono;
using Compono.XunitV3;
using DynamoDb.DistributedLock.Tests.TestKit.Profiles;

namespace DynamoDb.DistributedLock.Tests;

public class DistributedLockHandleTests
{
[Theory]
[DynamoDbDistributedLockAutoData]
[Compose<DynamoDbDistributedLockGeneratedTestDoubleProfile>]
public void Constructor_WhenLockServiceIsNull_ShouldThrowArgumentNullException(
string resourceId,
string ownerId,
Expand All @@ -22,7 +21,7 @@ public void Constructor_WhenLockServiceIsNull_ShouldThrowArgumentNullException(
}

[Theory]
[DynamoDbDistributedLockAutoData]
[Compose<DynamoDbDistributedLockGeneratedTestDoubleProfile>]
public void Constructor_WhenResourceIdIsNull_ShouldThrowArgumentNullException(
IDynamoDbDistributedLock lockService,
string ownerId,
Expand All @@ -35,7 +34,7 @@ public void Constructor_WhenResourceIdIsNull_ShouldThrowArgumentNullException(
}

[Theory]
[DynamoDbDistributedLockAutoData]
[Compose<DynamoDbDistributedLockGeneratedTestDoubleProfile>]
public void Constructor_WhenOwnerIdIsNull_ShouldThrowArgumentNullException(
IDynamoDbDistributedLock lockService,
string resourceId,
Expand All @@ -48,7 +47,7 @@ public void Constructor_WhenOwnerIdIsNull_ShouldThrowArgumentNullException(
}

[Theory]
[DynamoDbDistributedLockAutoData]
[Compose<DynamoDbDistributedLockGeneratedTestDoubleProfile>]
public void Properties_ShouldReturnConstructorValues(
IDynamoDbDistributedLock lockService,
string resourceId,
Expand All @@ -63,7 +62,7 @@ public void Properties_ShouldReturnConstructorValues(
}

[Theory]
[DynamoDbDistributedLockAutoData]
[Compose<DynamoDbDistributedLockGeneratedTestDoubleProfile>]
public void IsAcquired_WhenNotDisposedAndNotExpired_ShouldReturnTrue(
IDynamoDbDistributedLock lockService,
string resourceId,
Expand All @@ -76,7 +75,7 @@ public void IsAcquired_WhenNotDisposedAndNotExpired_ShouldReturnTrue(
}

[Theory]
[DynamoDbDistributedLockAutoData]
[Compose<DynamoDbDistributedLockGeneratedTestDoubleProfile>]
public void IsAcquired_WhenExpired_ShouldReturnFalse(
IDynamoDbDistributedLock lockService,
string resourceId,
Expand All @@ -89,7 +88,7 @@ public void IsAcquired_WhenExpired_ShouldReturnFalse(
}

[Theory]
[DynamoDbDistributedLockAutoData]
[Compose<DynamoDbDistributedLockGeneratedTestDoubleProfile>]
public async Task IsAcquired_WhenDisposed_ShouldReturnFalse(
IDynamoDbDistributedLock lockService,
string resourceId,
Expand All @@ -104,9 +103,9 @@ public async Task IsAcquired_WhenDisposed_ShouldReturnFalse(
}

[Theory]
[DynamoDbDistributedLockAutoData]
[Compose<DynamoDbDistributedLockGeneratedTestDoubleProfile>]
public async Task DisposeAsync_ShouldCallReleaseLockAsync(
[Frozen] IDynamoDbDistributedLock lockService,
IDynamoDbDistributedLock lockService,
string resourceId,
string ownerId,
DateTimeOffset expiresAt)
Expand All @@ -115,13 +114,15 @@ public async Task DisposeAsync_ShouldCallReleaseLockAsync(

await handle.DisposeAsync();

await lockService.Received(1).ReleaseLockAsync(resourceId, ownerId, Arg.Any<CancellationToken>());
lockService.Verify()
.ReleaseLockAsync(resourceId, ownerId, Match.Any<CancellationToken>())
.Once();
}

[Theory]
[DynamoDbDistributedLockAutoData]
[Compose<DynamoDbDistributedLockGeneratedTestDoubleProfile>]
public async Task DisposeAsync_WhenCalledMultipleTimes_ShouldOnlyCallReleaseLockOnce(
[Frozen] IDynamoDbDistributedLock lockService,
IDynamoDbDistributedLock lockService,
string resourceId,
string ownerId,
DateTimeOffset expiresAt)
Expand All @@ -132,24 +133,27 @@ public async Task DisposeAsync_WhenCalledMultipleTimes_ShouldOnlyCallReleaseLock
await handle.DisposeAsync();
await handle.DisposeAsync();

await lockService.Received(1).ReleaseLockAsync(resourceId, ownerId, Arg.Any<CancellationToken>());
lockService.Verify()
.ReleaseLockAsync(resourceId, ownerId, Match.Any<CancellationToken>())
.Once();
}

[Theory]
[DynamoDbDistributedLockAutoData]
[Compose<DynamoDbDistributedLockGeneratedTestDoubleProfile>]
public async Task DisposeAsync_WhenReleaseLockThrows_ShouldSwallowException(
[Frozen] IDynamoDbDistributedLock lockService,
IDynamoDbDistributedLock lockService,
string resourceId,
string ownerId,
DateTimeOffset expiresAt)
{
lockService.ReleaseLockAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<CancellationToken>())
.ThrowsAsync(new InvalidOperationException("Test exception"));
lockService.Configure()
.ReleaseLockAsync(Match.Any<string>(), Match.Any<string>(), Match.Any<CancellationToken>())
.Throws(new InvalidOperationException("Test exception"));

var handle = new DistributedLockHandle(lockService, resourceId, ownerId, expiresAt);

var act = async () => await handle.DisposeAsync();

await act.Should().NotThrowAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
<IsPackable>false</IsPackable>
<ComponoGeneratedTestDoubles>true</ComponoGeneratedTestDoubles>
</PropertyGroup>
<PropertyGroup>
<IsTestProject>true</IsTestProject>
Expand All @@ -24,14 +25,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoFixture.AutoNSubstitute"/>
<PackageReference Include="AutoFixture.Xunit3"/>
<PackageReference Include="AwesomeAssertions" />
<PackageReference Include="Compono" />
<PackageReference Include="Compono.XunitV3" />
<PackageReference Include="Compono.TestDoubles" />
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" />
<PackageReference Include="NSubstitute"/>
<PackageReference Include="xunit.v3.mtp-v2" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading