-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Isolate the key marshallign functionlity publicly for improved intent
- Loading branch information
1 parent
bbc9ab6
commit 4751bdb
Showing
13 changed files
with
95 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,31 +7,31 @@ public partial class DynamoDBGsiKeyMarshallerTests | |
[Fact] | ||
public void PartitionKey_MissMatchedIndexName_ShouldThrow() | ||
{ | ||
var act = () => GsiHashAndRangeKeyMarshallerWithIndex("Unknown").PartitionKey("test"); | ||
var act = () => GsiHashAndRangeKeyMarshaller.IndexKeyMarshaller("Unknown").PartitionKey("test"); | ||
|
||
act.Should().Throw<ArgumentOutOfRangeException>(); | ||
} | ||
|
||
[Fact] | ||
public void RangeKey_MissMatchedIndexName_ShouldThrow() | ||
{ | ||
var act = () => GsiHashAndRangeKeyMarshallerWithIndex("Unknown").RangeKey("test"); | ||
var act = () => GsiHashAndRangeKeyMarshaller.IndexKeyMarshaller("Unknown").RangeKey("test"); | ||
|
||
act.Should().Throw<ArgumentOutOfRangeException>(); | ||
} | ||
|
||
[Fact] | ||
public void Keys_MissMatchedIndexName_ShouldThrow() | ||
{ | ||
var act = () => GsiHashAndRangeKeyMarshallerWithIndex("Unknown").Keys("1", 1); | ||
var act = () => GsiHashAndRangeKeyMarshaller.IndexKeyMarshaller("Unknown").Keys("1", 1); | ||
|
||
act.Should().Throw<ArgumentOutOfRangeException>(); | ||
} | ||
|
||
[Fact] | ||
public void PartitionKey_MatchedIndexName_ShouldMapCorrectly() | ||
{ | ||
GsiHashAndRangeKeyMarshallerWithIndex(GsiHashAndRangeKey.IndexName) | ||
GsiHashAndRangeKeyMarshaller.IndexKeyMarshaller(GsiHashAndRangeKey.IndexName) | ||
.PartitionKey("[email protected]") | ||
.Should() | ||
.SatisfyRespectively(x => | ||
|
@@ -44,7 +44,7 @@ public void PartitionKey_MatchedIndexName_ShouldMapCorrectly() | |
[Fact] | ||
public void RangeKey_MatchedIndexName_ShouldMapCorrectly() | ||
{ | ||
GsiHashAndRangeKeyMarshallerWithIndex(GsiHashAndRangeKey.IndexName) | ||
GsiHashAndRangeKeyMarshaller.IndexKeyMarshaller(GsiHashAndRangeKey.IndexName) | ||
.RangeKey(1) | ||
.Should() | ||
.SatisfyRespectively(x => | ||
|
@@ -57,7 +57,7 @@ public void RangeKey_MatchedIndexName_ShouldMapCorrectly() | |
[Fact] | ||
public void Keys_MatchedIndexName_ShouldMapCorrectly() | ||
{ | ||
GsiHashAndRangeKeyMarshallerWithIndex(GsiHashAndRangeKey.IndexName) | ||
GsiHashAndRangeKeyMarshaller.IndexKeyMarshaller(GsiHashAndRangeKey.IndexName) | ||
.Keys("[email protected]", 1) | ||
.Should() | ||
.SatisfyRespectively(x => | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,31 +7,31 @@ public partial class DynamoDBLsiKeyMarshallerTests | |
[Fact] | ||
public void PartitionKey_MissMatchedIndexName_ShouldThrow() | ||
{ | ||
var act = () => LsiHashAndRangeKeyMarshallerWithIndex("Unknown").PartitionKey("test"); | ||
var act = () => LsiHashAndRangeKeyMarshaller.IndexKeyMarshaller("Unknown").PartitionKey("test"); | ||
|
||
act.Should().Throw<ArgumentOutOfRangeException>(); | ||
} | ||
|
||
[Fact] | ||
public void RangeKey_MissMatchedIndexName_ShouldThrow() | ||
{ | ||
var act = () => LsiHashAndRangeKeyMarshallerWithIndex("Unknown").RangeKey("test"); | ||
var act = () => LsiHashAndRangeKeyMarshaller.IndexKeyMarshaller("Unknown").RangeKey("test"); | ||
|
||
act.Should().Throw<ArgumentOutOfRangeException>(); | ||
} | ||
|
||
[Fact] | ||
public void Keys_MissMatchedIndexName_ShouldThrow() | ||
{ | ||
var act = () => LsiHashAndRangeKeyMarshallerWithIndex("Unknown").Keys("1", 1); | ||
var act = () => LsiHashAndRangeKeyMarshaller.IndexKeyMarshaller("Unknown").Keys("1", 1); | ||
|
||
act.Should().Throw<ArgumentOutOfRangeException>(); | ||
} | ||
|
||
[Fact] | ||
public void PartitionKey_MatchedIndexName_ShouldMapCorrectly() | ||
{ | ||
LsiHashAndRangeKeyMarshallerWithIndex(LsiHashAndRangeKey.IndexName) | ||
LsiHashAndRangeKeyMarshaller.IndexKeyMarshaller(LsiHashAndRangeKey.IndexName) | ||
.PartitionKey("[email protected]") | ||
.Should() | ||
.SatisfyRespectively(x => | ||
|
@@ -44,7 +44,7 @@ public void PartitionKey_MatchedIndexName_ShouldMapCorrectly() | |
[Fact] | ||
public void RangeKey_MatchedIndexName_ShouldMapCorrectly() | ||
{ | ||
LsiHashAndRangeKeyMarshallerWithIndex(LsiHashAndRangeKey.IndexName) | ||
LsiHashAndRangeKeyMarshaller.IndexKeyMarshaller(LsiHashAndRangeKey.IndexName) | ||
.RangeKey(1) | ||
.Should() | ||
.SatisfyRespectively(x => | ||
|
@@ -57,7 +57,7 @@ public void RangeKey_MatchedIndexName_ShouldMapCorrectly() | |
[Fact] | ||
public void Keys_MatchedIndexName_ShouldMapCorrectly() | ||
{ | ||
LsiHashAndRangeKeyMarshallerWithIndex(LsiHashAndRangeKey.IndexName) | ||
LsiHashAndRangeKeyMarshaller.IndexKeyMarshaller(LsiHashAndRangeKey.IndexName) | ||
.Keys("[email protected]", 1) | ||
.Should() | ||
.SatisfyRespectively(x => | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
DynamoDBGenerator/Internal/DynamoDBKeyMarshallerDelegator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Amazon.DynamoDBv2.Model; | ||
namespace DynamoDBGenerator.Internal; | ||
|
||
/// <summary> | ||
/// This is an internal API that supports the source generator and not subject to | ||
/// the same compatibility standards as public APIs. It may be changed or removed without notice in | ||
/// any release. You should only use it directly in your code with extreme caution and knowing that | ||
/// doing so can result in application failures when updating to a new version. | ||
/// </summary> | ||
public sealed class DynamoDBKeyMarshallerDelegator : IDynamoDBKeyMarshaller | ||
|
||
{ | ||
private readonly Func<object?, object?, bool, bool, string?, Dictionary<string, AttributeValue>> _fn; | ||
public DynamoDBKeyMarshallerDelegator(Func<object?, object?, bool, bool, string?, Dictionary<string, AttributeValue>> fn) => _fn = fn; | ||
public Dictionary<string, AttributeValue> Keys(object partitionKey, object rangeKey) => _fn(partitionKey, rangeKey, true, true, null); | ||
public Dictionary<string, AttributeValue> PartitionKey(object key) => _fn(key, null, true, false, null); | ||
public Dictionary<string, AttributeValue> RangeKey(object key) => _fn(null, key, false, true, null); | ||
} |
Oops, something went wrong.