(refactor): review namespaces

This commit is contained in:
Maksym Sadovnychyy 2025-06-09 23:40:03 +02:00
parent e5898dbfe7
commit fa1e270882
15 changed files with 1361 additions and 1362 deletions

View File

@ -10,341 +10,335 @@ using MaksIT.MongoDB.Linq.Utilities;
using MaksIT.MongoDB.Linq.Tests.Mock;
namespace MaksIT.MongoDB.Tests {
namespace MaksIT.MongoDB.Tests;
// Sample DTO class for testing
public class TestableDocumentDto : DtoDocumentBase<Guid> {
public required string Name { get; set; }
// Sample DTO class for testing
public class TestableDocumentDto : DtoDocumentBase<Guid> {
public required string Name { get; set; }
}
// Generalized Testable class to simulate MongoDB operations using an in-memory list
public class TestableCollectionDataProvider : BaseCollectionDataProviderBase<TestableCollectionDataProvider, TestableDocumentDto, Guid> {
private readonly List<TestableDocumentDto> _inMemoryCollection;
public TestableCollectionDataProvider(ILogger<TestableCollectionDataProvider> logger)
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
: base(logger, new MongoClientMock(), "TestDatabase", "TestCollection") {
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
_inMemoryCollection = new List<TestableDocumentDto>(); // Initialize correctly
}
// Generalized Testable class to simulate MongoDB operations using an in-memory list
public class TestableCollectionDataProvider : BaseCollectionDataProviderBase<TestableCollectionDataProvider, TestableDocumentDto, Guid> {
private readonly List<TestableDocumentDto> _inMemoryCollection;
// Override protected methods to use in-memory list instead of a real database
protected override IQueryable<TestableDocumentDto> GetQuery() => _inMemoryCollection.AsQueryable();
public TestableCollectionDataProvider(ILogger<TestableCollectionDataProvider> logger)
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
: base(logger, new MongoClientMock(), "TestDatabase", "TestCollection") {
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
_inMemoryCollection = new List<TestableDocumentDto>(); // Initialize correctly
protected override async Task<Result<Guid>> InsertAsync(TestableDocumentDto document, IClientSessionHandle? session) {
_inMemoryCollection.Add(document);
return await Task.FromResult(Result<Guid>.Ok(document.Id));
}
protected override async Task<Result<List<Guid>?>> InsertManyAsync(List<TestableDocumentDto> documents, IClientSessionHandle? session) {
_inMemoryCollection.AddRange(documents);
return await Task.FromResult(Result<List<Guid>?>.Ok(documents.Select(d => d.Id).ToList()));
}
protected override async Task<Result<Guid>> UpsertWithPredicateAsync(TestableDocumentDto document, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
var existingDocument = _inMemoryCollection.FirstOrDefault(predicate.Compile());
if (existingDocument != null) {
_inMemoryCollection.Remove(existingDocument);
}
_inMemoryCollection.Add(document);
return await Task.FromResult(Result<Guid>.Ok(document.Id));
}
// Override protected methods to use in-memory list instead of a real database
protected override IQueryable<TestableDocumentDto> GetQuery() => _inMemoryCollection.AsQueryable();
protected override async Task<Result<List<Guid>?>> UpsertManyWithPredicateAsync(List<TestableDocumentDto> documents, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
var existingDocuments = _inMemoryCollection.Where(predicate.Compile()).ToList();
foreach (var doc in existingDocuments) {
_inMemoryCollection.Remove(doc);
}
_inMemoryCollection.AddRange(documents);
return await Task.FromResult(Result<List<Guid>?>.Ok(documents.Select(d => d.Id).ToList()));
}
protected override async Task<Result<Guid>> InsertAsync(TestableDocumentDto document, IClientSessionHandle? session) {
protected override async Task<Result<Guid>> UpdateWithPredicateAsync(TestableDocumentDto document, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
var existingDocument = _inMemoryCollection.FirstOrDefault(predicate.Compile());
if (existingDocument != null) {
_inMemoryCollection.Remove(existingDocument);
_inMemoryCollection.Add(document);
return await Task.FromResult(Result<Guid>.Ok(document.Id));
}
return await Task.FromResult(Result<Guid>.InternalServerError(default(Guid), "Update failed"));
}
protected override async Task<Result<List<Guid>?>> InsertManyAsync(List<TestableDocumentDto> documents, IClientSessionHandle? session) {
_inMemoryCollection.AddRange(documents);
return await Task.FromResult(Result<List<Guid>?>.Ok(documents.Select(d => d.Id).ToList()));
}
protected override async Task<Result<Guid>> UpsertWithPredicateAsync(TestableDocumentDto document, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
var existingDocument = _inMemoryCollection.FirstOrDefault(predicate.Compile());
if (existingDocument != null) {
_inMemoryCollection.Remove(existingDocument);
}
_inMemoryCollection.Add(document);
return await Task.FromResult(Result<Guid>.Ok(document.Id));
}
protected override async Task<Result<List<Guid>?>> UpsertManyWithPredicateAsync(List<TestableDocumentDto> documents, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
var existingDocuments = _inMemoryCollection.Where(predicate.Compile()).ToList();
protected override async Task<Result<List<Guid>?>> UpdateManyWithPredicateAsync(List<TestableDocumentDto> documents, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
var existingDocuments = _inMemoryCollection.Where(predicate.Compile()).ToList();
if (existingDocuments.Any()) {
foreach (var doc in existingDocuments) {
_inMemoryCollection.Remove(doc);
}
_inMemoryCollection.AddRange(documents);
return await Task.FromResult(Result<List<Guid>?>.Ok(documents.Select(d => d.Id).ToList()));
}
protected override async Task<Result<Guid>> UpdateWithPredicateAsync(TestableDocumentDto document, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
var existingDocument = _inMemoryCollection.FirstOrDefault(predicate.Compile());
if (existingDocument != null) {
_inMemoryCollection.Remove(existingDocument);
_inMemoryCollection.Add(document);
return await Task.FromResult(Result<Guid>.Ok(document.Id));
}
return await Task.FromResult(Result<Guid>.InternalServerError(default(Guid), "Update failed"));
}
protected override async Task<Result<List<Guid>?>> UpdateManyWithPredicateAsync(List<TestableDocumentDto> documents, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
var existingDocuments = _inMemoryCollection.Where(predicate.Compile()).ToList();
if (existingDocuments.Any()) {
foreach (var doc in existingDocuments) {
_inMemoryCollection.Remove(doc);
}
_inMemoryCollection.AddRange(documents);
return await Task.FromResult(Result<List<Guid>?>.Ok(documents.Select(d => d.Id).ToList()));
}
return await Task.FromResult(Result<List<Guid>?>.InternalServerError(default, "UpdateMany failed"));
}
protected override async Task<Result> DeleteWithPredicateAsync(Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
var documentToRemove = _inMemoryCollection.FirstOrDefault(predicate.Compile());
if (documentToRemove != null) {
_inMemoryCollection.Remove(documentToRemove);
return await Task.FromResult(Result.Ok());
}
return await Task.FromResult(Result.InternalServerError("Delete failed"));
}
protected override async Task<Result> DeleteManyWithPredicateAsync(Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
var documentsToRemove = _inMemoryCollection.Where(predicate.Compile()).ToList();
if (documentsToRemove.Any()) {
foreach (var doc in documentsToRemove) {
_inMemoryCollection.Remove(doc);
}
return await Task.FromResult(Result.Ok());
}
return await Task.FromResult(Result.InternalServerError("DeleteMany failed"));
}
// Expose protected methods as public with different names for testing purposes
public async Task<Result<Guid>> TestInsertAsync(TestableDocumentDto document, IClientSessionHandle? session = null) {
return await InsertAsync(document, session);
}
public async Task<Result<List<Guid>?>> TestInsertManyAsync(List<TestableDocumentDto> documents, IClientSessionHandle? session = null) {
return await InsertManyAsync(documents, session);
}
public async Task<Result<Guid>> TestUpsertWithPredicateAsync(TestableDocumentDto document, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session = null) {
return await UpsertWithPredicateAsync(document, predicate, session);
}
public async Task<Result<List<Guid>?>> TestUpsertManyWithPredicateAsync(List<TestableDocumentDto> documents, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session = null) {
return await UpsertManyWithPredicateAsync(documents, predicate, session);
}
public async Task<Result<Guid>> TestUpdateWithPredicateAsync(TestableDocumentDto document, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session = null) {
return await UpdateWithPredicateAsync(document, predicate, session);
}
public async Task<Result<List<Guid>?>> TestUpdateManyWithPredicateAsync(List<TestableDocumentDto> documents, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session = null) {
return await UpdateManyWithPredicateAsync(documents, predicate, session);
}
public async Task<Result> TestDeleteWithPredicateAsync(Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session = null) {
return await DeleteWithPredicateAsync(predicate, session);
}
public async Task<Result> TestDeleteManyWithPredicateAsync(Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session = null) {
return await DeleteManyWithPredicateAsync(predicate, session);
}
// Helper method to access the in-memory collection for validation
public IQueryable<TestableDocumentDto> GetInMemoryCollection() {
return _inMemoryCollection.AsQueryable();
}
return await Task.FromResult(Result<List<Guid>?>.InternalServerError(default, "UpdateMany failed"));
}
public class TestableCollectionDataProviderTests {
private readonly TestableCollectionDataProvider _dataProvider;
public TestableCollectionDataProviderTests() {
// Set up a mock logger
var logger = new LoggerFactory().CreateLogger<TestableCollectionDataProvider>();
_dataProvider = new TestableCollectionDataProvider(logger);
protected override async Task<Result> DeleteWithPredicateAsync(Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
var documentToRemove = _inMemoryCollection.FirstOrDefault(predicate.Compile());
if (documentToRemove != null) {
_inMemoryCollection.Remove(documentToRemove);
return await Task.FromResult(Result.Ok());
}
return await Task.FromResult(Result.InternalServerError("Delete failed"));
}
[Fact]
public async Task TestInsertAsync_ShouldReturnOkResult_WhenDocumentIsInserted() {
// Arrange
var document = new TestableDocumentDto {
Id = CombGuidGenerator.CreateCombGuid(),
Name = "Test Document"
};
// Act
var result = await _dataProvider.TestInsertAsync(document, null);
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(document.Id, result.Value);
protected override async Task<Result> DeleteManyWithPredicateAsync(Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
var documentsToRemove = _inMemoryCollection.Where(predicate.Compile()).ToList();
if (documentsToRemove.Any()) {
foreach (var doc in documentsToRemove) {
_inMemoryCollection.Remove(doc);
}
return await Task.FromResult(Result.Ok());
}
return await Task.FromResult(Result.InternalServerError("DeleteMany failed"));
}
[Fact]
public async Task TestInsertManyAsync_ShouldReturnOkResult_WhenDocumentsAreInserted() {
// Arrange
var documents = new List<TestableDocumentDto>
{
// Expose protected methods as public with different names for testing purposes
public async Task<Result<Guid>> TestInsertAsync(TestableDocumentDto document, IClientSessionHandle? session = null) {
return await InsertAsync(document, session);
}
public async Task<Result<List<Guid>?>> TestInsertManyAsync(List<TestableDocumentDto> documents, IClientSessionHandle? session = null) {
return await InsertManyAsync(documents, session);
}
public async Task<Result<Guid>> TestUpsertWithPredicateAsync(TestableDocumentDto document, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session = null) {
return await UpsertWithPredicateAsync(document, predicate, session);
}
public async Task<Result<List<Guid>?>> TestUpsertManyWithPredicateAsync(List<TestableDocumentDto> documents, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session = null) {
return await UpsertManyWithPredicateAsync(documents, predicate, session);
}
public async Task<Result<Guid>> TestUpdateWithPredicateAsync(TestableDocumentDto document, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session = null) {
return await UpdateWithPredicateAsync(document, predicate, session);
}
public async Task<Result<List<Guid>?>> TestUpdateManyWithPredicateAsync(List<TestableDocumentDto> documents, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session = null) {
return await UpdateManyWithPredicateAsync(documents, predicate, session);
}
public async Task<Result> TestDeleteWithPredicateAsync(Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session = null) {
return await DeleteWithPredicateAsync(predicate, session);
}
public async Task<Result> TestDeleteManyWithPredicateAsync(Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session = null) {
return await DeleteManyWithPredicateAsync(predicate, session);
}
// Helper method to access the in-memory collection for validation
public IQueryable<TestableDocumentDto> GetInMemoryCollection() {
return _inMemoryCollection.AsQueryable();
}
}
public class TestableCollectionDataProviderTests {
private readonly TestableCollectionDataProvider _dataProvider;
public TestableCollectionDataProviderTests() {
// Set up a mock logger
var logger = new LoggerFactory().CreateLogger<TestableCollectionDataProvider>();
_dataProvider = new TestableCollectionDataProvider(logger);
}
[Fact]
public async Task TestInsertAsync_ShouldReturnOkResult_WhenDocumentIsInserted() {
// Arrange
var document = new TestableDocumentDto {
Id = CombGuidGenerator.CreateCombGuid(),
Name = "Test Document"
};
// Act
var result = await _dataProvider.TestInsertAsync(document, null);
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(document.Id, result.Value);
}
[Fact]
public async Task TestInsertManyAsync_ShouldReturnOkResult_WhenDocumentsAreInserted() {
// Arrange
var documents = new List<TestableDocumentDto>
{
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" },
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" }
};
// Act
var result = await _dataProvider.TestInsertManyAsync(documents, null);
// Act
var result = await _dataProvider.TestInsertManyAsync(documents, null);
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(2, result.Value?.Count);
}
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(2, result.Value?.Count);
}
[Fact]
public async Task TestUpsertWithPredicateAsync_ShouldInsertNewDocument_WhenNoMatchingDocumentExists() {
// Arrange
var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Test Document" };
[Fact]
public async Task TestUpsertWithPredicateAsync_ShouldInsertNewDocument_WhenNoMatchingDocumentExists() {
// Arrange
var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Test Document" };
// Act
var result = await _dataProvider.TestUpsertWithPredicateAsync(document, x => x.Id == document.Id, null);
// Act
var result = await _dataProvider.TestUpsertWithPredicateAsync(document, x => x.Id == document.Id, null);
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(document.Id, result.Value);
}
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(document.Id, result.Value);
}
[Fact]
public async Task TestUpsertWithPredicateAsync_ShouldUpdateExistingDocument_WhenMatchingDocumentExists() {
// Arrange
var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Initial Document" };
await _dataProvider.TestInsertAsync(document, null);
[Fact]
public async Task TestUpsertWithPredicateAsync_ShouldUpdateExistingDocument_WhenMatchingDocumentExists() {
// Arrange
var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Initial Document" };
await _dataProvider.TestInsertAsync(document, null);
var updatedDocument = new TestableDocumentDto { Id = document.Id, Name = "Updated Document" };
var updatedDocument = new TestableDocumentDto { Id = document.Id, Name = "Updated Document" };
// Act
var result = await _dataProvider.TestUpsertWithPredicateAsync(updatedDocument, x => x.Id == document.Id, null);
// Act
var result = await _dataProvider.TestUpsertWithPredicateAsync(updatedDocument, x => x.Id == document.Id, null);
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(updatedDocument.Id, result.Value);
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(updatedDocument.Id, result.Value);
var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == updatedDocument.Id);
Assert.NotNull(inMemoryCollection);
Assert.Equal("Updated Document", inMemoryCollection.Name);
}
var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == updatedDocument.Id);
Assert.NotNull(inMemoryCollection);
Assert.Equal("Updated Document", inMemoryCollection.Name);
}
[Fact]
public async Task TestUpsertManyWithPredicateAsync_ShouldInsertNewDocuments_WhenNoMatchingDocumentsExist() {
// Arrange
var documents = new List<TestableDocumentDto>
{
[Fact]
public async Task TestUpsertManyWithPredicateAsync_ShouldInsertNewDocuments_WhenNoMatchingDocumentsExist() {
// Arrange
var documents = new List<TestableDocumentDto>
{
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" },
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" }
};
// Act
var result = await _dataProvider.TestUpsertManyWithPredicateAsync(documents, x => documents.Select(d => d.Id).Contains(x.Id), null);
// Act
var result = await _dataProvider.TestUpsertManyWithPredicateAsync(documents, x => documents.Select(d => d.Id).Contains(x.Id), null);
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(2, result.Value?.Count);
}
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(2, result.Value?.Count);
}
[Fact]
public async Task TestUpdateWithPredicateAsync_ShouldUpdateDocument_WhenMatchingDocumentExists() {
// Arrange
var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Initial Document" };
await _dataProvider.TestInsertAsync(document, null);
[Fact]
public async Task TestUpdateWithPredicateAsync_ShouldUpdateDocument_WhenMatchingDocumentExists() {
// Arrange
var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Initial Document" };
await _dataProvider.TestInsertAsync(document, null);
var updatedDocument = new TestableDocumentDto { Id = document.Id, Name = "Updated Document" };
var updatedDocument = new TestableDocumentDto { Id = document.Id, Name = "Updated Document" };
// Act
var result = await _dataProvider.TestUpdateWithPredicateAsync(updatedDocument, x => x.Id == document.Id, null);
// Act
var result = await _dataProvider.TestUpdateWithPredicateAsync(updatedDocument, x => x.Id == document.Id, null);
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(updatedDocument.Id, result.Value);
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(updatedDocument.Id, result.Value);
var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == updatedDocument.Id);
Assert.NotNull(inMemoryCollection);
Assert.Equal("Updated Document", inMemoryCollection.Name);
}
var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == updatedDocument.Id);
Assert.NotNull(inMemoryCollection);
Assert.Equal("Updated Document", inMemoryCollection.Name);
}
[Fact]
public async Task TestUpdateManyWithPredicateAsync_ShouldUpdateDocuments_WhenMatchingDocumentsExist() {
// Arrange
var documents = new List<TestableDocumentDto>
{
[Fact]
public async Task TestUpdateManyWithPredicateAsync_ShouldUpdateDocuments_WhenMatchingDocumentsExist() {
// Arrange
var documents = new List<TestableDocumentDto>
{
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" },
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" }
};
await _dataProvider.TestInsertManyAsync(documents, null);
await _dataProvider.TestInsertManyAsync(documents, null);
var updatedDocuments = new List<TestableDocumentDto>
{
var updatedDocuments = new List<TestableDocumentDto>
{
new TestableDocumentDto { Id = documents[0].Id, Name = "Updated Document 1" },
new TestableDocumentDto { Id = documents[1].Id, Name = "Updated Document 2" }
};
// Act
var result = await _dataProvider.TestUpdateManyWithPredicateAsync(updatedDocuments, x => updatedDocuments.Select(d => d.Id).Contains(x.Id), null);
// Act
var result = await _dataProvider.TestUpdateManyWithPredicateAsync(updatedDocuments, x => updatedDocuments.Select(d => d.Id).Contains(x.Id), null);
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(2, result.Value?.Count);
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(2, result.Value?.Count);
var inMemoryCollection = _dataProvider.GetInMemoryCollection().ToList();
Assert.Equal("Updated Document 1", inMemoryCollection[0].Name);
Assert.Equal("Updated Document 2", inMemoryCollection[1].Name);
}
[Fact]
public async Task TestDeleteWithPredicateAsync_ShouldDeleteDocument_WhenMatchingDocumentExists() {
// Arrange
var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Test Document" };
await _dataProvider.TestInsertAsync(document, null);
// Act
var result = await _dataProvider.TestDeleteWithPredicateAsync(x => x.Id == document.Id, null);
// Assert
Assert.True(result.IsSuccess);
var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == document.Id);
Assert.Null(inMemoryCollection);
}
[Fact]
public async Task TestDeleteManyWithPredicateAsync_ShouldDeleteDocuments_WhenMatchingDocumentsExist() {
// Arrange
var documents = new List<TestableDocumentDto>
{
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" },
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" }
};
await _dataProvider.TestInsertManyAsync(documents, null);
// Act
var result = await _dataProvider.TestDeleteManyWithPredicateAsync(x => documents.Select(d => d.Id).Contains(x.Id), null);
// Assert
Assert.True(result.IsSuccess);
var inMemoryCollection = _dataProvider.GetInMemoryCollection().ToList();
Assert.Empty(inMemoryCollection);
}
[Fact]
public async Task TestGetQuery_ShouldReturnCorrectDocuments() {
// Arrange
var documents = new List<TestableDocumentDto>
{
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" },
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" }
};
// Use 'await' to asynchronously wait for the operation
await _dataProvider.TestInsertManyAsync(documents, null);
// Act
var queryResult = _dataProvider.GetInMemoryCollection().ToList();
// Assert
Assert.Equal(2, queryResult.Count);
Assert.Contains(queryResult, doc => doc.Name == "Document 1");
Assert.Contains(queryResult, doc => doc.Name == "Document 2");
}
var inMemoryCollection = _dataProvider.GetInMemoryCollection().ToList();
Assert.Equal("Updated Document 1", inMemoryCollection[0].Name);
Assert.Equal("Updated Document 2", inMemoryCollection[1].Name);
}
[Fact]
public async Task TestDeleteWithPredicateAsync_ShouldDeleteDocument_WhenMatchingDocumentExists() {
// Arrange
var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Test Document" };
await _dataProvider.TestInsertAsync(document, null);
// Act
var result = await _dataProvider.TestDeleteWithPredicateAsync(x => x.Id == document.Id, null);
// Assert
Assert.True(result.IsSuccess);
var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == document.Id);
Assert.Null(inMemoryCollection);
}
}
[Fact]
public async Task TestDeleteManyWithPredicateAsync_ShouldDeleteDocuments_WhenMatchingDocumentsExist() {
// Arrange
var documents = new List<TestableDocumentDto>
{
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" },
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" }
};
await _dataProvider.TestInsertManyAsync(documents, null);
// Act
var result = await _dataProvider.TestDeleteManyWithPredicateAsync(x => documents.Select(d => d.Id).Contains(x.Id), null);
// Assert
Assert.True(result.IsSuccess);
var inMemoryCollection = _dataProvider.GetInMemoryCollection().ToList();
Assert.Empty(inMemoryCollection);
}
[Fact]
public async Task TestGetQuery_ShouldReturnCorrectDocuments() {
// Arrange
var documents = new List<TestableDocumentDto>
{
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" },
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" }
};
// Use 'await' to asynchronously wait for the operation
await _dataProvider.TestInsertManyAsync(documents, null);
// Act
var queryResult = _dataProvider.GetInMemoryCollection().ToList();
// Assert
Assert.Equal(2, queryResult.Count);
Assert.Contains(queryResult, doc => doc.Name == "Document 1");
Assert.Contains(queryResult, doc => doc.Name == "Document 2");
}
}

View File

@ -1,20 +1,20 @@
using MongoDB.Driver;
namespace MaksIT.MongoDB.Linq.Tests.Mock {
internal class MongoAsyncCursorMock<T>(List<T> documents) : IAsyncCursor<T> {
public IEnumerable<T> Current => documents;
namespace MaksIT.MongoDB.Linq.Tests.Mock;
internal class MongoAsyncCursorMock<T>(List<T> documents) : IAsyncCursor<T> {
public bool MoveNext(CancellationToken cancellationToken = default) {
return false; // Only one batch of data
}
public IEnumerable<T> Current => documents;
public Task<bool> MoveNextAsync(CancellationToken cancellationToken = default) {
return Task.FromResult(false);
}
public bool MoveNext(CancellationToken cancellationToken = default) {
return false; // Only one batch of data
}
public void Dispose() {
public Task<bool> MoveNextAsync(CancellationToken cancellationToken = default) {
return Task.FromResult(false);
}
public void Dispose() {
}
}
}

View File

@ -2,162 +2,161 @@
using MongoDB.Driver;
using MongoDB.Driver.Core.Clusters;
namespace MaksIT.MongoDB.Linq.Tests.Mock {
internal class MongoClientMock : IMongoClient {
namespace MaksIT.MongoDB.Linq.Tests.Mock;
internal class MongoClientMock : IMongoClient {
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
public IMongoDatabase GetDatabase(string name, MongoDatabaseSettings settings = null) {
return new MongoDatabaseMock();
}
public IMongoDatabase GetDatabase(string name, MongoDatabaseSettings settings = null) {
return new MongoDatabaseMock();
}
public IClientSessionHandle StartSession(ClientSessionOptions options = null, CancellationToken cancellationToken = default) {
return new MongoSessionMock();
}
public IClientSessionHandle StartSession(ClientSessionOptions options = null, CancellationToken cancellationToken = default) {
return new MongoSessionMock();
}
public Task<IClientSessionHandle> StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default) {
return Task.FromResult((IClientSessionHandle)new MongoSessionMock());
}
public Task<IClientSessionHandle> StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default) {
return Task.FromResult((IClientSessionHandle)new MongoSessionMock());
}
#region not implemented
#region not implemented
public ICluster Cluster => throw new NotImplementedException();
public ICluster Cluster => throw new NotImplementedException();
public MongoClientSettings Settings => throw new NotImplementedException();
public MongoClientSettings Settings => throw new NotImplementedException();
public void DropDatabase(string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void DropDatabase(string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void DropDatabase(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void DropDatabase(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task DropDatabaseAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task DropDatabaseAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<string> ListDatabaseNames(CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<string> ListDatabaseNames(CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<string> ListDatabaseNames(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<string> ListDatabaseNames(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<string> ListDatabaseNames(IClientSessionHandle session, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<string> ListDatabaseNames(IClientSessionHandle session, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<string> ListDatabaseNames(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<string> ListDatabaseNames(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<BsonDocument> ListDatabases(CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<BsonDocument> ListDatabases(CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<BsonDocument> ListDatabases(ListDatabasesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<BsonDocument> ListDatabases(ListDatabasesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<BsonDocument> ListDatabases(IClientSessionHandle session, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<BsonDocument> ListDatabases(IClientSessionHandle session, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<BsonDocument> ListDatabases(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<BsonDocument> ListDatabases(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(ListDatabasesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(ListDatabasesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IMongoClient WithReadConcern(ReadConcern readConcern) {
throw new NotImplementedException();
}
public IMongoClient WithReadConcern(ReadConcern readConcern) {
throw new NotImplementedException();
}
public IMongoClient WithReadPreference(ReadPreference readPreference) {
throw new NotImplementedException();
}
public IMongoClient WithReadPreference(ReadPreference readPreference) {
throw new NotImplementedException();
}
public IMongoClient WithWriteConcern(WriteConcern writeConcern) {
throw new NotImplementedException();
}
public IMongoClient WithWriteConcern(WriteConcern writeConcern) {
throw new NotImplementedException();
}
public ClientBulkWriteResult BulkWrite(IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public ClientBulkWriteResult BulkWrite(IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public ClientBulkWriteResult BulkWrite(IClientSessionHandle session, IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public ClientBulkWriteResult BulkWrite(IClientSessionHandle session, IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<ClientBulkWriteResult> BulkWriteAsync(IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<ClientBulkWriteResult> BulkWriteAsync(IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<ClientBulkWriteResult> BulkWriteAsync(IClientSessionHandle session, IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<ClientBulkWriteResult> BulkWriteAsync(IClientSessionHandle session, IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void Dispose() {
throw new NotImplementedException();
}
public void Dispose() {
throw new NotImplementedException();
}
#endregion
#endregion
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
}

View File

@ -2,408 +2,409 @@
using MongoDB.Driver;
using MongoDB.Driver.Search;
namespace MaksIT.MongoDB.Linq.Tests.Mock {
internal class MongoCollectionMock<TDocument> : IMongoCollection<TDocument> {
namespace MaksIT.MongoDB.Linq.Tests.Mock;
internal class MongoCollectionMock<TDocument> : IMongoCollection<TDocument> {
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
#pragma warning disable CS0618 // Type or member is obsolete
#region not implemented
public CollectionNamespace CollectionNamespace => throw new NotImplementedException();
#region not implemented
public CollectionNamespace CollectionNamespace => throw new NotImplementedException();
public IMongoDatabase Database => throw new NotImplementedException();
public IMongoDatabase Database => throw new NotImplementedException();
public global::MongoDB.Bson.Serialization.IBsonSerializer<TDocument> DocumentSerializer => throw new NotImplementedException();
public global::MongoDB.Bson.Serialization.IBsonSerializer<TDocument> DocumentSerializer => throw new NotImplementedException();
public IMongoIndexManager<TDocument> Indexes => throw new NotImplementedException();
public IMongoIndexManager<TDocument> Indexes => throw new NotImplementedException();
public IMongoSearchIndexManager SearchIndexes => throw new NotImplementedException();
public IMongoSearchIndexManager SearchIndexes => throw new NotImplementedException();
public MongoCollectionSettings Settings => throw new NotImplementedException();
public MongoCollectionSettings Settings => throw new NotImplementedException();
public IAsyncCursor<TResult> Aggregate<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TResult> Aggregate<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TResult> Aggregate<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TResult> Aggregate<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void AggregateToCollection<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void AggregateToCollection<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void AggregateToCollection<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void AggregateToCollection<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task AggregateToCollectionAsync<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task AggregateToCollectionAsync<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task AggregateToCollectionAsync<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task AggregateToCollectionAsync<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public BulkWriteResult<TDocument> BulkWrite(IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public BulkWriteResult<TDocument> BulkWrite(IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public BulkWriteResult<TDocument> BulkWrite(IClientSessionHandle session, IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public BulkWriteResult<TDocument> BulkWrite(IClientSessionHandle session, IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<BulkWriteResult<TDocument>> BulkWriteAsync(IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<BulkWriteResult<TDocument>> BulkWriteAsync(IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<BulkWriteResult<TDocument>> BulkWriteAsync(IClientSessionHandle session, IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<BulkWriteResult<TDocument>> BulkWriteAsync(IClientSessionHandle session, IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public long Count(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public long Count(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public long Count(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public long Count(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<long> CountAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<long> CountAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<long> CountAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<long> CountAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public long CountDocuments(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public long CountDocuments(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public long CountDocuments(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public long CountDocuments(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<long> CountDocumentsAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<long> CountDocumentsAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<long> CountDocumentsAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<long> CountDocumentsAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public DeleteResult DeleteMany(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public DeleteResult DeleteMany(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public DeleteResult DeleteMany(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public DeleteResult DeleteMany(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public DeleteResult DeleteMany(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public DeleteResult DeleteMany(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<DeleteResult> DeleteManyAsync(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<DeleteResult> DeleteManyAsync(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<DeleteResult> DeleteManyAsync(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<DeleteResult> DeleteManyAsync(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<DeleteResult> DeleteManyAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<DeleteResult> DeleteManyAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public DeleteResult DeleteOne(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public DeleteResult DeleteOne(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public DeleteResult DeleteOne(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public DeleteResult DeleteOne(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public DeleteResult DeleteOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public DeleteResult DeleteOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<DeleteResult> DeleteOneAsync(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<DeleteResult> DeleteOneAsync(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<DeleteResult> DeleteOneAsync(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<DeleteResult> DeleteOneAsync(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<DeleteResult> DeleteOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<DeleteResult> DeleteOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TField> Distinct<TField>(FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TField> Distinct<TField>(FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TField> Distinct<TField>(IClientSessionHandle session, FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TField> Distinct<TField>(IClientSessionHandle session, FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TField>> DistinctAsync<TField>(FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TField>> DistinctAsync<TField>(FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TField>> DistinctAsync<TField>(IClientSessionHandle session, FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TField>> DistinctAsync<TField>(IClientSessionHandle session, FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TItem> DistinctMany<TItem>(FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TItem> DistinctMany<TItem>(FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TItem> DistinctMany<TItem>(IClientSessionHandle session, FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TItem> DistinctMany<TItem>(IClientSessionHandle session, FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TItem>> DistinctManyAsync<TItem>(FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TItem>> DistinctManyAsync<TItem>(FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TItem>> DistinctManyAsync<TItem>(IClientSessionHandle session, FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TItem>> DistinctManyAsync<TItem>(IClientSessionHandle session, FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public long EstimatedDocumentCount(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public long EstimatedDocumentCount(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<long> EstimatedDocumentCountAsync(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<long> EstimatedDocumentCountAsync(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TProjection>> FindAsync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TProjection>> FindAsync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TProjection>> FindAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TProjection>> FindAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TProjection FindOneAndDelete<TProjection>(FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TProjection FindOneAndDelete<TProjection>(FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TProjection FindOneAndDelete<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TProjection FindOneAndDelete<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TProjection> FindOneAndDeleteAsync<TProjection>(FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TProjection> FindOneAndDeleteAsync<TProjection>(FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TProjection> FindOneAndDeleteAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TProjection> FindOneAndDeleteAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TProjection FindOneAndReplace<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TProjection FindOneAndReplace<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TProjection FindOneAndReplace<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TProjection FindOneAndReplace<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TProjection> FindOneAndReplaceAsync<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TProjection> FindOneAndReplaceAsync<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TProjection> FindOneAndReplaceAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TProjection> FindOneAndReplaceAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TProjection FindOneAndUpdate<TProjection>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TProjection FindOneAndUpdate<TProjection>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TProjection FindOneAndUpdate<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TProjection FindOneAndUpdate<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TProjection> FindOneAndUpdateAsync<TProjection>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TProjection> FindOneAndUpdateAsync<TProjection>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TProjection> FindOneAndUpdateAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TProjection> FindOneAndUpdateAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TProjection> FindSync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TProjection> FindSync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TProjection> FindSync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TProjection> FindSync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void InsertMany(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void InsertMany(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void InsertMany(IClientSessionHandle session, IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void InsertMany(IClientSessionHandle session, IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task InsertManyAsync(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task InsertManyAsync(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task InsertManyAsync(IClientSessionHandle session, IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task InsertManyAsync(IClientSessionHandle session, IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void InsertOne(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void InsertOne(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void InsertOne(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void InsertOne(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task InsertOneAsync(TDocument document, CancellationToken _cancellationToken) {
throw new NotImplementedException();
}
public Task InsertOneAsync(TDocument document, CancellationToken _cancellationToken) {
throw new NotImplementedException();
}
public Task InsertOneAsync(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task InsertOneAsync(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task InsertOneAsync(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task InsertOneAsync(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TResult> MapReduce<TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TResult> MapReduce<TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TResult> MapReduce<TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TResult> MapReduce<TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TResult>> MapReduceAsync<TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TResult>> MapReduceAsync<TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TResult>> MapReduceAsync<TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TResult>> MapReduceAsync<TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IFilteredMongoCollection<TDerivedDocument> OfType<TDerivedDocument>() where TDerivedDocument : TDocument {
throw new NotImplementedException();
}
public IFilteredMongoCollection<TDerivedDocument> OfType<TDerivedDocument>() where TDerivedDocument : TDocument {
throw new NotImplementedException();
}
public ReplaceOneResult ReplaceOne(FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public ReplaceOneResult ReplaceOne(FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public ReplaceOneResult ReplaceOne(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public ReplaceOneResult ReplaceOne(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<ReplaceOneResult> ReplaceOneAsync(FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<ReplaceOneResult> ReplaceOneAsync(FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<ReplaceOneResult> ReplaceOneAsync(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<ReplaceOneResult> ReplaceOneAsync(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public UpdateResult UpdateMany(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public UpdateResult UpdateMany(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public UpdateResult UpdateMany(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public UpdateResult UpdateMany(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<UpdateResult> UpdateManyAsync(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<UpdateResult> UpdateManyAsync(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<UpdateResult> UpdateManyAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<UpdateResult> UpdateManyAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public UpdateResult UpdateOne(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public UpdateResult UpdateOne(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public UpdateResult UpdateOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public UpdateResult UpdateOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<UpdateResult> UpdateOneAsync(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<UpdateResult> UpdateOneAsync(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<UpdateResult> UpdateOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<UpdateResult> UpdateOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IMongoCollection<TDocument> WithReadConcern(ReadConcern readConcern) {
throw new NotImplementedException();
}
public IMongoCollection<TDocument> WithReadConcern(ReadConcern readConcern) {
throw new NotImplementedException();
}
public IMongoCollection<TDocument> WithReadPreference(ReadPreference readPreference) {
throw new NotImplementedException();
}
public IMongoCollection<TDocument> WithReadPreference(ReadPreference readPreference) {
throw new NotImplementedException();
}
public IMongoCollection<TDocument> WithWriteConcern(WriteConcern writeConcern) {
throw new NotImplementedException();
}
public IMongoCollection<TDocument> WithWriteConcern(WriteConcern writeConcern) {
throw new NotImplementedException();
}
#endregion
#endregion
#pragma warning restore CS0618 // Type or member is obsolete
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
}

View File

@ -1,221 +1,222 @@
using MongoDB.Bson;
using MongoDB.Driver;
namespace MaksIT.MongoDB.Linq.Tests.Mock {
internal class MongoDatabaseMock : IMongoDatabase {
namespace MaksIT.MongoDB.Linq.Tests.Mock;
internal class MongoDatabaseMock : IMongoDatabase {
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
public IAsyncCursor<string> ListCollectionNames(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) {
return new MongoAsyncCursorMock<string>(new List<string>() { "TestCollection" });
}
public IAsyncCursor<string> ListCollectionNames(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) {
return new MongoAsyncCursorMock<string>(new List<string>() { "TestCollection" });
}
public void CreateCollection(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) {
return;
}
public void CreateCollection(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) {
return;
}
public IMongoCollection<TDocument> GetCollection<TDocument>(string name, MongoCollectionSettings settings = null) {
return new MongoCollectionMock<TDocument>();
}
public IMongoCollection<TDocument> GetCollection<TDocument>(string name, MongoCollectionSettings settings = null) {
return new MongoCollectionMock<TDocument>();
}
#region not implemented
#region not implemented
public IMongoCollection<BsonDocument> this[string name] => throw new NotImplementedException();
public IMongoCollection<BsonDocument> this[string name] => throw new NotImplementedException();
public IMongoClient Client => throw new NotImplementedException();
public IMongoClient Client => throw new NotImplementedException();
public DatabaseNamespace DatabaseNamespace => throw new NotImplementedException();
public DatabaseNamespace DatabaseNamespace => throw new NotImplementedException();
public MongoDatabaseSettings Settings => throw new NotImplementedException();
public MongoDatabaseSettings Settings => throw new NotImplementedException();
public IAsyncCursor<TResult> Aggregate<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TResult> Aggregate<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TResult> Aggregate<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<TResult> Aggregate<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void AggregateToCollection<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void AggregateToCollection<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void AggregateToCollection<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void AggregateToCollection<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task AggregateToCollectionAsync<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task AggregateToCollectionAsync<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task AggregateToCollectionAsync<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task AggregateToCollectionAsync<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void CreateCollection(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void CreateCollection(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task CreateCollectionAsync(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task CreateCollectionAsync(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task CreateCollectionAsync(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task CreateCollectionAsync(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void CreateView<TDocument, TResult>(string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void CreateView<TDocument, TResult>(string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void CreateView<TDocument, TResult>(IClientSessionHandle session, string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void CreateView<TDocument, TResult>(IClientSessionHandle session, string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task CreateViewAsync<TDocument, TResult>(string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task CreateViewAsync<TDocument, TResult>(string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task CreateViewAsync<TDocument, TResult>(IClientSessionHandle session, string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task CreateViewAsync<TDocument, TResult>(IClientSessionHandle session, string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void DropCollection(string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void DropCollection(string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void DropCollection(string name, DropCollectionOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void DropCollection(string name, DropCollectionOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void DropCollection(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void DropCollection(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void DropCollection(IClientSessionHandle session, string name, DropCollectionOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void DropCollection(IClientSessionHandle session, string name, DropCollectionOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task DropCollectionAsync(string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task DropCollectionAsync(string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task DropCollectionAsync(string name, DropCollectionOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task DropCollectionAsync(string name, DropCollectionOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task DropCollectionAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task DropCollectionAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task DropCollectionAsync(IClientSessionHandle session, string name, DropCollectionOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task DropCollectionAsync(IClientSessionHandle session, string name, DropCollectionOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<string> ListCollectionNames(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<string> ListCollectionNames(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<string>> ListCollectionNamesAsync(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<string>> ListCollectionNamesAsync(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<string>> ListCollectionNamesAsync(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<string>> ListCollectionNamesAsync(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<BsonDocument> ListCollections(ListCollectionsOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<BsonDocument> ListCollections(ListCollectionsOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<BsonDocument> ListCollections(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IAsyncCursor<BsonDocument> ListCollections(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<BsonDocument>> ListCollectionsAsync(ListCollectionsOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<BsonDocument>> ListCollectionsAsync(ListCollectionsOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<BsonDocument>> ListCollectionsAsync(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IAsyncCursor<BsonDocument>> ListCollectionsAsync(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void RenameCollection(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void RenameCollection(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void RenameCollection(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public void RenameCollection(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task RenameCollectionAsync(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task RenameCollectionAsync(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task RenameCollectionAsync(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task RenameCollectionAsync(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TResult RunCommand<TResult>(Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TResult RunCommand<TResult>(Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TResult RunCommand<TResult>(IClientSessionHandle session, Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TResult RunCommand<TResult>(IClientSessionHandle session, Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TResult> RunCommandAsync<TResult>(Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TResult> RunCommandAsync<TResult>(Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TResult> RunCommandAsync<TResult>(IClientSessionHandle session, Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TResult> RunCommandAsync<TResult>(IClientSessionHandle session, Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public IMongoDatabase WithReadConcern(ReadConcern readConcern) {
throw new NotImplementedException();
}
public IMongoDatabase WithReadConcern(ReadConcern readConcern) {
throw new NotImplementedException();
}
public IMongoDatabase WithReadPreference(ReadPreference readPreference) {
throw new NotImplementedException();
}
public IMongoDatabase WithReadPreference(ReadPreference readPreference) {
throw new NotImplementedException();
}
public IMongoDatabase WithWriteConcern(WriteConcern writeConcern) {
throw new NotImplementedException();
}
public IMongoDatabase WithWriteConcern(WriteConcern writeConcern) {
throw new NotImplementedException();
}
#endregion
#endregion
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
}

View File

@ -3,91 +3,92 @@ using MongoDB.Driver;
using MongoDB.Driver.Core.Bindings;
using MongoDB.Driver.Core.Clusters;
namespace MaksIT.MongoDB.Linq.Tests {
internal class MongoSessionMock : IClientSessionHandle {
namespace MaksIT.MongoDB.Linq.Tests;
internal class MongoSessionMock : IClientSessionHandle {
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
public bool IsInTransaction { get; private set; } = false;
public bool IsInTransaction { get; private set; } = false;
public void StartTransaction(TransactionOptions transactionOptions = null) {
IsInTransaction = true;
}
public void StartTransaction(TransactionOptions transactionOptions = null) {
IsInTransaction = true;
}
public Task StartTransactionAsync(TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) {
IsInTransaction = true;
return Task.CompletedTask;
}
public Task StartTransactionAsync(TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) {
IsInTransaction = true;
return Task.CompletedTask;
}
public void AbortTransaction(CancellationToken cancellationToken = default) {
IsInTransaction = false;
}
public void AbortTransaction(CancellationToken cancellationToken = default) {
IsInTransaction = false;
}
public Task AbortTransactionAsync(CancellationToken cancellationToken = default) {
IsInTransaction = false;
return Task.CompletedTask;
}
public Task AbortTransactionAsync(CancellationToken cancellationToken = default) {
IsInTransaction = false;
return Task.CompletedTask;
}
public void CommitTransaction(CancellationToken cancellationToken = default) {
IsInTransaction = false;
}
public void CommitTransaction(CancellationToken cancellationToken = default) {
IsInTransaction = false;
}
public Task CommitTransactionAsync(CancellationToken cancellationToken = default) {
IsInTransaction = false;
return Task.CompletedTask;
}
public Task CommitTransactionAsync(CancellationToken cancellationToken = default) {
IsInTransaction = false;
return Task.CompletedTask;
}
#region not implemented
#region not implemented
public ClientSessionOptions Options => new ClientSessionOptions();
public ClientSessionOptions Options => new ClientSessionOptions();
public IMongoClient Client => throw new NotImplementedException();
public IMongoClient Client => throw new NotImplementedException();
public ICluster Cluster => throw new NotImplementedException();
public ICluster Cluster => throw new NotImplementedException();
public CoreSessionHandle WrappedCoreSession => throw new NotImplementedException();
public CoreSessionHandle WrappedCoreSession => throw new NotImplementedException();
public BsonDocument ClusterTime => throw new NotImplementedException();
public BsonDocument ClusterTime => throw new NotImplementedException();
public BsonDocument OperationTime => throw new NotImplementedException();
public BsonDocument OperationTime => throw new NotImplementedException();
public bool IsImplicit => throw new NotImplementedException();
public bool IsImplicit => throw new NotImplementedException();
BsonTimestamp IClientSession.OperationTime => throw new NotImplementedException();
BsonTimestamp IClientSession.OperationTime => throw new NotImplementedException();
public IServerSession ServerSession => throw new NotImplementedException();
public IServerSession ServerSession => throw new NotImplementedException();
ICoreSessionHandle IClientSession.WrappedCoreSession => throw new NotImplementedException();
ICoreSessionHandle IClientSession.WrappedCoreSession => throw new NotImplementedException();
public void Dispose() {
// Simulate disposing of the session
}
public void Dispose() {
// Simulate disposing of the session
}
public IClientSessionHandle Fork() {
throw new NotImplementedException();
}
public IClientSessionHandle Fork() {
throw new NotImplementedException();
}
public void AdvanceClusterTime(BsonDocument newClusterTime) {
throw new NotImplementedException();
}
public void AdvanceClusterTime(BsonDocument newClusterTime) {
throw new NotImplementedException();
}
public void AdvanceOperationTime(BsonTimestamp newOperationTime) {
throw new NotImplementedException();
}
public void AdvanceOperationTime(BsonTimestamp newOperationTime) {
throw new NotImplementedException();
}
public TResult WithTransaction<TResult>(Func<IClientSessionHandle, CancellationToken, TResult> callback, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public TResult WithTransaction<TResult>(Func<IClientSessionHandle, CancellationToken, TResult> callback, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TResult> WithTransactionAsync<TResult>(Func<IClientSessionHandle, CancellationToken, Task<TResult>> callbackAsync, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
public Task<TResult> WithTransactionAsync<TResult>(Func<IClientSessionHandle, CancellationToken, Task<TResult>> callbackAsync, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException();
}
#endregion
#endregion
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
}
}

View File

@ -3,64 +3,65 @@
using MaksIT.Results;
using MaksIT.MongoDB.Linq.Tests.Mock;
namespace MaksIT.MongoDB.Linq.Tests {
public class MongoSessionManagerTests {
private readonly MongoSessionManager _sessionManager;
private readonly ILogger<MongoSessionManager> _logger;
namespace MaksIT.MongoDB.Linq.Tests;
public MongoSessionManagerTests() {
_logger = new LoggerFactory().CreateLogger<MongoSessionManager>();
var mockClient = new MongoClientMock();
_sessionManager = new MongoSessionManager(_logger, mockClient);
}
public class MongoSessionManagerTests {
[Fact]
public void ExecuteInSession_ShouldCommitTransaction_WhenActionSucceeds() {
// Act
var result = _sessionManager.ExecuteInSession(session => {
// Simulate successful operation
return Result.Ok();
});
private readonly MongoSessionManager _sessionManager;
private readonly ILogger<MongoSessionManager> _logger;
// Assert
Assert.True(result.IsSuccess);
}
public MongoSessionManagerTests() {
_logger = new LoggerFactory().CreateLogger<MongoSessionManager>();
var mockClient = new MongoClientMock();
_sessionManager = new MongoSessionManager(_logger, mockClient);
}
[Fact]
public void ExecuteInSession_ShouldAbortTransaction_WhenActionFails() {
// Act
var result = _sessionManager.ExecuteInSession(session => {
// Simulate failed operation
return Result.InternalServerError("Simulated failure");
});
[Fact]
public void ExecuteInSession_ShouldCommitTransaction_WhenActionSucceeds() {
// Act
var result = _sessionManager.ExecuteInSession(session => {
// Simulate successful operation
return Result.Ok();
});
// Assert
Assert.False(result.IsSuccess);
}
// Assert
Assert.True(result.IsSuccess);
}
[Fact]
public async Task ExecuteInSessionAsync_ShouldCommitTransaction_WhenActionSucceeds() {
// Act
var result = await _sessionManager.ExecuteInSessionAsync(async session => {
// Simulate successful operation
return await Task.FromResult(Result.Ok());
});
[Fact]
public void ExecuteInSession_ShouldAbortTransaction_WhenActionFails() {
// Act
var result = _sessionManager.ExecuteInSession(session => {
// Simulate failed operation
return Result.InternalServerError("Simulated failure");
});
// Assert
Assert.True(result.IsSuccess);
}
// Assert
Assert.False(result.IsSuccess);
}
[Fact]
public async Task ExecuteInSessionAsync_ShouldAbortTransaction_WhenActionFails() {
// Act
var result = await _sessionManager.ExecuteInSessionAsync(async session => {
// Simulate failed operation
return await Task.FromResult(Result.InternalServerError("Simulated failure"));
});
[Fact]
public async Task ExecuteInSessionAsync_ShouldCommitTransaction_WhenActionSucceeds() {
// Act
var result = await _sessionManager.ExecuteInSessionAsync(async session => {
// Simulate successful operation
return await Task.FromResult(Result.Ok());
});
// Assert
Assert.False(result.IsSuccess);
}
// Assert
Assert.True(result.IsSuccess);
}
[Fact]
public async Task ExecuteInSessionAsync_ShouldAbortTransaction_WhenActionFails() {
// Act
var result = await _sessionManager.ExecuteInSessionAsync(async session => {
// Simulate failed operation
return await Task.FromResult(Result.InternalServerError("Simulated failure"));
});
// Assert
Assert.False(result.IsSuccess);
}
}

View File

@ -1,81 +1,82 @@
using MaksIT.MongoDB.Linq.Utilities;
namespace MaksIT.MongoDB.Linq.Tests.Utilities {
public class CombGuidGeneratorTests {
[Fact]
public void CreateCombGuid_WithCurrentTimestamp_ShouldGenerateGuid() {
// Act
Guid combGuid = CombGuidGenerator.CreateCombGuid();
// Assert
Assert.NotEqual(Guid.Empty, combGuid);
}
namespace MaksIT.MongoDB.Linq.Tests.Utilities;
[Fact]
public void CreateCombGuid_WithSpecificGuidAndCurrentTimestamp_ShouldEmbedTimestamp() {
// Arrange
Guid inputGuid = Guid.NewGuid();
public class CombGuidGeneratorTests {
[Fact]
public void CreateCombGuid_WithCurrentTimestamp_ShouldGenerateGuid() {
// Act
Guid combGuid = CombGuidGenerator.CreateCombGuid();
// Act
Guid combGuid = CombGuidGenerator.CreateCombGuid(inputGuid);
DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid);
// Assert
Assert.NotEqual(Guid.Empty, combGuid);
}
// Assert
Assert.NotEqual(Guid.Empty, combGuid);
Assert.True(extractedTimestamp <= DateTime.UtcNow, "The extracted timestamp should not be in the future.");
Assert.True(extractedTimestamp >= DateTime.UtcNow.AddSeconds(-5), "The extracted timestamp should be recent.");
}
[Fact]
public void CreateCombGuid_WithSpecificGuidAndCurrentTimestamp_ShouldEmbedTimestamp() {
// Arrange
Guid inputGuid = Guid.NewGuid();
[Fact]
public void CreateCombGuid_WithSpecificTimestamp_ShouldGenerateGuidWithEmbeddedTimestamp() {
// Arrange
DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc);
// Act
Guid combGuid = CombGuidGenerator.CreateCombGuid(inputGuid);
DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid);
// Act
Guid combGuid = CombGuidGenerator.CreateCombGuid(timestamp);
DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid);
// Assert
Assert.NotEqual(Guid.Empty, combGuid);
Assert.True(extractedTimestamp <= DateTime.UtcNow, "The extracted timestamp should not be in the future.");
Assert.True(extractedTimestamp >= DateTime.UtcNow.AddSeconds(-5), "The extracted timestamp should be recent.");
}
// Assert
Assert.NotEqual(Guid.Empty, combGuid);
Assert.Equal(timestamp, extractedTimestamp);
}
[Fact]
public void CreateCombGuid_WithSpecificTimestamp_ShouldGenerateGuidWithEmbeddedTimestamp() {
// Arrange
DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc);
[Fact]
public void CreateCombGuid_WithGuidAndSpecificTimestamp_ShouldGenerateGuidWithEmbeddedTimestamp() {
// Arrange
Guid inputGuid = Guid.NewGuid();
DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc);
// Act
Guid combGuid = CombGuidGenerator.CreateCombGuid(timestamp);
DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid);
// Act
Guid combGuid = CombGuidGenerator.CreateCombGuidWithTimestamp(inputGuid, timestamp);
DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid);
// Assert
Assert.NotEqual(Guid.Empty, combGuid);
Assert.Equal(timestamp, extractedTimestamp);
}
// Assert
Assert.NotEqual(Guid.Empty, combGuid);
Assert.Equal(timestamp, extractedTimestamp);
}
[Fact]
public void CreateCombGuid_WithGuidAndSpecificTimestamp_ShouldGenerateGuidWithEmbeddedTimestamp() {
// Arrange
Guid inputGuid = Guid.NewGuid();
DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc);
[Fact]
public void ExtractTimestamp_ShouldExtractCorrectTimestampFromCombGuid() {
// Arrange
DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc);
Guid combGuid = CombGuidGenerator.CreateCombGuid(timestamp);
// Act
Guid combGuid = CombGuidGenerator.CreateCombGuidWithTimestamp(inputGuid, timestamp);
DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid);
// Act
DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid);
// Assert
Assert.NotEqual(Guid.Empty, combGuid);
Assert.Equal(timestamp, extractedTimestamp);
}
// Assert
Assert.Equal(timestamp, extractedTimestamp);
}
[Fact]
public void ExtractTimestamp_ShouldExtractCorrectTimestampFromCombGuid() {
// Arrange
DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc);
Guid combGuid = CombGuidGenerator.CreateCombGuid(timestamp);
[Fact]
public void ExtractTimestamp_WithInvalidGuid_ShouldThrowException() {
// Arrange
Guid invalidGuid = Guid.NewGuid();
// Act
DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid);
// Act & Assert
var exception = Record.Exception(() => CombGuidGenerator.ExtractTimestamp(invalidGuid));
Assert.Null(exception); // Adjusted expectation based on behavior of `ExtractTimestamp` with a regular GUID
}
// Assert
Assert.Equal(timestamp, extractedTimestamp);
}
[Fact]
public void ExtractTimestamp_WithInvalidGuid_ShouldThrowException() {
// Arrange
Guid invalidGuid = Guid.NewGuid();
// Act & Assert
var exception = Record.Exception(() => CombGuidGenerator.ExtractTimestamp(invalidGuid));
Assert.Null(exception); // Adjusted expectation based on behavior of `ExtractTimestamp` with a regular GUID
}
}

View File

@ -7,234 +7,235 @@ using MaksIT.Core.Abstractions.Dto;
using MaksIT.Results;
namespace MaksIT.MongoDB.Linq.Abstractions {
public abstract class BaseCollectionDataProviderBase<T, TDtoDocument, TDtoKey> : DataProviderBase<T>
where TDtoDocument : DtoDocumentBase<TDtoKey> {
namespace MaksIT.MongoDB.Linq.Abstractions;
protected readonly IMongoCollection<TDtoDocument> Collection;
protected readonly string _errorMessage = "MaksIT.MongoDB.Linq - Data provider error";
public abstract class BaseCollectionDataProviderBase<T, TDtoDocument, TDtoKey> : DataProviderBase<T>
where TDtoDocument : DtoDocumentBase<TDtoKey> {
protected BaseCollectionDataProviderBase(
ILogger<T> logger,
IMongoClient client,
string databaseName,
string collectionName
) : base(logger, client, databaseName) {
if (!Database.ListCollectionNames().ToList().Contains(collectionName))
Database.CreateCollection(collectionName);
protected readonly IMongoCollection<TDtoDocument> Collection;
protected readonly string _errorMessage = "MaksIT.MongoDB.Linq - Data provider error";
Collection = Database.GetCollection<TDtoDocument>(collectionName);
}
protected BaseCollectionDataProviderBase(
ILogger<T> logger,
IMongoClient client,
string databaseName,
string collectionName
) : base(logger, client, databaseName) {
if (!Database.ListCollectionNames().ToList().Contains(collectionName))
Database.CreateCollection(collectionName);
#region Insert
protected virtual async Task<Result<TDtoKey?>> InsertAsync(TDtoDocument document, IClientSessionHandle? session) {
try {
if (session != null)
await Collection.InsertOneAsync(session, document);
else
await Collection.InsertOneAsync(document);
return Result<TDtoKey?>.Ok(document.Id);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<TDtoKey?>.InternalServerError(default(TDtoKey?), _errorMessage);
}
}
#endregion
#region InsertMany
protected virtual async Task<Result<List<TDtoKey>?>> InsertManyAsync(List<TDtoDocument> documents, IClientSessionHandle? session) {
try {
// Check if the documents list is empty
if (documents.Count == 0) {
return Result<List<TDtoKey>?>.Ok(new List<TDtoKey>());
}
if (session != null)
await Collection.InsertManyAsync(session, documents);
else
await Collection.InsertManyAsync(documents);
return Result<List<TDtoKey>?>.Ok(documents.Select(x => x.Id).ToList());
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<List<TDtoKey>?>.InternalServerError(default, _errorMessage);
}
}
#endregion
#region Get
protected virtual IQueryable<TDtoDocument> GetQuery() => Collection.AsQueryable();
#endregion
#region Update
protected virtual async Task<Result<TDtoKey?>> UpdateWithPredicateAsync(
TDtoDocument document,
Expression<Func<TDtoDocument, bool>> predicate,
IClientSessionHandle? session) {
try {
if (session != null)
await Collection.ReplaceOneAsync(session, predicate, document);
else
await Collection.ReplaceOneAsync(predicate, document);
return Result<TDtoKey?>.Ok(document.Id);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<TDtoKey?>.InternalServerError(default(TDtoKey?), _errorMessage);
}
}
#endregion
#region UpdateMany
protected virtual async Task<Result<List<TDtoKey>?>> UpdateManyWithPredicateAsync(
List<TDtoDocument> documents,
Expression<Func<TDtoDocument, bool>> predicate,
IClientSessionHandle? session) {
try {
// Check if the documents list is empty
if (documents.Count == 0) {
return Result<List<TDtoKey>?>.Ok(new List<TDtoKey>());
}
// Step 1: Find the documents that already exist based on the predicate
List<TDtoDocument> existingDocuments;
if (session != null) {
existingDocuments = await Collection.Find(session, predicate).ToListAsync();
}
else {
existingDocuments = await Collection.Find(predicate).ToListAsync();
}
// Step 2: Get the existing document IDs
var existingIds = existingDocuments.Select(doc => doc.Id).ToHashSet();
// Step 3: Filter the documents to update only those that exist in the collection
var documentsToUpdate = documents.Where(doc => existingIds.Contains(doc.Id)).ToList();
// Step 4: Update each of the existing documents
foreach (var document in documentsToUpdate) {
// Handling nullable Id by checking both document.Id and x.Id for null
var documentPredicate = (Expression<Func<TDtoDocument, bool>>)(x =>
(x.Id == null && document.Id == null) ||
(x.Id != null && x.Id.Equals(document.Id)));
if (session != null) {
await Collection.ReplaceOneAsync(session, documentPredicate, document);
}
else {
await Collection.ReplaceOneAsync(documentPredicate, document);
}
}
var updatedIds = documentsToUpdate.Select(doc => doc.Id).ToList();
return Result<List<TDtoKey>?>.Ok(updatedIds);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<List<TDtoKey>?>.InternalServerError(default, _errorMessage);
}
}
#endregion
#region Upsert
protected virtual async Task<Result<TDtoKey?>> UpsertWithPredicateAsync(
TDtoDocument document,
Expression<Func<TDtoDocument, bool>> predicate,
IClientSessionHandle? session
) {
try {
if (session != null) {
await Collection.DeleteOneAsync(session, predicate);
await Collection.InsertOneAsync(session, document);
}
else {
await Collection.DeleteOneAsync(predicate);
await Collection.InsertOneAsync(document);
}
return Result<TDtoKey?>.Ok(document.Id);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<TDtoKey?>.InternalServerError(default(TDtoKey?), _errorMessage);
}
}
#endregion
#region UpsertMany
protected virtual async Task<Result<List<TDtoKey>?>> UpsertManyWithPredicateAsync(
List<TDtoDocument> documents,
Expression<Func<TDtoDocument, bool>> predicate,
IClientSessionHandle? session) {
try {
// Check if the documents list is empty
if (documents.Count == 0) {
return Result<List<TDtoKey>?>.Ok(new List<TDtoKey>());
}
// Deletion
if (session != null)
await Collection.DeleteManyAsync(session, predicate);
else
await Collection.DeleteManyAsync(predicate);
// Creation
if (session != null)
await Collection.InsertManyAsync(session, documents);
else
await Collection.InsertManyAsync(documents);
var upsertedIds = documents.Select(doc => doc.Id).ToList();
return Result<List<TDtoKey>?>.Ok(upsertedIds);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<List<TDtoKey>?>.InternalServerError(default, _errorMessage);
}
}
#endregion
#region Delete
protected virtual async Task<Result> DeleteWithPredicateAsync(
Expression<Func<TDtoDocument, bool>> predicate,
IClientSessionHandle? session) {
try {
if (session != null)
await Collection.DeleteOneAsync(session, predicate);
else
await Collection.DeleteOneAsync(predicate);
return Result.Ok();
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result.InternalServerError(_errorMessage);
}
}
#endregion
#region DeleteMany
protected virtual async Task<Result> DeleteManyWithPredicateAsync(
Expression<Func<TDtoDocument, bool>> predicate,
IClientSessionHandle? session) {
try {
if (session != null)
await Collection.DeleteManyAsync(session, predicate);
else
await Collection.DeleteManyAsync(predicate);
return Result.Ok();
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result.InternalServerError(_errorMessage);
}
}
#endregion
Collection = Database.GetCollection<TDtoDocument>(collectionName);
}
#region Insert
protected virtual async Task<Result<TDtoKey?>> InsertAsync(TDtoDocument document, IClientSessionHandle? session) {
try {
if (session != null)
await Collection.InsertOneAsync(session, document);
else
await Collection.InsertOneAsync(document);
return Result<TDtoKey?>.Ok(document.Id);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<TDtoKey?>.InternalServerError(default(TDtoKey?), _errorMessage);
}
}
#endregion
#region InsertMany
protected virtual async Task<Result<List<TDtoKey>?>> InsertManyAsync(List<TDtoDocument> documents, IClientSessionHandle? session) {
try {
// Check if the documents list is empty
if (documents.Count == 0) {
return Result<List<TDtoKey>?>.Ok(new List<TDtoKey>());
}
if (session != null)
await Collection.InsertManyAsync(session, documents);
else
await Collection.InsertManyAsync(documents);
return Result<List<TDtoKey>?>.Ok(documents.Select(x => x.Id).ToList());
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<List<TDtoKey>?>.InternalServerError(default, _errorMessage);
}
}
#endregion
#region Get
protected virtual IQueryable<TDtoDocument> GetQuery() => Collection.AsQueryable();
#endregion
#region Update
protected virtual async Task<Result<TDtoKey?>> UpdateWithPredicateAsync(
TDtoDocument document,
Expression<Func<TDtoDocument, bool>> predicate,
IClientSessionHandle? session) {
try {
if (session != null)
await Collection.ReplaceOneAsync(session, predicate, document);
else
await Collection.ReplaceOneAsync(predicate, document);
return Result<TDtoKey?>.Ok(document.Id);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<TDtoKey?>.InternalServerError(default(TDtoKey?), _errorMessage);
}
}
#endregion
#region UpdateMany
protected virtual async Task<Result<List<TDtoKey>?>> UpdateManyWithPredicateAsync(
List<TDtoDocument> documents,
Expression<Func<TDtoDocument, bool>> predicate,
IClientSessionHandle? session) {
try {
// Check if the documents list is empty
if (documents.Count == 0) {
return Result<List<TDtoKey>?>.Ok(new List<TDtoKey>());
}
// Step 1: Find the documents that already exist based on the predicate
List<TDtoDocument> existingDocuments;
if (session != null) {
existingDocuments = await Collection.Find(session, predicate).ToListAsync();
}
else {
existingDocuments = await Collection.Find(predicate).ToListAsync();
}
// Step 2: Get the existing document IDs
var existingIds = existingDocuments.Select(doc => doc.Id).ToHashSet();
// Step 3: Filter the documents to update only those that exist in the collection
var documentsToUpdate = documents.Where(doc => existingIds.Contains(doc.Id)).ToList();
// Step 4: Update each of the existing documents
foreach (var document in documentsToUpdate) {
// Handling nullable Id by checking both document.Id and x.Id for null
var documentPredicate = (Expression<Func<TDtoDocument, bool>>)(x =>
(x.Id == null && document.Id == null) ||
(x.Id != null && x.Id.Equals(document.Id)));
if (session != null) {
await Collection.ReplaceOneAsync(session, documentPredicate, document);
}
else {
await Collection.ReplaceOneAsync(documentPredicate, document);
}
}
var updatedIds = documentsToUpdate.Select(doc => doc.Id).ToList();
return Result<List<TDtoKey>?>.Ok(updatedIds);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<List<TDtoKey>?>.InternalServerError(default, _errorMessage);
}
}
#endregion
#region Upsert
protected virtual async Task<Result<TDtoKey?>> UpsertWithPredicateAsync(
TDtoDocument document,
Expression<Func<TDtoDocument, bool>> predicate,
IClientSessionHandle? session
) {
try {
if (session != null) {
await Collection.DeleteOneAsync(session, predicate);
await Collection.InsertOneAsync(session, document);
}
else {
await Collection.DeleteOneAsync(predicate);
await Collection.InsertOneAsync(document);
}
return Result<TDtoKey?>.Ok(document.Id);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<TDtoKey?>.InternalServerError(default(TDtoKey?), _errorMessage);
}
}
#endregion
#region UpsertMany
protected virtual async Task<Result<List<TDtoKey>?>> UpsertManyWithPredicateAsync(
List<TDtoDocument> documents,
Expression<Func<TDtoDocument, bool>> predicate,
IClientSessionHandle? session) {
try {
// Check if the documents list is empty
if (documents.Count == 0) {
return Result<List<TDtoKey>?>.Ok(new List<TDtoKey>());
}
// Deletion
if (session != null)
await Collection.DeleteManyAsync(session, predicate);
else
await Collection.DeleteManyAsync(predicate);
// Creation
if (session != null)
await Collection.InsertManyAsync(session, documents);
else
await Collection.InsertManyAsync(documents);
var upsertedIds = documents.Select(doc => doc.Id).ToList();
return Result<List<TDtoKey>?>.Ok(upsertedIds);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<List<TDtoKey>?>.InternalServerError(default, _errorMessage);
}
}
#endregion
#region Delete
protected virtual async Task<Result> DeleteWithPredicateAsync(
Expression<Func<TDtoDocument, bool>> predicate,
IClientSessionHandle? session) {
try {
if (session != null)
await Collection.DeleteOneAsync(session, predicate);
else
await Collection.DeleteOneAsync(predicate);
return Result.Ok();
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result.InternalServerError(_errorMessage);
}
}
#endregion
#region DeleteMany
protected virtual async Task<Result> DeleteManyWithPredicateAsync(
Expression<Func<TDtoDocument, bool>> predicate,
IClientSessionHandle? session) {
try {
if (session != null)
await Collection.DeleteManyAsync(session, predicate);
else
await Collection.DeleteManyAsync(predicate);
return Result.Ok();
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result.InternalServerError(_errorMessage);
}
}
#endregion
}

View File

@ -7,120 +7,120 @@ using MongoDB.Driver;
using MaksIT.Results;
using MaksIT.Core.Abstractions.Dto;
namespace MaksIT.MongoDB.Linq.Abstractions {
public abstract class CollectionDataProviderBase<T, TDtoDocument, TDtoKey> : BaseCollectionDataProviderBase<T, TDtoDocument, TDtoKey>
where TDtoDocument : DtoDocumentBase<TDtoKey> {
namespace MaksIT.MongoDB.Linq.Abstractions;
protected CollectionDataProviderBase(
ILogger<T> logger,
IMongoClient client,
string databaseName,
string collectionName
) : base(logger, client, databaseName, collectionName) { }
public abstract class CollectionDataProviderBase<T, TDtoDocument, TDtoKey> : BaseCollectionDataProviderBase<T, TDtoDocument, TDtoKey>
where TDtoDocument : DtoDocumentBase<TDtoKey> {
#region Insert
public Result<TDtoKey?> Insert(TDtoDocument obj, IClientSessionHandle? session) =>
InsertAsync(obj, session).Result;
#endregion
protected CollectionDataProviderBase(
ILogger<T> logger,
IMongoClient client,
string databaseName,
string collectionName
) : base(logger, client, databaseName, collectionName) { }
#region InsertMany
public Result<List<TDtoKey>?> InsertMany(List<TDtoDocument> objList, IClientSessionHandle? session) =>
InsertManyAsync(objList, session).Result;
#endregion
#region Insert
public Result<TDtoKey?> Insert(TDtoDocument obj, IClientSessionHandle? session) =>
InsertAsync(obj, session).Result;
#endregion
#region Count
protected Result<int?> CountWithPredicate(Expression<Func<TDtoDocument, bool>> predicate) =>
CountWithPredicate(new List<Expression<Func<TDtoDocument, bool>>> { predicate });
#region InsertMany
public Result<List<TDtoKey>?> InsertMany(List<TDtoDocument> objList, IClientSessionHandle? session) =>
InsertManyAsync(objList, session).Result;
#endregion
private protected Result<int?> CountWithPredicate(List<Expression<Func<TDtoDocument, bool>>> predicates) {
try {
var query = GetWithPredicate(predicates);
#region Count
protected Result<int?> CountWithPredicate(Expression<Func<TDtoDocument, bool>> predicate) =>
CountWithPredicate(new List<Expression<Func<TDtoDocument, bool>>> { predicate });
var result = query.Count();
private protected Result<int?> CountWithPredicate(List<Expression<Func<TDtoDocument, bool>>> predicates) {
try {
var query = GetWithPredicate(predicates);
return Result<int?>.Ok(result);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<int?>.InternalServerError(null, _errorMessage);
}
var result = query.Count();
return Result<int?>.Ok(result);
}
#endregion
#region Get
protected Result<List<TResult>?> GetWithPredicate<TResult>(Expression<Func<TDtoDocument, bool>> predicate, Expression<Func<TDtoDocument, TResult>> selector) =>
GetWithPredicate(new List<Expression<Func<TDtoDocument, bool>>> { predicate }, selector, null, null);
protected Result<List<TResult>?> GetWithPredicate<TResult>(Expression<Func<TDtoDocument, bool>> predicate, Expression<Func<TDtoDocument, TResult>> selector, int? skip, int? limit) =>
GetWithPredicate(new List<Expression<Func<TDtoDocument, bool>>> { predicate }, selector, skip, limit);
protected Result<List<TResult>?> GetWithPredicate<TResult>(
List<Expression<Func<TDtoDocument, bool>>> predicates,
Expression<Func<TDtoDocument, TResult>> selector,
int? skip,
int? limit
) {
try {
var query = GetWithPredicate(predicates).Select(selector);
if (skip != null)
query = query.Skip(skip.Value);
if (limit != null)
query = query.Take(limit.Value);
var result = query.ToList();
return result.Count > 0
? Result<List<TResult>?>.Ok(result)
: Result<List<TResult>?>.NotFound(null);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<List<TResult>?>.InternalServerError(null, _errorMessage);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<int?>.InternalServerError(null, _errorMessage);
}
protected IQueryable<TDtoDocument> GetWithPredicate(List<Expression<Func<TDtoDocument, bool>>> predicates) {
var query = GetQuery();
foreach (var predicate in predicates)
query = query.Where(predicate);
return query;
}
#endregion
#region Update
protected Result<TDtoKey?> UpdateWithPredicate(TDtoDocument obj, Expression<Func<TDtoDocument, bool>> predicate, IClientSessionHandle? session) =>
UpdateWithPredicateAsync(obj, predicate, session).Result;
#endregion
#region UpdateMany
public Result<List<TDtoKey>?> UpdateManyWithPredicate(Expression<Func<TDtoDocument, bool>> predicate, List<TDtoDocument> objList, IClientSessionHandle? session) =>
UpdateManyWithPredicateAsync(objList, predicate, session).Result;
#endregion
#region Upsert
protected Result<TDtoKey?> UpsertWithPredicate(TDtoDocument obj, Expression<Func<TDtoDocument, bool>> predicate, IClientSessionHandle? session) =>
UpsertWithPredicateAsync(obj, predicate, session).Result;
#endregion
#region UpsertMany
public Result<List<TDtoKey>?> UpsertManyWithPredicate(List<TDtoDocument> objList, Expression<Func<TDtoDocument, bool>> predicate, IClientSessionHandle? session) =>
UpsertManyWithPredicateAsync(objList, predicate, session).Result;
#endregion
#region Delete
protected Result DeleteWithPredicate(Expression<Func<TDtoDocument, bool>> predicate, IClientSessionHandle? session) =>
DeleteWithPredicateAsync(predicate, session).Result;
#endregion
#region DeleteMany
protected Result DeleteManyWithPredicate(Expression<Func<TDtoDocument, bool>> predicate, IClientSessionHandle? session) =>
DeleteManyWithPredicateAsync(predicate, session).Result;
#endregion
}
#endregion
#region Get
protected Result<List<TResult>?> GetWithPredicate<TResult>(Expression<Func<TDtoDocument, bool>> predicate, Expression<Func<TDtoDocument, TResult>> selector) =>
GetWithPredicate(new List<Expression<Func<TDtoDocument, bool>>> { predicate }, selector, null, null);
protected Result<List<TResult>?> GetWithPredicate<TResult>(Expression<Func<TDtoDocument, bool>> predicate, Expression<Func<TDtoDocument, TResult>> selector, int? skip, int? limit) =>
GetWithPredicate(new List<Expression<Func<TDtoDocument, bool>>> { predicate }, selector, skip, limit);
protected Result<List<TResult>?> GetWithPredicate<TResult>(
List<Expression<Func<TDtoDocument, bool>>> predicates,
Expression<Func<TDtoDocument, TResult>> selector,
int? skip,
int? limit
) {
try {
var query = GetWithPredicate(predicates).Select(selector);
if (skip != null)
query = query.Skip(skip.Value);
if (limit != null)
query = query.Take(limit.Value);
var result = query.ToList();
return result.Count > 0
? Result<List<TResult>?>.Ok(result)
: Result<List<TResult>?>.NotFound(null);
}
catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
return Result<List<TResult>?>.InternalServerError(null, _errorMessage);
}
}
protected IQueryable<TDtoDocument> GetWithPredicate(List<Expression<Func<TDtoDocument, bool>>> predicates) {
var query = GetQuery();
foreach (var predicate in predicates)
query = query.Where(predicate);
return query;
}
#endregion
#region Update
protected Result<TDtoKey?> UpdateWithPredicate(TDtoDocument obj, Expression<Func<TDtoDocument, bool>> predicate, IClientSessionHandle? session) =>
UpdateWithPredicateAsync(obj, predicate, session).Result;
#endregion
#region UpdateMany
public Result<List<TDtoKey>?> UpdateManyWithPredicate(Expression<Func<TDtoDocument, bool>> predicate, List<TDtoDocument> objList, IClientSessionHandle? session) =>
UpdateManyWithPredicateAsync(objList, predicate, session).Result;
#endregion
#region Upsert
protected Result<TDtoKey?> UpsertWithPredicate(TDtoDocument obj, Expression<Func<TDtoDocument, bool>> predicate, IClientSessionHandle? session) =>
UpsertWithPredicateAsync(obj, predicate, session).Result;
#endregion
#region UpsertMany
public Result<List<TDtoKey>?> UpsertManyWithPredicate(List<TDtoDocument> objList, Expression<Func<TDtoDocument, bool>> predicate, IClientSessionHandle? session) =>
UpsertManyWithPredicateAsync(objList, predicate, session).Result;
#endregion
#region Delete
protected Result DeleteWithPredicate(Expression<Func<TDtoDocument, bool>> predicate, IClientSessionHandle? session) =>
DeleteWithPredicateAsync(predicate, session).Result;
#endregion
#region DeleteMany
protected Result DeleteManyWithPredicate(Expression<Func<TDtoDocument, bool>> predicate, IClientSessionHandle? session) =>
DeleteManyWithPredicateAsync(predicate, session).Result;
#endregion
}

View File

@ -1,19 +1,20 @@
using Microsoft.Extensions.Logging;
using MongoDB.Driver;
namespace MaksIT.MongoDB.Linq.Abstractions {
public abstract class DataProviderBase<T> {
protected readonly ILogger<T> Logger;
protected readonly IMongoDatabase Database;
private readonly IMongoClient _client;
protected DataProviderBase(
ILogger<T> logger,
IMongoClient client,
string databaseName) {
Logger = logger;
_client = client;
Database = _client.GetDatabase(databaseName);
}
namespace MaksIT.MongoDB.Linq.Abstractions;
public abstract class DataProviderBase<T> {
protected readonly ILogger<T> Logger;
protected readonly IMongoDatabase Database;
private readonly IMongoClient _client;
protected DataProviderBase(
ILogger<T> logger,
IMongoClient client,
string databaseName) {
Logger = logger;
_client = client;
Database = _client.GetDatabase(databaseName);
}
}

View File

@ -4,11 +4,11 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>MaksIT.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<RootNamespace>$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<!-- NuGet package metadata -->
<PackageId>MaksIT.MongoDB.Linq</PackageId>
<Version>1.1.1</Version>
<Version>1.1.2</Version>
<Authors>Maksym Sadovnychyy</Authors>
<Company>MAKS-IT</Company>
<Product>MaksIT.MongoDB.Linq</Product>

View File

@ -1,5 +1,5 @@
using MongoDB.Driver;
using System;
namespace MaksIT.MongoDB.Linq {
public class DisposableMongoSession : IDisposable {

View File

@ -4,7 +4,7 @@ using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
namespace MaksIT.MaksIT.MongoDB.Linq.Serializers;
namespace MaksIT.MongoDB.Linq.Serializers;
public class GuidKeyDictionarySerializer<TValue> : SerializerBase<Dictionary<Guid, TValue>> {
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, Dictionary<Guid, TValue> value) {

View File

@ -1,5 +1,4 @@
using System;
using System.Buffers.Binary;
using System.Buffers.Binary;
namespace MaksIT.MongoDB.Linq.Utilities {
public static class CombGuidGenerator {