Skip to content

Commit

Permalink
Merge pull request #58 from atc-net/feature/expose-delete-stream
Browse files Browse the repository at this point in the history
Expose DeleteStream to Package Consumers
  • Loading branch information
LarsSkovslund authored Dec 23, 2024
2 parents de34dcf + a08f765 commit 72c482a
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 113 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Remove `IEventStoreManagementClient` and move `DeleteStreamAsync` method to `IEventStoreClient`.

## [1.14.11] - 2024-12-09

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public static IServiceCollection AddEventStore(
{
services.TryAddSingleton<CosmosEventSerializer>();
services.TryAddSingleton<IEventStoreClient, EventStoreClient>();
services.TryAddSingleton<IEventStoreManagementClient, EventStoreManagementClient>();

var configureOptions = new EventStoreOptionsBuilder(services);
configure?.Invoke(configureOptions);
Expand Down
10 changes: 9 additions & 1 deletion src/Atc.Cosmos.EventStore/EventStoreClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal class EventStoreClient : IEventStoreClient
private readonly IStreamCheckpointReader checkpointReader;
private readonly IStreamSubscriptionFactory subscriptionFactory;
private readonly IStreamSubscriptionRemover subscriptionRemover;
private readonly IStreamDeleter streamDeleter;

public EventStoreClient(
IStreamWriter streamWriter,
Expand All @@ -22,7 +23,8 @@ public EventStoreClient(
IStreamCheckpointWriter checkpointWriter,
IStreamCheckpointReader checkpointReader,
IStreamSubscriptionFactory subscriptionFactory,
IStreamSubscriptionRemover subscriptionRemover)
IStreamSubscriptionRemover subscriptionRemover,
IStreamDeleter streamDeleter)
{
this.streamWriter = streamWriter;
this.streamReader = streamReader;
Expand All @@ -32,6 +34,7 @@ public EventStoreClient(
this.checkpointReader = checkpointReader;
this.subscriptionFactory = subscriptionFactory;
this.subscriptionRemover = subscriptionRemover;
this.streamDeleter = streamDeleter;
}

public Task DeleteSubscriptionAsync(
Expand Down Expand Up @@ -130,4 +133,9 @@ public Task SetStreamCheckpointAsync(
streamId,
cancellationToken)
.ConfigureAwait(false);

public Task DeleteStreamAsync(
StreamId streamId,
CancellationToken cancellationToken = default)
=> streamDeleter.DeleteAsync(streamId, cancellationToken);
}
31 changes: 0 additions & 31 deletions src/Atc.Cosmos.EventStore/EventStoreManagementClient.cs

This file was deleted.

11 changes: 11 additions & 0 deletions src/Atc.Cosmos.EventStore/IEventStoreClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,15 @@ Task SetStreamCheckpointAsync(
string name,
StreamId streamId,
CancellationToken cancellationToken = default);

/// <summary>
/// Deletes an entire stream.
/// </summary>
/// <remarks>Attempting to write to a deleted stream will create a new empty stream.</remarks>
/// <param name="streamId">Id of the event stream to delete.</param>
/// <param name="cancellationToken">(Optional) <seealso cref="CancellationToken"/> representing request cancellation.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
Task DeleteStreamAsync(
StreamId streamId,
CancellationToken cancellationToken = default);
}
51 changes: 0 additions & 51 deletions src/Atc.Cosmos.EventStore/IEventStoreManagementClient.cs

This file was deleted.

18 changes: 18 additions & 0 deletions test/Atc.Cosmos.EventStore.Tests/EventStoreClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,22 @@ internal Task Should_Throw_On_GetStreamCheckpoint_Without_State_When_Name_IsNull
.Awaiting(() => sut.GetStreamCheckpointAsync(null, streamId, cancellationToken))
.Should()
.ThrowAsync<ArgumentNullException>();

[Theory, AutoNSubstituteData]
internal async Task Should_DeleteStream(
[Frozen] IStreamDeleter deleter,
EventStoreClient sut,
StreamId streamId,
CancellationToken cancellationToken)
{
await sut.DeleteStreamAsync(
streamId,
cancellationToken: cancellationToken);

_ = deleter
.Received(1)
.DeleteAsync(
streamId,
cancellationToken);
}
}

This file was deleted.

0 comments on commit 72c482a

Please sign in to comment.