unit tests for repo update methods

This commit is contained in:
Sean Garrett
2023-07-06 18:32:00 +01:00
parent 26b71ff76e
commit 3a7b24262e
15 changed files with 6730 additions and 22 deletions
@@ -504,5 +504,22 @@ namespace MongoDbGenericRepository.DataAccess.Update
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
/// <summary>
/// For the entities selected by the filter, apply the update definition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <typeparam name="TKey">The type of the primary key for a Document.</typeparam>
/// <param name="filter">The document filter.</param>
/// <param name="updateDefinition">The update definition.</param>
/// <param name="partitionKey">The value of the partition key.</param>
/// <param name="cancellationToken">The optional cancellation token.</param>
long UpdateMany<TDocument, TKey>(
Expression<Func<TDocument, bool>> filter,
UpdateDefinition<TDocument> updateDefinition,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;
}
}
@@ -253,5 +253,19 @@ namespace MongoDbGenericRepository.DataAccess.Update
var updateRes = collection.UpdateMany(filter, updateDefinition, cancellationToken: cancellationToken);
return updateRes.ModifiedCount;
}
/// <inheritdoc cref="IMongoDbUpdater" />
public virtual long UpdateMany<TDocument, TKey>(
Expression<Func<TDocument, bool>> filter,
UpdateDefinition<TDocument> updateDefinition,
string partitionKey = null,
CancellationToken cancellationToken = default)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var collection = string.IsNullOrEmpty(partitionKey) ? GetCollection<TDocument, TKey>() : GetCollection<TDocument, TKey>(partitionKey);
var updateRes = collection.UpdateMany(filter, updateDefinition, cancellationToken: cancellationToken);
return updateRes.ModifiedCount;
}
}
}