Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
493 changes: 493 additions & 0 deletions CoreIntegrationTests/Infrastructure/MongoDbDocumentTestBase.Main.cs

Large diffs are not rendered by default.

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions MongoDbGenericRepository/Abstractions/IBaseMongoRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ public interface IBaseMongoRepository :
IBaseMongoRepository_Delete,
IBaseMongoRepository_Index
{
/// <summary>
/// Asynchronously returns a paginated list of the documents matching the filter condition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="condition">A mongodb filter definition.</param>
/// <param name="findOption">A mongodb filter option.</param>
/// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param>
/// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<List<TDocument>> GetPaginatedAsync<TDocument>(FilterDefinition<TDocument> condition, FindOptions findOption = null, int skipNumber = 0, int takeNumber = 50, string partitionKey = null)
where TDocument : IDocument;

/// <summary>
/// Asynchronously returns a paginated list of the documents matching the filter condition.
/// </summary>
Expand All @@ -28,6 +40,20 @@ public interface IBaseMongoRepository :
Task<List<TDocument>> GetPaginatedAsync<TDocument>(Expression<Func<TDocument, bool>> filter, int skipNumber = 0, int takeNumber = 50, string partitionKey = null)
where TDocument : IDocument;

/// <summary>
/// Asynchronously returns a paginated list of the documents matching the filter condition.
/// </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="condition">A mongodb filter definition.</param>
/// <param name="findOption">A mongodb filter option.</param>
/// <param name="skipNumber">The number of documents you want to skip. Default value is 0.</param>
/// <param name="takeNumber">The number of documents you want to take. Default value is 50.</param>
/// <param name="partitionKey">An optional partition key.</param>
Task<List<TDocument>> GetPaginatedAsync<TDocument, TKey>(FilterDefinition<TDocument> condition, FindOptions findOption = null, int skipNumber = 0, int takeNumber = 50, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;

/// <summary>
/// Asynchronously returns a paginated list of the documents matching the filter condition.
/// </summary>
Expand Down
332 changes: 332 additions & 0 deletions MongoDbGenericRepository/Abstractions/IBaseReadOnlyRepository.cs

Large diffs are not rendered by default.

249 changes: 249 additions & 0 deletions MongoDbGenericRepository/Abstractions/IReadOnlyMongoRepository.TKey.cs

Large diffs are not rendered by default.

175 changes: 175 additions & 0 deletions MongoDbGenericRepository/BaseMongoRepository.Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using MongoDB.Driver;

namespace MongoDbGenericRepository
{
Expand Down Expand Up @@ -31,6 +32,19 @@ Task<long> DeleteOneAsync<TDocument, TKey>(TDocument document)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;

/// <summary>
/// Deletes a document matching the condition of the filter 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="condition">A mongodb filter definition.</param>
/// <param name="deleteOption">A mongodb delete option.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteOne<TDocument, TKey>(FilterDefinition<TDocument> condition, DeleteOptions deleteOption = null, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;

/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
Expand All @@ -43,6 +57,20 @@ long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;

/// <summary>
/// Asynchronously deletes a document matching the condition of the filter 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="condition">A mongodb filter definition.</param>
/// <param name="deleteOption">A mongodb delete option.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
Task<long> DeleteOneAsync<TDocument, TKey>(FilterDefinition<TDocument> condition, DeleteOptions deleteOption = null,
string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;

/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// </summary>
Expand All @@ -54,6 +82,19 @@ long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string
Task<long> DeleteOneAsync<TDocument, TKey>(Expression<Func<TDocument, bool>> filter, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;

/// <summary>
/// Asynchronously deletes the documents matching the condition of the filter 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="condition">A mongodb filter definition.</param>
/// <param name="deleteOption">A mongodb delete option.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
Task<long> DeleteManyAsync<TDocument, TKey>(FilterDefinition<TDocument> condition, DeleteOptions deleteOption = null, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;

/// <summary>
/// Asynchronously deletes the documents matching the condition of the LINQ expression filter.
Expand Down Expand Up @@ -88,6 +129,19 @@ Task<long> DeleteManyAsync<TDocument, TKey>(IEnumerable<TDocument> documents)
long DeleteMany<TDocument, TKey>(IEnumerable<TDocument> documents)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;

/// <summary>
/// Deletes the documents matching the condition of the filter 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="condition">A mongodb filter definition.</param>
/// <param name="deleteOption">A mongodb delete option.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
long DeleteMany<TDocument, TKey>(FilterDefinition<TDocument> condition, DeleteOptions deleteOption = null, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>;

/// <summary>
/// Deletes the documents matching the condition of the LINQ expression filter.
Expand Down Expand Up @@ -147,6 +201,19 @@ public virtual long DeleteOne<TDocument>(TDocument document) where TDocument : I
{
return MongoDbEraser.DeleteOne<TDocument, Guid>(document);
}

/// <summary>
/// Deletes a document.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="condition">A mongodb filter definition.</param>
/// <param name="deleteOption">A mongodb delete option.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
public virtual long DeleteOne<TDocument>(FilterDefinition<TDocument> condition, DeleteOptions deleteOption = null, string partitionKey = null) where TDocument : IDocument<Guid>
{
return MongoDbEraser.DeleteOne<TDocument, Guid>(condition, deleteOption, partitionKey).DeletedCount;
}

/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
Expand All @@ -160,6 +227,20 @@ public virtual long DeleteOne<TDocument>(Expression<Func<TDocument, bool>> filte
return MongoDbEraser.DeleteOne<TDocument, Guid>(filter, partitionKey);
}

/// <summary>
/// Asynchronously deletes a document matching the condition of the filter definition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="condition">A mongodb filter definition.</param>
/// <param name="deleteOption">A mongodb delete option.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
public virtual async Task<long> DeleteOneAsync<TDocument>(FilterDefinition<TDocument> condition, DeleteOptions deleteOption = null, string partitionKey = null) where TDocument : IDocument<Guid>
{
var result = await MongoDbEraser.DeleteOneAsync<TDocument, Guid>(condition, deleteOption, partitionKey);
return result.DeletedCount;
}

/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// </summary>
Expand All @@ -172,6 +253,20 @@ public virtual async Task<long> DeleteOneAsync<TDocument>(Expression<Func<TDocum
return await MongoDbEraser.DeleteOneAsync<TDocument, Guid>(filter, partitionKey);
}

/// <summary>
/// Asynchronously deletes the documents matching the condition of the filter definition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="condition">A mongodb filter definition.</param>
/// <param name="deleteOption">A mongodb delete option.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
public virtual async Task<long> DeleteManyAsync<TDocument>(FilterDefinition<TDocument> condition, DeleteOptions deleteOption = null, string partitionKey = null) where TDocument : IDocument<Guid>
{
var result = await MongoDbEraser.DeleteManyAsync<TDocument, Guid>(condition, deleteOption, partitionKey);
return result.DeletedCount;
}

/// <summary>
/// Asynchronously deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
Expand Down Expand Up @@ -206,6 +301,19 @@ public virtual long DeleteMany<TDocument>(IEnumerable<TDocument> documents) wher
return DeleteMany<TDocument, Guid>(documents);
}

/// <summary>
/// Deletes the documents matching the condition of the filter definition.
/// </summary>
/// <typeparam name="TDocument">The type representing a Document.</typeparam>
/// <param name="condition">A mongodb filter definition.</param>
/// <param name="deleteOption">A mongodb delete option.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
public long DeleteMany<TDocument>(FilterDefinition<TDocument> condition, DeleteOptions deleteOption = null, string partitionKey = null) where TDocument : IDocument<Guid>
{
return MongoDbEraser.DeleteMany<TDocument, Guid>(condition, deleteOption, partitionKey).DeletedCount;
}

/// <summary>
/// Deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
Expand Down Expand Up @@ -250,6 +358,23 @@ public virtual async Task<long> DeleteOneAsync<TDocument, TKey>(TDocument docume
return await MongoDbEraser.DeleteOneAsync<TDocument, TKey>(document);
}

/// <summary>
/// Deletes a document matching the condition of the filter 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="condition">A mongodb filter definition.</param>
/// <param name="deleteOption">A mongodb delete option.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
public virtual long DeleteOne<TDocument, TKey>(FilterDefinition<TDocument> condition, DeleteOptions deleteOption = null,
string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
return MongoDbEraser.DeleteOne<TDocument, TKey>(condition, deleteOption, partitionKey).DeletedCount;
}

/// <summary>
/// Deletes a document matching the condition of the LINQ expression filter.
/// </summary>
Expand All @@ -265,6 +390,24 @@ public virtual long DeleteOne<TDocument, TKey>(Expression<Func<TDocument, bool>>
return MongoDbEraser.DeleteOne<TDocument, TKey>(filter, partitionKey);
}

/// <summary>
/// Deletes a document matching the condition of the filter 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="condition">A mongodb filter definition.</param>
/// <param name="deleteOption">A mongodb delete option.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
public virtual async Task<long> DeleteOneAsync<TDocument, TKey>(FilterDefinition<TDocument> condition,
DeleteOptions deleteOption = null, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var result = await MongoDbEraser.DeleteOneAsync<TDocument, TKey>(condition, deleteOption, partitionKey);
return result.DeletedCount;
}

/// <summary>
/// Asynchronously deletes a document matching the condition of the LINQ expression filter.
/// </summary>
Expand All @@ -280,6 +423,24 @@ public virtual async Task<long> DeleteOneAsync<TDocument, TKey>(Expression<Func<
return await MongoDbEraser.DeleteOneAsync<TDocument, TKey>(filter, partitionKey);
}

/// <summary>
/// Asynchronously deletes the documents matching the condition of the filter 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="condition">A mongodb filter definition.</param>
/// <param name="deleteOption">A mongodb delete option.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
public virtual async Task<long> DeleteManyAsync<TDocument, TKey>(FilterDefinition<TDocument> condition,
DeleteOptions deleteOption = null, string partitionKey = null)
where TDocument : IDocument<TKey>
where TKey : IEquatable<TKey>
{
var result = await MongoDbEraser.DeleteManyAsync<TDocument, TKey>(condition, deleteOption, partitionKey);
return result.DeletedCount;
}

/// <summary>
/// Asynchronously deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
Expand Down Expand Up @@ -323,6 +484,20 @@ public virtual long DeleteMany<TDocument, TKey>(IEnumerable<TDocument> documents
return MongoDbEraser.DeleteMany<TDocument, TKey>(documents);
}

/// <summary>
/// Deletes the documents matching the condition of the filter 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="condition">A mongodb filter definition.</param>
/// <param name="deleteOption">A mongodb delete option.</param>
/// <param name="partitionKey">An optional partition key.</param>
/// <returns>The number of documents deleted.</returns>
public virtual long DeleteMany<TDocument, TKey>(FilterDefinition<TDocument> condition, DeleteOptions deleteOption = null, string partitionKey = null) where TDocument : IDocument<TKey> where TKey : IEquatable<TKey>
{
return MongoDbEraser.DeleteMany<TDocument, TKey>(condition, deleteOption, partitionKey).DeletedCount;
}

/// <summary>
/// Deletes the documents matching the condition of the LINQ expression filter.
/// </summary>
Expand Down
Loading