Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose DeleteStream to Package Consumers #58

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
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.

Loading