Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit e7f61cb

Browse files
Merge pull request #31 from thefringeninja/204
Delete Operations Should Return No Content
2 parents 1935f4a + 5f8b78e commit e7f61cb

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

src/SqlStreamStore.HAL.Tests/StreamDeleteTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public async Task expected_version(int? expectedVersion)
3333

3434
using(var response = await _fixture.HttpClient.SendAsync(request))
3535
{
36-
response.StatusCode.ShouldBe(HttpStatusCode.OK);
36+
response.StatusCode.ShouldBe(HttpStatusCode.NoContent);
3737
}
3838

3939
var page = await _fixture.StreamStore.ReadStreamForwards(StreamId, 0, 1);

src/SqlStreamStore.HAL.Tests/StreamMessageTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public async Task delete_single_message_by_version()
7272

7373
using(var response = await _fixture.HttpClient.DeleteAsync("/streams/a-stream/0"))
7474
{
75-
response.StatusCode.ShouldBe(HttpStatusCode.OK);
75+
response.StatusCode.ShouldBe(HttpStatusCode.NoContent);
7676
}
7777

7878
using(var response = await _fixture.HttpClient.GetAsync("/streams/a-stream/0"))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace SqlStreamStore.HAL
2+
{
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Http;
6+
7+
internal class NoContentResponse : Response
8+
{
9+
public static readonly NoContentResponse Instance = new NoContentResponse();
10+
11+
private NoContentResponse()
12+
: base(204)
13+
{ }
14+
15+
public override Task WriteBody(HttpResponse response, CancellationToken cancellationToken)
16+
=> Task.CompletedTask;
17+
}
18+
}

src/SqlStreamStore.HAL/Response.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ internal abstract class Response
1111
public int StatusCode { get; }
1212
public IDictionary<string, string[]> Headers { get; }
1313

14+
protected Response(int statusCode)
15+
: this(statusCode, null)
16+
{ }
17+
1418
protected Response(int statusCode, string mediaType)
1519
{
1620
StatusCode = statusCode;

src/SqlStreamStore.HAL/StreamMessage/StreamMessageResource.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ public async Task<Response> Delete(
9191
{
9292
await operation.Invoke(_streamStore, cancellationToken);
9393

94-
return new HalJsonResponse(
95-
new HALResponse(new HALModelConfig()));
94+
return NoContentResponse.Instance;
9695
}
9796
}
9897
}

src/SqlStreamStore.HAL/Streams/StreamResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public async Task<Response> Delete(DeleteStreamOperation operation, Cancellation
130130
{
131131
await operation.Invoke(_streamStore, cancellationToken);
132132

133-
return new HalJsonResponse(new HALResponse(new object()));
133+
return NoContentResponse.Instance;
134134
}
135135
}
136136
}

0 commit comments

Comments
 (0)