Skip to content

Commit

Permalink
Add the ability to mock Table operations in Document model
Browse files Browse the repository at this point in the history
  • Loading branch information
96malhar committed Aug 21, 2024
1 parent ad3d8a4 commit f72f194
Show file tree
Hide file tree
Showing 22 changed files with 787 additions and 462 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ internal Table GetUnconfiguredTable(string tableName, bool disableFetchingTableM

var emptyConfig = new TableConfig(tableName, conversion: null, consumer: Table.DynamoDBConsumer.DataModel,
storeAsEpoch: null, isEmptyStringValueEnabled: false, metadataCachingMode: Config.MetadataCachingMode);
table = Table.LoadTable(Client, emptyConfig);
table = Table.LoadTable(Client, emptyConfig) as Table;
tablesMap[tableName] = table;

return table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,20 +348,20 @@ public IEnumerable<T> FromQuery<T>(QueryOperationConfig queryConfig, FromQueryCo
#region Table methods

/// <inheritdoc/>
public Table GetTargetTable<T>()
public ITable GetTargetTable<T>()
{
return GetTargetTable<T>((GetTargetTableConfig)null);
}

/// <inheritdoc/>
[Obsolete("Use the GetTargetTable overload that takes GetTargetTableConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to GetTargetTable.")]
public Table GetTargetTable<T>(DynamoDBOperationConfig operationConfig = null)
public ITable GetTargetTable<T>(DynamoDBOperationConfig operationConfig = null)
{
return GetTargetTableInternal<T>(new DynamoDBFlatConfig(operationConfig, Config));
}

/// <inheritdoc/>
public Table GetTargetTable<T>(GetTargetTableConfig getTargetTableConfig)
public ITable GetTargetTable<T>(GetTargetTableConfig getTargetTableConfig)
{
return GetTargetTableInternal<T>(new DynamoDBFlatConfig(getTargetTableConfig?.ToDynamoDBOperationConfig(), Config));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ partial interface IDynamoDBContext
/// </summary>
/// <typeparam name="T">Type to retrieve table for</typeparam>
/// <returns>Table object</returns>
Table GetTargetTable<T>();
ITable GetTargetTable<T>();

/// <summary>
/// Retrieves the target table for the specified type
Expand All @@ -602,15 +602,15 @@ partial interface IDynamoDBContext
/// <param name="operationConfig">Config object which can be used to override that table used.</param>
/// <returns>Table object</returns>
[Obsolete("Use the GetTargetTable overload that takes GetTargetTableConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to GetTargetTable.")]
Table GetTargetTable<T>(DynamoDBOperationConfig operationConfig = null);
ITable GetTargetTable<T>(DynamoDBOperationConfig operationConfig = null);

/// <summary>
/// Retrieves the target table for the specified type
/// </summary>
/// <typeparam name="T">Type to retrieve table for</typeparam>
/// <param name="getTargetTableConfig">Config object that can be used to override properties on the table's context for this request.</param>
/// <returns>Table object</returns>
Table GetTargetTable<T>(GetTargetTableConfig getTargetTableConfig);
ITable GetTargetTable<T>(GetTargetTableConfig getTargetTableConfig);

#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
*/

using System;
using System.Collections.Generic;
using System.Linq;

using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.Model;

namespace Amazon.DynamoDBv2.DataModel
{
Expand All @@ -27,20 +24,20 @@ public partial class DynamoDBContext : IDynamoDBContext
#region Table methods

/// <inheritdoc/>
public Table GetTargetTable<T>()
public ITable GetTargetTable<T>()
{
return GetTargetTableInternal<T>(new DynamoDBFlatConfig(null, Config));
}

/// <inheritdoc/>
[Obsolete("Use the GetTargetTable overload that takes GetTargetTableConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to GetTargetTable.")]
public Table GetTargetTable<T>(DynamoDBOperationConfig operationConfig = null)
public ITable GetTargetTable<T>(DynamoDBOperationConfig operationConfig = null)
{
return GetTargetTableInternal<T>(new DynamoDBFlatConfig(operationConfig, Config));
}

/// <inheritdoc/>
public Table GetTargetTable<T>(GetTargetTableConfig getTargetTableConfig)
public ITable GetTargetTable<T>(GetTargetTableConfig getTargetTableConfig)
{
return GetTargetTableInternal<T>(new DynamoDBFlatConfig(getTargetTableConfig?.ToDynamoDBOperationConfig(), Config));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
*/

using System;
using System.Collections.Generic;

using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.Model;

namespace Amazon.DynamoDBv2.DataModel
{
Expand All @@ -34,22 +32,22 @@ partial interface IDynamoDBContext
/// </summary>
/// <typeparam name="T">Type to retrieve table for</typeparam>
/// <returns>Table object</returns>
Table GetTargetTable<T>();
ITable GetTargetTable<T>();

/// <summary>
/// Retrieves the target table for the specified type
/// </summary>
/// <typeparam name="T">Type to retrieve table for</typeparam>
/// <returns>Table object</returns>
[Obsolete("Use the GetTargetTable overload that takes GetTargetTableConfig instead, since DynamoDBOperationConfig contains properties that are not applicable to GetTargetTable.")]
Table GetTargetTable<T>(DynamoDBOperationConfig operationConfig = null);
ITable GetTargetTable<T>(DynamoDBOperationConfig operationConfig = null);

/// <summary>
/// Retrieves the target table for the specified type
/// </summary>
/// <typeparam name="T">Type to retrieve table for</typeparam>
/// <returns>Table object</returns>
Table GetTargetTable<T>(GetTargetTableConfig getTargetTableConfig);
ITable GetTargetTable<T>(GetTargetTableConfig getTargetTableConfig);

#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public partial interface IDocumentBatchGet
/// MultiTableDocumentBatchGet consisting of the two DocumentBatchGet
/// objects.
/// </returns>
MultiTableDocumentBatchGet Combine(IDocumentBatchGet otherBatch);
IMultiTableDocumentBatchGet Combine(IDocumentBatchGet otherBatch);
}

/// <summary>
Expand Down Expand Up @@ -147,7 +147,7 @@ public void AddKey(IDictionary<string, DynamoDBEntry> key)
}

/// <inheritdoc/>
public MultiTableDocumentBatchGet Combine(IDocumentBatchGet otherBatch)
public IMultiTableDocumentBatchGet Combine(IDocumentBatchGet otherBatch)
{
return new MultiTableDocumentBatchGet(this, otherBatch);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public partial interface IDocumentBatchWrite
/// MultiTableDocumentBatchWrite consisting of the two DocumentBatchWrite
/// objects.
/// </returns>
MultiTableDocumentBatchWrite Combine(IDocumentBatchWrite otherBatch);
IMultiTableDocumentBatchWrite Combine(IDocumentBatchWrite otherBatch);
}

/// <summary>
Expand Down Expand Up @@ -146,7 +146,7 @@ public void AddDocumentToPut(Document document)
#region Public methods

/// <inheritdoc/>
public MultiTableDocumentBatchWrite Combine(IDocumentBatchWrite otherBatch)
public IMultiTableDocumentBatchWrite Combine(IDocumentBatchWrite otherBatch)
{
return new MultiTableDocumentBatchWrite(this, otherBatch);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public partial interface IDocumentTransactGet
/// <returns>
/// MultiTableDocumentTransactGet consisting of the two DocumentTransactGet objects.
/// </returns>
MultiTableDocumentTransactGet Combine(IDocumentTransactGet otherTransactionPart);
IMultiTableDocumentTransactGet Combine(IDocumentTransactGet otherTransactionPart);
}

/// <summary>
Expand Down Expand Up @@ -174,7 +174,7 @@ public void AddKey(IDictionary<string, DynamoDBEntry> key, TransactGetItemOperat
}

/// <inheritdoc/>
public MultiTableDocumentTransactGet Combine(IDocumentTransactGet otherTransactionPart)
public IMultiTableDocumentTransactGet Combine(IDocumentTransactGet otherTransactionPart)
{
return new MultiTableDocumentTransactGet(this, otherTransactionPart);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public partial interface IDocumentTransactWrite
/// <returns>
/// MultiTableDocumentTransactWrite consisting of the two DocumentTransactWrite objects.
/// </returns>
MultiTableDocumentTransactWrite Combine(IDocumentTransactWrite otherTransactionPart);
IMultiTableDocumentTransactWrite Combine(IDocumentTransactWrite otherTransactionPart);
}

/// <summary>
Expand Down Expand Up @@ -529,7 +529,7 @@ private static bool TryFilterDuplicates<T>(Dictionary<string, T> src, Dictionary
#region Public methods

/// <inheritdoc/>
public MultiTableDocumentTransactWrite Combine(IDocumentTransactWrite otherTransactionPart)
public IMultiTableDocumentTransactWrite Combine(IDocumentTransactWrite otherTransactionPart)
{
return new MultiTableDocumentTransactWrite(this, otherTransactionPart);
}
Expand Down
Loading

0 comments on commit f72f194

Please sign in to comment.