Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
inputfalken committed Jul 12, 2024
1 parent d29c9c4 commit ebe8f13
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/Dynatello.Tests/HandlerTests/DeleteRequestHandlerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
using AutoFixture;
using Dynatello.Builders;
using Dynatello.Handlers;
using NSubstitute;

namespace Dynatello.Tests.HandlerTests;
public class DeleteRequestHandlerTests
{


[Fact]
public async Task Send_SuccessMock_ShouldReturnItem()
{
var amazonDynamoDB = Substitute.For<IAmazonDynamoDB>();
var expected = Cat.Fixture.Create<Cat>();

amazonDynamoDB
.DeleteItemAsync(Arg.Any<DeleteItemRequest>())
.Returns(new DeleteItemResponse
{
HttpStatusCode = System.Net.HttpStatusCode.OK,
Attributes = Cat.GetById.Marshall(expected)
});

var actual = await Cat.GetById
.OnTable("TABLE")
.ToDeleteRequestHandler(x => x.ToDeleteRequestBuilder(), x => x.AmazonDynamoDB = amazonDynamoDB)
.Send(expected.Id, default);

Assert.Equal(expected, actual);
}

[Fact]
public async Task Send_MissingValue_ShouldReturnNull()
{
var amazonDynamoDB = Substitute.For<IAmazonDynamoDB>();
var expected = Cat.Fixture.Create<Cat>();

amazonDynamoDB
.DeleteItemAsync(Arg.Any<DeleteItemRequest>())
.Returns(new DeleteItemResponse { });

var actual = await Cat.GetById
.OnTable("TABLE")
.ToDeleteRequestHandler(x => x.ToDeleteRequestBuilder(), x => x.AmazonDynamoDB = amazonDynamoDB)
.Send(expected.Id, default);

Assert.Null(actual);
}
}

0 comments on commit ebe8f13

Please sign in to comment.