-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from atc-net/feature/delete-stream
Implement DeleteStream in Management Client
- Loading branch information
Showing
10 changed files
with
135 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Atc.Cosmos.EventStore.Streams; | ||
using Microsoft.Azure.Cosmos; | ||
|
||
namespace Atc.Cosmos.EventStore.Cosmos; | ||
|
||
internal class CosmosDeleter : IStreamDeleter | ||
{ | ||
private readonly IEventStoreContainerProvider containerProvider; | ||
|
||
public CosmosDeleter(IEventStoreContainerProvider containerProvider) | ||
{ | ||
this.containerProvider = containerProvider; | ||
} | ||
|
||
public async Task DeleteAsync( | ||
StreamId streamId, | ||
CancellationToken cancellationToken) | ||
{ | ||
var pk = new PartitionKey(streamId.Value); | ||
var container = containerProvider.GetStreamContainer(); | ||
var response = await container.DeleteAllItemsByPartitionKeyStreamAsync(pk, null, cancellationToken); | ||
|
||
response.EnsureSuccessStatusCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Atc.Cosmos.EventStore.Streams; | ||
|
||
internal interface IStreamDeleter | ||
{ | ||
Task DeleteAsync( | ||
StreamId streamId, | ||
CancellationToken cancellationToken); | ||
} |
50 changes: 50 additions & 0 deletions
50
test/Atc.Cosmos.EventStore.Tests/Cosmos/CosmosDeleterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Atc.Cosmos.EventStore.Cosmos; | ||
using Atc.Test; | ||
using Microsoft.Azure.Cosmos; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace Atc.Cosmos.EventStore.Tests.Cosmos; | ||
|
||
public class CosmosDeleterTests | ||
{ | ||
private readonly ResponseMessage responseMessage; | ||
private readonly Container container; | ||
private readonly IEventStoreContainerProvider containerProvider; | ||
private readonly CosmosDeleter sut; | ||
|
||
public CosmosDeleterTests() | ||
{ | ||
responseMessage = Substitute.For<ResponseMessage>(); | ||
responseMessage.IsSuccessStatusCode.Returns(true); | ||
|
||
container = Substitute.For<Container>(); | ||
container | ||
.DeleteAllItemsByPartitionKeyStreamAsync(default, default, default) | ||
.ReturnsForAnyArgs(responseMessage); | ||
|
||
containerProvider = Substitute.For<IEventStoreContainerProvider>(); | ||
containerProvider | ||
.GetStreamContainer() | ||
.Returns(container, returnThese: null); | ||
|
||
sut = new CosmosDeleter(containerProvider); | ||
} | ||
|
||
[Theory, AutoNSubstituteData] | ||
public async Task Should_Use_StreamId_As_PartitionKey( | ||
StreamId streamId, | ||
CancellationToken cancellationToken) | ||
{ | ||
await sut.DeleteAsync( | ||
streamId, | ||
cancellationToken); | ||
|
||
_ = container | ||
.Received() | ||
.DeleteAllItemsByPartitionKeyStreamAsync( | ||
new PartitionKey(streamId.Value), | ||
null, | ||
cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/Atc.Cosmos.EventStore.Tests/EventStoreManagementClientTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Atc.Cosmos.EventStore.Streams; | ||
using Atc.Test; | ||
using AutoFixture.Xunit2; | ||
using FluentAssertions; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace Atc.Cosmos.EventStore.Tests; | ||
|
||
public class EventStoreManagementClientTests | ||
{ | ||
[Theory, AutoNSubstituteData] | ||
internal async Task Should_DeleteStream( | ||
[Frozen] IStreamDeleter deleter, | ||
EventStoreManagementClient sut, | ||
StreamId streamId, | ||
CancellationToken cancellationToken) | ||
{ | ||
await sut.DeleteStreamAsync( | ||
streamId, | ||
cancellationToken: cancellationToken); | ||
|
||
_ = deleter | ||
.Received(1) | ||
.DeleteAsync( | ||
streamId, | ||
cancellationToken); | ||
} | ||
} |