Skip to content

Commit a82511a

Browse files
committed
Add test to check exception
1 parent aaa30b0 commit a82511a

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

src/DynamoDBGenerator/Internal/ExceptionHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static DynamoDBMarshallingException KeysArgumentNotNull(string memberName
2323

2424
public static DynamoDBMarshallingException KeysInvalidConversion(string memberName, string argumentName, object value, string expectedType)
2525
{
26-
return new DynamoDBMarshallingException(memberName, $"Value '{{{value}}}' from argument '{{nameof({argumentName})}}' is not convertable to '{expectedType}'.");
26+
return new DynamoDBMarshallingException(memberName, $"Value '{{{value}}}' from argument '{argumentName}' is not convertable to '{expectedType}'.");
2727
}
2828

2929
public static InvalidOperationException KeysValueWithNoCorrespondence(string argumentName, object value)

tests/Dynatello.Tests/ToGetItemRequestTests.cs

+55-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Amazon.DynamoDBv2.Model;
22
using AutoFixture;
3+
using DynamoDBGenerator.Exceptions;
34
using Dynatello.Builders;
45
using FluentAssertions;
56

@@ -16,6 +17,57 @@ static ToGetItemRequestTests()
1617
GetCatByCompositeKeys = Cat.QueryWithCuteness.OnTable("TABLE").ToGetRequestBuilder(x => x.Id, x => x.HomeId);
1718
}
1819

20+
[Fact]
21+
public void Build_Request_CompositeKeys_InvalidPartition()
22+
{
23+
var act = () => Cat.QueryWithCuteness
24+
.OnTable("TABLE")
25+
.ToGetRequestBuilder(x => x.Name, x => x.HomeId)
26+
.Build(("", Guid.Empty));
27+
28+
act.Should()
29+
.Throw<DynamoDBMarshallingException>()
30+
.WithMessage("Value '*' from argument '*' is not convertable*");
31+
}
32+
33+
[Fact]
34+
public void Build_Request_CompositeKeys_InvalidRange()
35+
{
36+
var act = () => Cat.QueryWithCuteness
37+
.OnTable("TABLE")
38+
.ToGetRequestBuilder(x => x.Id, x => x.Name)
39+
.Build((Guid.Empty, ""));
40+
41+
act.Should()
42+
.Throw<DynamoDBMarshallingException>()
43+
.WithMessage("Value '*' from argument '*' is not convertable*");
44+
}
45+
46+
[Fact]
47+
public void Build_Request_CompositeKeys_InvalidPartitionAndRange()
48+
{
49+
var act = () => Cat.QueryWithCuteness
50+
.OnTable("TABLE")
51+
.ToGetRequestBuilder(x => x.Cuteness, x => x.Name)
52+
.Build((2.3, ""));
53+
54+
act.Should()
55+
.Throw<DynamoDBMarshallingException>()
56+
.WithMessage("Value '*' from argument '*' is not convertable*");
57+
}
58+
59+
[Fact]
60+
public void Build_Request_WithInvalidPartitionKey()
61+
{
62+
var act = () => Cat.QueryWithCuteness
63+
.OnTable("TABLE")
64+
.ToGetRequestBuilder(x => x.Name)
65+
.Build("TEST");
66+
act.Should()
67+
.Throw<DynamoDBMarshallingException>()
68+
.WithMessage("Value '*' from argument '*' is not convertable*");
69+
}
70+
1971
[Fact]
2072
public void Build_Request_PartitionKeyOnly()
2173
{
@@ -32,6 +84,7 @@ public void Build_Request_PartitionKeyOnly()
3284
request.TableName.Should().Be("TABLE");
3385
});
3486
}
87+
3588
[Fact]
3689
public void Build_Request_CompositeKeys()
3790
{
@@ -43,8 +96,8 @@ public void Build_Request_CompositeKeys()
4396
.Should()
4497
.BeEquivalentTo(new Dictionary<string, AttributeValue>()
4598
{
46-
{ nameof(Cat.Id), new AttributeValue { S = keys.PartitionKey.ToString() } } ,
47-
{ nameof(Cat.HomeId), new AttributeValue { S = keys.RangeKey.ToString() } }
99+
{ nameof(Cat.Id), new AttributeValue { S = keys.PartitionKey.ToString() } },
100+
{ nameof(Cat.HomeId), new AttributeValue { S = keys.RangeKey.ToString() } }
48101
}
49102
);
50103

0 commit comments

Comments
 (0)