(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; using MaksIT.MongoDB.Linq.Tests.Mock;
namespace MaksIT.MongoDB.Tests { namespace MaksIT.MongoDB.Tests;
// Sample DTO class for testing // Sample DTO class for testing
public class TestableDocumentDto : DtoDocumentBase<Guid> { public class TestableDocumentDto : DtoDocumentBase<Guid> {
public required string Name { get; set; } 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 // Override protected methods to use in-memory list instead of a real database
public class TestableCollectionDataProvider : BaseCollectionDataProviderBase<TestableCollectionDataProvider, TestableDocumentDto, Guid> { protected override IQueryable<TestableDocumentDto> GetQuery() => _inMemoryCollection.AsQueryable();
private readonly List<TestableDocumentDto> _inMemoryCollection;
public TestableCollectionDataProvider(ILogger<TestableCollectionDataProvider> logger) protected override async Task<Result<Guid>> InsertAsync(TestableDocumentDto document, IClientSessionHandle? session) {
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. _inMemoryCollection.Add(document);
: base(logger, new MongoClientMock(), "TestDatabase", "TestCollection") { return await Task.FromResult(Result<Guid>.Ok(document.Id));
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. }
_inMemoryCollection = new List<TestableDocumentDto>(); // Initialize correctly
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 async Task<Result<List<Guid>?>> UpsertManyWithPredicateAsync(List<TestableDocumentDto> documents, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
protected override IQueryable<TestableDocumentDto> GetQuery() => _inMemoryCollection.AsQueryable(); 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); _inMemoryCollection.Add(document);
return await Task.FromResult(Result<Guid>.Ok(document.Id)); 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) { protected override async Task<Result<List<Guid>?>> UpdateManyWithPredicateAsync(List<TestableDocumentDto> documents, Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
_inMemoryCollection.AddRange(documents); var existingDocuments = _inMemoryCollection.Where(predicate.Compile()).ToList();
return await Task.FromResult(Result<List<Guid>?>.Ok(documents.Select(d => d.Id).ToList())); if (existingDocuments.Any()) {
}
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();
foreach (var doc in existingDocuments) { foreach (var doc in existingDocuments) {
_inMemoryCollection.Remove(doc); _inMemoryCollection.Remove(doc);
} }
_inMemoryCollection.AddRange(documents); _inMemoryCollection.AddRange(documents);
return await Task.FromResult(Result<List<Guid>?>.Ok(documents.Select(d => d.Id).ToList())); 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<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();
}
} }
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());
public class TestableCollectionDataProviderTests {
private readonly TestableCollectionDataProvider _dataProvider;
public TestableCollectionDataProviderTests() {
// Set up a mock logger
var logger = new LoggerFactory().CreateLogger<TestableCollectionDataProvider>();
_dataProvider = new TestableCollectionDataProvider(logger);
} }
return await Task.FromResult(Result.InternalServerError("Delete failed"));
}
[Fact] protected override async Task<Result> DeleteManyWithPredicateAsync(Expression<Func<TestableDocumentDto, bool>> predicate, IClientSessionHandle? session) {
public async Task TestInsertAsync_ShouldReturnOkResult_WhenDocumentIsInserted() { var documentsToRemove = _inMemoryCollection.Where(predicate.Compile()).ToList();
// Arrange if (documentsToRemove.Any()) {
var document = new TestableDocumentDto { foreach (var doc in documentsToRemove) {
Id = CombGuidGenerator.CreateCombGuid(), _inMemoryCollection.Remove(doc);
Name = "Test Document" }
}; return await Task.FromResult(Result.Ok());
// Act
var result = await _dataProvider.TestInsertAsync(document, null);
// Assert
Assert.True(result.IsSuccess);
Assert.Equal(document.Id, result.Value);
} }
return await Task.FromResult(Result.InternalServerError("DeleteMany failed"));
}
[Fact] // Expose protected methods as public with different names for testing purposes
public async Task TestInsertManyAsync_ShouldReturnOkResult_WhenDocumentsAreInserted() { public async Task<Result<Guid>> TestInsertAsync(TestableDocumentDto document, IClientSessionHandle? session = null) {
// Arrange return await InsertAsync(document, session);
var documents = new List<TestableDocumentDto> }
{
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 1" },
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" } new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" }
}; };
// Act // Act
var result = await _dataProvider.TestInsertManyAsync(documents, null); var result = await _dataProvider.TestInsertManyAsync(documents, null);
// Assert // Assert
Assert.True(result.IsSuccess); Assert.True(result.IsSuccess);
Assert.Equal(2, result.Value?.Count); Assert.Equal(2, result.Value?.Count);
} }
[Fact] [Fact]
public async Task TestUpsertWithPredicateAsync_ShouldInsertNewDocument_WhenNoMatchingDocumentExists() { public async Task TestUpsertWithPredicateAsync_ShouldInsertNewDocument_WhenNoMatchingDocumentExists() {
// Arrange // Arrange
var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Test Document" }; var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Test Document" };
// Act // Act
var result = await _dataProvider.TestUpsertWithPredicateAsync(document, x => x.Id == document.Id, null); var result = await _dataProvider.TestUpsertWithPredicateAsync(document, x => x.Id == document.Id, null);
// Assert // Assert
Assert.True(result.IsSuccess); Assert.True(result.IsSuccess);
Assert.Equal(document.Id, result.Value); Assert.Equal(document.Id, result.Value);
} }
[Fact] [Fact]
public async Task TestUpsertWithPredicateAsync_ShouldUpdateExistingDocument_WhenMatchingDocumentExists() { public async Task TestUpsertWithPredicateAsync_ShouldUpdateExistingDocument_WhenMatchingDocumentExists() {
// Arrange // Arrange
var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Initial Document" }; var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Initial Document" };
await _dataProvider.TestInsertAsync(document, null); 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 // Act
var result = await _dataProvider.TestUpsertWithPredicateAsync(updatedDocument, x => x.Id == document.Id, null); var result = await _dataProvider.TestUpsertWithPredicateAsync(updatedDocument, x => x.Id == document.Id, null);
// Assert // Assert
Assert.True(result.IsSuccess); Assert.True(result.IsSuccess);
Assert.Equal(updatedDocument.Id, result.Value); Assert.Equal(updatedDocument.Id, result.Value);
var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == updatedDocument.Id); var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == updatedDocument.Id);
Assert.NotNull(inMemoryCollection); Assert.NotNull(inMemoryCollection);
Assert.Equal("Updated Document", inMemoryCollection.Name); Assert.Equal("Updated Document", inMemoryCollection.Name);
} }
[Fact] [Fact]
public async Task TestUpsertManyWithPredicateAsync_ShouldInsertNewDocuments_WhenNoMatchingDocumentsExist() { public async Task TestUpsertManyWithPredicateAsync_ShouldInsertNewDocuments_WhenNoMatchingDocumentsExist() {
// Arrange // Arrange
var documents = new List<TestableDocumentDto> var documents = new List<TestableDocumentDto>
{ {
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" }, new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" },
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" } new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" }
}; };
// Act // Act
var result = await _dataProvider.TestUpsertManyWithPredicateAsync(documents, x => documents.Select(d => d.Id).Contains(x.Id), null); var result = await _dataProvider.TestUpsertManyWithPredicateAsync(documents, x => documents.Select(d => d.Id).Contains(x.Id), null);
// Assert // Assert
Assert.True(result.IsSuccess); Assert.True(result.IsSuccess);
Assert.Equal(2, result.Value?.Count); Assert.Equal(2, result.Value?.Count);
} }
[Fact] [Fact]
public async Task TestUpdateWithPredicateAsync_ShouldUpdateDocument_WhenMatchingDocumentExists() { public async Task TestUpdateWithPredicateAsync_ShouldUpdateDocument_WhenMatchingDocumentExists() {
// Arrange // Arrange
var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Initial Document" }; var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Initial Document" };
await _dataProvider.TestInsertAsync(document, null); 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 // Act
var result = await _dataProvider.TestUpdateWithPredicateAsync(updatedDocument, x => x.Id == document.Id, null); var result = await _dataProvider.TestUpdateWithPredicateAsync(updatedDocument, x => x.Id == document.Id, null);
// Assert // Assert
Assert.True(result.IsSuccess); Assert.True(result.IsSuccess);
Assert.Equal(updatedDocument.Id, result.Value); Assert.Equal(updatedDocument.Id, result.Value);
var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == updatedDocument.Id); var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == updatedDocument.Id);
Assert.NotNull(inMemoryCollection); Assert.NotNull(inMemoryCollection);
Assert.Equal("Updated Document", inMemoryCollection.Name); Assert.Equal("Updated Document", inMemoryCollection.Name);
} }
[Fact] [Fact]
public async Task TestUpdateManyWithPredicateAsync_ShouldUpdateDocuments_WhenMatchingDocumentsExist() { public async Task TestUpdateManyWithPredicateAsync_ShouldUpdateDocuments_WhenMatchingDocumentsExist() {
// Arrange // Arrange
var documents = new List<TestableDocumentDto> var documents = new List<TestableDocumentDto>
{ {
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" }, new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" },
new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" } 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[0].Id, Name = "Updated Document 1" },
new TestableDocumentDto { Id = documents[1].Id, Name = "Updated Document 2" } new TestableDocumentDto { Id = documents[1].Id, Name = "Updated Document 2" }
}; };
// Act // Act
var result = await _dataProvider.TestUpdateManyWithPredicateAsync(updatedDocuments, x => updatedDocuments.Select(d => d.Id).Contains(x.Id), null); var result = await _dataProvider.TestUpdateManyWithPredicateAsync(updatedDocuments, x => updatedDocuments.Select(d => d.Id).Contains(x.Id), null);
// Assert // Assert
Assert.True(result.IsSuccess); Assert.True(result.IsSuccess);
Assert.Equal(2, result.Value?.Count); Assert.Equal(2, result.Value?.Count);
var inMemoryCollection = _dataProvider.GetInMemoryCollection().ToList(); var inMemoryCollection = _dataProvider.GetInMemoryCollection().ToList();
Assert.Equal("Updated Document 1", inMemoryCollection[0].Name); Assert.Equal("Updated Document 1", inMemoryCollection[0].Name);
Assert.Equal("Updated Document 2", inMemoryCollection[1].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");
}
} }
[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; 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) { public IEnumerable<T> Current => documents;
return false; // Only one batch of data
}
public Task<bool> MoveNextAsync(CancellationToken cancellationToken = default) { public bool MoveNext(CancellationToken cancellationToken = default) {
return Task.FromResult(false); 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;
using MongoDB.Driver.Core.Clusters; using MongoDB.Driver.Core.Clusters;
namespace MaksIT.MongoDB.Linq.Tests.Mock { namespace MaksIT.MongoDB.Linq.Tests.Mock;
internal class MongoClientMock : IMongoClient { internal class MongoClientMock : IMongoClient {
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
public IMongoDatabase GetDatabase(string name, MongoDatabaseSettings settings = null) { public IMongoDatabase GetDatabase(string name, MongoDatabaseSettings settings = null) {
return new MongoDatabaseMock(); return new MongoDatabaseMock();
} }
public IClientSessionHandle StartSession(ClientSessionOptions options = null, CancellationToken cancellationToken = default) { public IClientSessionHandle StartSession(ClientSessionOptions options = null, CancellationToken cancellationToken = default) {
return new MongoSessionMock(); return new MongoSessionMock();
} }
public Task<IClientSessionHandle> StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default) { public Task<IClientSessionHandle> StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default) {
return Task.FromResult((IClientSessionHandle)new MongoSessionMock()); 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) { public void DropDatabase(string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void DropDatabase(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) { public void DropDatabase(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default) { public Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task DropDatabaseAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) { public Task DropDatabaseAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<string> ListDatabaseNames(CancellationToken cancellationToken = default) { public IAsyncCursor<string> ListDatabaseNames(CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<string> ListDatabaseNames(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) { public IAsyncCursor<string> ListDatabaseNames(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<string> ListDatabaseNames(IClientSessionHandle session, CancellationToken cancellationToken = default) { public IAsyncCursor<string> ListDatabaseNames(IClientSessionHandle session, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<string> ListDatabaseNames(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) { public IAsyncCursor<string> ListDatabaseNames(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(CancellationToken cancellationToken = default) { public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<string>> ListDatabaseNamesAsync(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<BsonDocument> ListDatabases(CancellationToken cancellationToken = default) { public IAsyncCursor<BsonDocument> ListDatabases(CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<BsonDocument> ListDatabases(ListDatabasesOptions options, CancellationToken cancellationToken = default) { public IAsyncCursor<BsonDocument> ListDatabases(ListDatabasesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<BsonDocument> ListDatabases(IClientSessionHandle session, CancellationToken cancellationToken = default) { public IAsyncCursor<BsonDocument> ListDatabases(IClientSessionHandle session, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<BsonDocument> ListDatabases(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default) { public IAsyncCursor<BsonDocument> ListDatabases(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(CancellationToken cancellationToken = default) { public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(ListDatabasesOptions options, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(ListDatabasesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { public IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { public IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IMongoClient WithReadConcern(ReadConcern readConcern) { public IMongoClient WithReadConcern(ReadConcern readConcern) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IMongoClient WithReadPreference(ReadPreference readPreference) { public IMongoClient WithReadPreference(ReadPreference readPreference) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IMongoClient WithWriteConcern(WriteConcern writeConcern) { public IMongoClient WithWriteConcern(WriteConcern writeConcern) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public ClientBulkWriteResult BulkWrite(IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) { public ClientBulkWriteResult BulkWrite(IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public ClientBulkWriteResult BulkWrite(IClientSessionHandle session, IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) { public ClientBulkWriteResult BulkWrite(IClientSessionHandle session, IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<ClientBulkWriteResult> BulkWriteAsync(IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) { public Task<ClientBulkWriteResult> BulkWriteAsync(IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<ClientBulkWriteResult> BulkWriteAsync(IClientSessionHandle session, IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) { public Task<ClientBulkWriteResult> BulkWriteAsync(IClientSessionHandle session, IReadOnlyList<BulkWriteModel> models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void Dispose() { public void Dispose() {
throw new NotImplementedException(); throw new NotImplementedException();
} }
#endregion #endregion
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. #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;
using MongoDB.Driver.Search; using MongoDB.Driver.Search;
namespace MaksIT.MongoDB.Linq.Tests.Mock { namespace MaksIT.MongoDB.Linq.Tests.Mock;
internal class MongoCollectionMock<TDocument> : IMongoCollection<TDocument> {
internal class MongoCollectionMock<TDocument> : IMongoCollection<TDocument> {
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
#pragma warning disable CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete
#region not implemented #region not implemented
public CollectionNamespace CollectionNamespace => throw new NotImplementedException(); 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) { public IAsyncCursor<TResult> Aggregate<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<TResult> Aggregate<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<TResult> Aggregate<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void AggregateToCollection<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public void AggregateToCollection<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void AggregateToCollection<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public void AggregateToCollection<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task AggregateToCollectionAsync<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public Task AggregateToCollectionAsync<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task AggregateToCollectionAsync<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public Task AggregateToCollectionAsync<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public BulkWriteResult<TDocument> BulkWrite(IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) { public BulkWriteResult<TDocument> BulkWrite(IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public BulkWriteResult<TDocument> BulkWrite(IClientSessionHandle session, IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) { public BulkWriteResult<TDocument> BulkWrite(IClientSessionHandle session, IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<BulkWriteResult<TDocument>> BulkWriteAsync(IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) { public Task<BulkWriteResult<TDocument>> BulkWriteAsync(IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<BulkWriteResult<TDocument>> BulkWriteAsync(IClientSessionHandle session, IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) { public Task<BulkWriteResult<TDocument>> BulkWriteAsync(IClientSessionHandle session, IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public long Count(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) { public long Count(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public long Count(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) { public long Count(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<long> CountAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) { public Task<long> CountAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<long> CountAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) { public Task<long> CountAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public long CountDocuments(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) { public long CountDocuments(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public long CountDocuments(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) { public long CountDocuments(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<long> CountDocumentsAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) { public Task<long> CountDocumentsAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<long> CountDocumentsAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) { public Task<long> CountDocumentsAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public DeleteResult DeleteMany(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) { public DeleteResult DeleteMany(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public DeleteResult DeleteMany(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) { public DeleteResult DeleteMany(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public DeleteResult DeleteMany(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) { public DeleteResult DeleteMany(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<DeleteResult> DeleteManyAsync(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) { public Task<DeleteResult> DeleteManyAsync(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<DeleteResult> DeleteManyAsync(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) { public Task<DeleteResult> DeleteManyAsync(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<DeleteResult> DeleteManyAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) { public Task<DeleteResult> DeleteManyAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public DeleteResult DeleteOne(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) { public DeleteResult DeleteOne(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public DeleteResult DeleteOne(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) { public DeleteResult DeleteOne(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public DeleteResult DeleteOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) { public DeleteResult DeleteOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<DeleteResult> DeleteOneAsync(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) { public Task<DeleteResult> DeleteOneAsync(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<DeleteResult> DeleteOneAsync(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) { public Task<DeleteResult> DeleteOneAsync(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<DeleteResult> DeleteOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) { public Task<DeleteResult> DeleteOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<TField> Distinct<TField>(FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<TField> Distinct<TField>(FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<TField> Distinct<TField>(IClientSessionHandle session, FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<TField> Distinct<TField>(IClientSessionHandle session, FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<TField>> DistinctAsync<TField>(FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<TField>> DistinctAsync<TField>(FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<TField>> DistinctAsync<TField>(IClientSessionHandle session, FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<TField>> DistinctAsync<TField>(IClientSessionHandle session, FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<TItem> DistinctMany<TItem>(FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<TItem> DistinctMany<TItem>(FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<TItem> DistinctMany<TItem>(IClientSessionHandle session, FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<TItem> DistinctMany<TItem>(IClientSessionHandle session, FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<TItem>> DistinctManyAsync<TItem>(FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<TItem>> DistinctManyAsync<TItem>(FieldDefinition<TDocument, IEnumerable<TItem>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); 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) { 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(); throw new NotImplementedException();
} }
public long EstimatedDocumentCount(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default) { public long EstimatedDocumentCount(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<long> EstimatedDocumentCountAsync(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default) { public Task<long> EstimatedDocumentCountAsync(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<TProjection>> FindAsync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<TProjection>> FindAsync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<TProjection>> FindAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<TProjection>> FindAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public TProjection FindOneAndDelete<TProjection>(FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public TProjection FindOneAndDelete<TProjection>(FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public TProjection FindOneAndDelete<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public TProjection FindOneAndDelete<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<TProjection> FindOneAndDeleteAsync<TProjection>(FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public Task<TProjection> FindOneAndDeleteAsync<TProjection>(FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<TProjection> FindOneAndDeleteAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public Task<TProjection> FindOneAndDeleteAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public TProjection FindOneAndReplace<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public TProjection FindOneAndReplace<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public TProjection FindOneAndReplace<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public TProjection FindOneAndReplace<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<TProjection> FindOneAndReplaceAsync<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public Task<TProjection> FindOneAndReplaceAsync<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<TProjection> FindOneAndReplaceAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public Task<TProjection> FindOneAndReplaceAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public TProjection FindOneAndUpdate<TProjection>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public TProjection FindOneAndUpdate<TProjection>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public TProjection FindOneAndUpdate<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public TProjection FindOneAndUpdate<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<TProjection> FindOneAndUpdateAsync<TProjection>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public Task<TProjection> FindOneAndUpdateAsync<TProjection>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<TProjection> FindOneAndUpdateAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public Task<TProjection> FindOneAndUpdateAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<TProjection> FindSync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<TProjection> FindSync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<TProjection> FindSync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<TProjection> FindSync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void InsertMany(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) { public void InsertMany(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void InsertMany(IClientSessionHandle session, IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) { public void InsertMany(IClientSessionHandle session, IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task InsertManyAsync(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) { public Task InsertManyAsync(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task InsertManyAsync(IClientSessionHandle session, IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) { public Task InsertManyAsync(IClientSessionHandle session, IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void InsertOne(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) { public void InsertOne(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void InsertOne(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) { public void InsertOne(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task InsertOneAsync(TDocument document, CancellationToken _cancellationToken) { public Task InsertOneAsync(TDocument document, CancellationToken _cancellationToken) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task InsertOneAsync(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) { public Task InsertOneAsync(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task InsertOneAsync(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) { public Task InsertOneAsync(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<TResult> MapReduce<TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<TResult> MapReduce<TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<TResult> MapReduce<TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<TResult> MapReduce<TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<TResult>> MapReduceAsync<TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<TResult>> MapReduceAsync<TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<TResult>> MapReduceAsync<TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<TResult>> MapReduceAsync<TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IFilteredMongoCollection<TDerivedDocument> OfType<TDerivedDocument>() where TDerivedDocument : TDocument { public IFilteredMongoCollection<TDerivedDocument> OfType<TDerivedDocument>() where TDerivedDocument : TDocument {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public ReplaceOneResult ReplaceOne(FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) { public ReplaceOneResult ReplaceOne(FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public ReplaceOneResult ReplaceOne(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) { public ReplaceOneResult ReplaceOne(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) { public ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) { public ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<ReplaceOneResult> ReplaceOneAsync(FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) { public Task<ReplaceOneResult> ReplaceOneAsync(FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<ReplaceOneResult> ReplaceOneAsync(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) { public Task<ReplaceOneResult> ReplaceOneAsync(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) { public Task<ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) { public Task<ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public UpdateResult UpdateMany(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) { public UpdateResult UpdateMany(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public UpdateResult UpdateMany(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) { public UpdateResult UpdateMany(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<UpdateResult> UpdateManyAsync(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) { public Task<UpdateResult> UpdateManyAsync(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<UpdateResult> UpdateManyAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) { public Task<UpdateResult> UpdateManyAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public UpdateResult UpdateOne(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) { public UpdateResult UpdateOne(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public UpdateResult UpdateOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) { public UpdateResult UpdateOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<UpdateResult> UpdateOneAsync(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) { public Task<UpdateResult> UpdateOneAsync(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<UpdateResult> UpdateOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) { public Task<UpdateResult> UpdateOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { public IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { public IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IMongoCollection<TDocument> WithReadConcern(ReadConcern readConcern) { public IMongoCollection<TDocument> WithReadConcern(ReadConcern readConcern) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IMongoCollection<TDocument> WithReadPreference(ReadPreference readPreference) { public IMongoCollection<TDocument> WithReadPreference(ReadPreference readPreference) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IMongoCollection<TDocument> WithWriteConcern(WriteConcern writeConcern) { public IMongoCollection<TDocument> WithWriteConcern(WriteConcern writeConcern) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
#endregion #endregion
#pragma warning restore CS0618 // Type or member is obsolete #pragma warning restore CS0618 // Type or member is obsolete
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
} }

View File

@ -1,221 +1,222 @@
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Driver; 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. #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
public IAsyncCursor<string> ListCollectionNames(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<string> ListCollectionNames(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) {
return new MongoAsyncCursorMock<string>(new List<string>() { "TestCollection" }); return new MongoAsyncCursorMock<string>(new List<string>() { "TestCollection" });
} }
public void CreateCollection(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) { public void CreateCollection(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) {
return; return;
} }
public IMongoCollection<TDocument> GetCollection<TDocument>(string name, MongoCollectionSettings settings = null) { public IMongoCollection<TDocument> GetCollection<TDocument>(string name, MongoCollectionSettings settings = null) {
return new MongoCollectionMock<TDocument>(); 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) { public IAsyncCursor<TResult> Aggregate<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<TResult> Aggregate<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<TResult> Aggregate<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void AggregateToCollection<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public void AggregateToCollection<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void AggregateToCollection<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public void AggregateToCollection<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task AggregateToCollectionAsync<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public Task AggregateToCollectionAsync<TResult>(PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task AggregateToCollectionAsync<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { public Task AggregateToCollectionAsync<TResult>(IClientSessionHandle session, PipelineDefinition<NoPipelineInput, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void CreateCollection(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) { public void CreateCollection(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task CreateCollectionAsync(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) { public Task CreateCollectionAsync(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task CreateCollectionAsync(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) { public Task CreateCollectionAsync(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void CreateView<TDocument, TResult>(string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default) { public void CreateView<TDocument, TResult>(string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); 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) { 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(); throw new NotImplementedException();
} }
public Task CreateViewAsync<TDocument, TResult>(string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default) { public Task CreateViewAsync<TDocument, TResult>(string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); 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) { 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(); throw new NotImplementedException();
} }
public void DropCollection(string name, CancellationToken cancellationToken = default) { public void DropCollection(string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void DropCollection(string name, DropCollectionOptions options, CancellationToken cancellationToken = default) { public void DropCollection(string name, DropCollectionOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void DropCollection(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) { public void DropCollection(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void DropCollection(IClientSessionHandle session, string name, DropCollectionOptions options, CancellationToken cancellationToken = default) { public void DropCollection(IClientSessionHandle session, string name, DropCollectionOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task DropCollectionAsync(string name, CancellationToken cancellationToken = default) { public Task DropCollectionAsync(string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task DropCollectionAsync(string name, DropCollectionOptions options, CancellationToken cancellationToken = default) { public Task DropCollectionAsync(string name, DropCollectionOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task DropCollectionAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) { public Task DropCollectionAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task DropCollectionAsync(IClientSessionHandle session, string name, DropCollectionOptions options, CancellationToken cancellationToken = default) { public Task DropCollectionAsync(IClientSessionHandle session, string name, DropCollectionOptions options, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<string> ListCollectionNames(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<string> ListCollectionNames(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<string>> ListCollectionNamesAsync(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<string>> ListCollectionNamesAsync(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<string>> ListCollectionNamesAsync(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<string>> ListCollectionNamesAsync(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<BsonDocument> ListCollections(ListCollectionsOptions options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<BsonDocument> ListCollections(ListCollectionsOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IAsyncCursor<BsonDocument> ListCollections(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default) { public IAsyncCursor<BsonDocument> ListCollections(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<BsonDocument>> ListCollectionsAsync(ListCollectionsOptions options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<BsonDocument>> ListCollectionsAsync(ListCollectionsOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IAsyncCursor<BsonDocument>> ListCollectionsAsync(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default) { public Task<IAsyncCursor<BsonDocument>> ListCollectionsAsync(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void RenameCollection(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) { public void RenameCollection(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void RenameCollection(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) { public void RenameCollection(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task RenameCollectionAsync(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) { public Task RenameCollectionAsync(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task RenameCollectionAsync(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) { public Task RenameCollectionAsync(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public TResult RunCommand<TResult>(Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) { public TResult RunCommand<TResult>(Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public TResult RunCommand<TResult>(IClientSessionHandle session, Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) { public TResult RunCommand<TResult>(IClientSessionHandle session, Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<TResult> RunCommandAsync<TResult>(Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) { public Task<TResult> RunCommandAsync<TResult>(Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<TResult> RunCommandAsync<TResult>(IClientSessionHandle session, Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) { public Task<TResult> RunCommandAsync<TResult>(IClientSessionHandle session, Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { public IChangeStreamCursor<TResult> Watch<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { public IChangeStreamCursor<TResult> Watch<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { public Task<IChangeStreamCursor<TResult>> WatchAsync<TResult>(IClientSessionHandle session, PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IMongoDatabase WithReadConcern(ReadConcern readConcern) { public IMongoDatabase WithReadConcern(ReadConcern readConcern) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IMongoDatabase WithReadPreference(ReadPreference readPreference) { public IMongoDatabase WithReadPreference(ReadPreference readPreference) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public IMongoDatabase WithWriteConcern(WriteConcern writeConcern) { public IMongoDatabase WithWriteConcern(WriteConcern writeConcern) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
#endregion #endregion
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. #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.Bindings;
using MongoDB.Driver.Core.Clusters; 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. #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) { public void StartTransaction(TransactionOptions transactionOptions = null) {
IsInTransaction = true; IsInTransaction = true;
} }
public Task StartTransactionAsync(TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) { public Task StartTransactionAsync(TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) {
IsInTransaction = true; IsInTransaction = true;
return Task.CompletedTask; return Task.CompletedTask;
} }
public void AbortTransaction(CancellationToken cancellationToken = default) { public void AbortTransaction(CancellationToken cancellationToken = default) {
IsInTransaction = false; IsInTransaction = false;
} }
public Task AbortTransactionAsync(CancellationToken cancellationToken = default) { public Task AbortTransactionAsync(CancellationToken cancellationToken = default) {
IsInTransaction = false; IsInTransaction = false;
return Task.CompletedTask; return Task.CompletedTask;
} }
public void CommitTransaction(CancellationToken cancellationToken = default) { public void CommitTransaction(CancellationToken cancellationToken = default) {
IsInTransaction = false; IsInTransaction = false;
} }
public Task CommitTransactionAsync(CancellationToken cancellationToken = default) { public Task CommitTransactionAsync(CancellationToken cancellationToken = default) {
IsInTransaction = false; IsInTransaction = false;
return Task.CompletedTask; 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() { public void Dispose() {
// Simulate disposing of the session // Simulate disposing of the session
} }
public IClientSessionHandle Fork() { public IClientSessionHandle Fork() {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void AdvanceClusterTime(BsonDocument newClusterTime) { public void AdvanceClusterTime(BsonDocument newClusterTime) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void AdvanceOperationTime(BsonTimestamp newOperationTime) { public void AdvanceOperationTime(BsonTimestamp newOperationTime) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public TResult WithTransaction<TResult>(Func<IClientSessionHandle, CancellationToken, TResult> callback, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) { public TResult WithTransaction<TResult>(Func<IClientSessionHandle, CancellationToken, TResult> callback, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<TResult> WithTransactionAsync<TResult>(Func<IClientSessionHandle, CancellationToken, Task<TResult>> callbackAsync, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) { public Task<TResult> WithTransactionAsync<TResult>(Func<IClientSessionHandle, CancellationToken, Task<TResult>> callbackAsync, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) {
throw new NotImplementedException(); throw new NotImplementedException();
} }
#endregion #endregion
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
} }

View File

@ -3,64 +3,65 @@
using MaksIT.Results; using MaksIT.Results;
using MaksIT.MongoDB.Linq.Tests.Mock; using MaksIT.MongoDB.Linq.Tests.Mock;
namespace MaksIT.MongoDB.Linq.Tests {
public class MongoSessionManagerTests {
private readonly MongoSessionManager _sessionManager; namespace MaksIT.MongoDB.Linq.Tests;
private readonly ILogger<MongoSessionManager> _logger;
public MongoSessionManagerTests() { public class MongoSessionManagerTests {
_logger = new LoggerFactory().CreateLogger<MongoSessionManager>();
var mockClient = new MongoClientMock();
_sessionManager = new MongoSessionManager(_logger, mockClient);
}
[Fact] private readonly MongoSessionManager _sessionManager;
public void ExecuteInSession_ShouldCommitTransaction_WhenActionSucceeds() { private readonly ILogger<MongoSessionManager> _logger;
// Act
var result = _sessionManager.ExecuteInSession(session => {
// Simulate successful operation
return Result.Ok();
});
// Assert public MongoSessionManagerTests() {
Assert.True(result.IsSuccess); _logger = new LoggerFactory().CreateLogger<MongoSessionManager>();
} var mockClient = new MongoClientMock();
_sessionManager = new MongoSessionManager(_logger, mockClient);
}
[Fact] [Fact]
public void ExecuteInSession_ShouldAbortTransaction_WhenActionFails() { public void ExecuteInSession_ShouldCommitTransaction_WhenActionSucceeds() {
// Act // Act
var result = _sessionManager.ExecuteInSession(session => { var result = _sessionManager.ExecuteInSession(session => {
// Simulate failed operation // Simulate successful operation
return Result.InternalServerError("Simulated failure"); return Result.Ok();
}); });
// Assert // Assert
Assert.False(result.IsSuccess); Assert.True(result.IsSuccess);
} }
[Fact] [Fact]
public async Task ExecuteInSessionAsync_ShouldCommitTransaction_WhenActionSucceeds() { public void ExecuteInSession_ShouldAbortTransaction_WhenActionFails() {
// Act // Act
var result = await _sessionManager.ExecuteInSessionAsync(async session => { var result = _sessionManager.ExecuteInSession(session => {
// Simulate successful operation // Simulate failed operation
return await Task.FromResult(Result.Ok()); return Result.InternalServerError("Simulated failure");
}); });
// Assert // Assert
Assert.True(result.IsSuccess); Assert.False(result.IsSuccess);
} }
[Fact] [Fact]
public async Task ExecuteInSessionAsync_ShouldAbortTransaction_WhenActionFails() { public async Task ExecuteInSessionAsync_ShouldCommitTransaction_WhenActionSucceeds() {
// Act // Act
var result = await _sessionManager.ExecuteInSessionAsync(async session => { var result = await _sessionManager.ExecuteInSessionAsync(async session => {
// Simulate failed operation // Simulate successful operation
return await Task.FromResult(Result.InternalServerError("Simulated failure")); return await Task.FromResult(Result.Ok());
}); });
// Assert // Assert
Assert.False(result.IsSuccess); 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; 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 namespace MaksIT.MongoDB.Linq.Tests.Utilities;
Assert.NotEqual(Guid.Empty, combGuid);
}
[Fact] public class CombGuidGeneratorTests {
public void CreateCombGuid_WithSpecificGuidAndCurrentTimestamp_ShouldEmbedTimestamp() { [Fact]
// Arrange public void CreateCombGuid_WithCurrentTimestamp_ShouldGenerateGuid() {
Guid inputGuid = Guid.NewGuid(); // Act
Guid combGuid = CombGuidGenerator.CreateCombGuid();
// Act // Assert
Guid combGuid = CombGuidGenerator.CreateCombGuid(inputGuid); Assert.NotEqual(Guid.Empty, combGuid);
DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid); }
// Assert [Fact]
Assert.NotEqual(Guid.Empty, combGuid); public void CreateCombGuid_WithSpecificGuidAndCurrentTimestamp_ShouldEmbedTimestamp() {
Assert.True(extractedTimestamp <= DateTime.UtcNow, "The extracted timestamp should not be in the future."); // Arrange
Assert.True(extractedTimestamp >= DateTime.UtcNow.AddSeconds(-5), "The extracted timestamp should be recent."); Guid inputGuid = Guid.NewGuid();
}
[Fact] // Act
public void CreateCombGuid_WithSpecificTimestamp_ShouldGenerateGuidWithEmbeddedTimestamp() { Guid combGuid = CombGuidGenerator.CreateCombGuid(inputGuid);
// Arrange DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid);
DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc);
// Act // Assert
Guid combGuid = CombGuidGenerator.CreateCombGuid(timestamp); Assert.NotEqual(Guid.Empty, combGuid);
DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(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 [Fact]
Assert.NotEqual(Guid.Empty, combGuid); public void CreateCombGuid_WithSpecificTimestamp_ShouldGenerateGuidWithEmbeddedTimestamp() {
Assert.Equal(timestamp, extractedTimestamp); // Arrange
} DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc);
[Fact] // Act
public void CreateCombGuid_WithGuidAndSpecificTimestamp_ShouldGenerateGuidWithEmbeddedTimestamp() { Guid combGuid = CombGuidGenerator.CreateCombGuid(timestamp);
// Arrange DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid);
Guid inputGuid = Guid.NewGuid();
DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc);
// Act // Assert
Guid combGuid = CombGuidGenerator.CreateCombGuidWithTimestamp(inputGuid, timestamp); Assert.NotEqual(Guid.Empty, combGuid);
DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid); Assert.Equal(timestamp, extractedTimestamp);
}
// Assert [Fact]
Assert.NotEqual(Guid.Empty, combGuid); public void CreateCombGuid_WithGuidAndSpecificTimestamp_ShouldGenerateGuidWithEmbeddedTimestamp() {
Assert.Equal(timestamp, extractedTimestamp); // Arrange
} Guid inputGuid = Guid.NewGuid();
DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc);
[Fact] // Act
public void ExtractTimestamp_ShouldExtractCorrectTimestampFromCombGuid() { Guid combGuid = CombGuidGenerator.CreateCombGuidWithTimestamp(inputGuid, timestamp);
// Arrange DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid);
DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc);
Guid combGuid = CombGuidGenerator.CreateCombGuid(timestamp);
// Act // Assert
DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid); Assert.NotEqual(Guid.Empty, combGuid);
Assert.Equal(timestamp, extractedTimestamp);
}
// Assert [Fact]
Assert.Equal(timestamp, extractedTimestamp); public void ExtractTimestamp_ShouldExtractCorrectTimestampFromCombGuid() {
} // Arrange
DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc);
Guid combGuid = CombGuidGenerator.CreateCombGuid(timestamp);
[Fact] // Act
public void ExtractTimestamp_WithInvalidGuid_ShouldThrowException() { DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid);
// Arrange
Guid invalidGuid = Guid.NewGuid();
// Act & Assert // Assert
var exception = Record.Exception(() => CombGuidGenerator.ExtractTimestamp(invalidGuid)); Assert.Equal(timestamp, extractedTimestamp);
Assert.Null(exception); // Adjusted expectation based on behavior of `ExtractTimestamp` with a regular GUID }
}
[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; using MaksIT.Results;
namespace MaksIT.MongoDB.Linq.Abstractions { namespace MaksIT.MongoDB.Linq.Abstractions;
public abstract class BaseCollectionDataProviderBase<T, TDtoDocument, TDtoKey> : DataProviderBase<T>
where TDtoDocument : DtoDocumentBase<TDtoKey> {
protected readonly IMongoCollection<TDtoDocument> Collection; public abstract class BaseCollectionDataProviderBase<T, TDtoDocument, TDtoKey> : DataProviderBase<T>
protected readonly string _errorMessage = "MaksIT.MongoDB.Linq - Data provider error"; where TDtoDocument : DtoDocumentBase<TDtoKey> {
protected BaseCollectionDataProviderBase( protected readonly IMongoCollection<TDtoDocument> Collection;
ILogger<T> logger, protected readonly string _errorMessage = "MaksIT.MongoDB.Linq - Data provider error";
IMongoClient client,
string databaseName,
string collectionName
) : base(logger, client, databaseName) {
if (!Database.ListCollectionNames().ToList().Contains(collectionName))
Database.CreateCollection(collectionName);
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 Collection = Database.GetCollection<TDtoDocument>(collectionName);
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
} }
#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.Results;
using MaksIT.Core.Abstractions.Dto; using MaksIT.Core.Abstractions.Dto;
namespace MaksIT.MongoDB.Linq.Abstractions {
public abstract class CollectionDataProviderBase<T, TDtoDocument, TDtoKey> : BaseCollectionDataProviderBase<T, TDtoDocument, TDtoKey> namespace MaksIT.MongoDB.Linq.Abstractions;
where TDtoDocument : DtoDocumentBase<TDtoKey> {
protected CollectionDataProviderBase( public abstract class CollectionDataProviderBase<T, TDtoDocument, TDtoKey> : BaseCollectionDataProviderBase<T, TDtoDocument, TDtoKey>
ILogger<T> logger, where TDtoDocument : DtoDocumentBase<TDtoKey> {
IMongoClient client,
string databaseName,
string collectionName
) : base(logger, client, databaseName, collectionName) { }
#region Insert protected CollectionDataProviderBase(
public Result<TDtoKey?> Insert(TDtoDocument obj, IClientSessionHandle? session) => ILogger<T> logger,
InsertAsync(obj, session).Result; IMongoClient client,
#endregion string databaseName,
string collectionName
) : base(logger, client, databaseName, collectionName) { }
#region InsertMany #region Insert
public Result<List<TDtoKey>?> InsertMany(List<TDtoDocument> objList, IClientSessionHandle? session) => public Result<TDtoKey?> Insert(TDtoDocument obj, IClientSessionHandle? session) =>
InsertManyAsync(objList, session).Result; InsertAsync(obj, session).Result;
#endregion #endregion
#region Count #region InsertMany
protected Result<int?> CountWithPredicate(Expression<Func<TDtoDocument, bool>> predicate) => public Result<List<TDtoKey>?> InsertMany(List<TDtoDocument> objList, IClientSessionHandle? session) =>
CountWithPredicate(new List<Expression<Func<TDtoDocument, bool>>> { predicate }); InsertManyAsync(objList, session).Result;
#endregion
private protected Result<int?> CountWithPredicate(List<Expression<Func<TDtoDocument, bool>>> predicates) { #region Count
try { protected Result<int?> CountWithPredicate(Expression<Func<TDtoDocument, bool>> predicate) =>
var query = GetWithPredicate(predicates); 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); var result = query.Count();
}
catch (Exception ex) { return Result<int?>.Ok(result);
Logger.LogError(ex, _errorMessage);
return Result<int?>.InternalServerError(null, _errorMessage);
}
} }
#endregion catch (Exception ex) {
Logger.LogError(ex, _errorMessage);
#region Get return Result<int?>.InternalServerError(null, _errorMessage);
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
} }
#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 Microsoft.Extensions.Logging;
using MongoDB.Driver; 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( namespace MaksIT.MongoDB.Linq.Abstractions;
ILogger<T> logger,
IMongoClient client, public abstract class DataProviderBase<T> {
string databaseName) { protected readonly ILogger<T> Logger;
Logger = logger; protected readonly IMongoDatabase Database;
_client = client; private readonly IMongoClient _client;
Database = _client.GetDatabase(databaseName);
} 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> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>MaksIT.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace> <RootNamespace>$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<!-- NuGet package metadata --> <!-- NuGet package metadata -->
<PackageId>MaksIT.MongoDB.Linq</PackageId> <PackageId>MaksIT.MongoDB.Linq</PackageId>
<Version>1.1.1</Version> <Version>1.1.2</Version>
<Authors>Maksym Sadovnychyy</Authors> <Authors>Maksym Sadovnychyy</Authors>
<Company>MAKS-IT</Company> <Company>MAKS-IT</Company>
<Product>MaksIT.MongoDB.Linq</Product> <Product>MaksIT.MongoDB.Linq</Product>

View File

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

View File

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