diff --git a/src/MaksIT.MongoDB.Linq.Tests/CollectionDataProviderBaseTests.cs b/src/MaksIT.MongoDB.Linq.Tests/CollectionDataProviderBaseTests.cs index d6f9966..8d0e43c 100644 --- a/src/MaksIT.MongoDB.Linq.Tests/CollectionDataProviderBaseTests.cs +++ b/src/MaksIT.MongoDB.Linq.Tests/CollectionDataProviderBaseTests.cs @@ -10,341 +10,335 @@ using MaksIT.MongoDB.Linq.Utilities; using MaksIT.MongoDB.Linq.Tests.Mock; -namespace MaksIT.MongoDB.Tests { +namespace MaksIT.MongoDB.Tests; - // Sample DTO class for testing - public class TestableDocumentDto : DtoDocumentBase { - public required string Name { get; set; } +// Sample DTO class for testing +public class TestableDocumentDto : DtoDocumentBase { + public required string Name { get; set; } +} + +// Generalized Testable class to simulate MongoDB operations using an in-memory list +public class TestableCollectionDataProvider : BaseCollectionDataProviderBase { + private readonly List _inMemoryCollection; + + public TestableCollectionDataProvider(ILogger 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(); // Initialize correctly } - // Generalized Testable class to simulate MongoDB operations using an in-memory list - public class TestableCollectionDataProvider : BaseCollectionDataProviderBase { - private readonly List _inMemoryCollection; + // Override protected methods to use in-memory list instead of a real database + protected override IQueryable GetQuery() => _inMemoryCollection.AsQueryable(); - public TestableCollectionDataProvider(ILogger 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(); // Initialize correctly + protected override async Task> InsertAsync(TestableDocumentDto document, IClientSessionHandle? session) { + _inMemoryCollection.Add(document); + return await Task.FromResult(Result.Ok(document.Id)); + } + + protected override async Task?>> InsertManyAsync(List documents, IClientSessionHandle? session) { + _inMemoryCollection.AddRange(documents); + return await Task.FromResult(Result?>.Ok(documents.Select(d => d.Id).ToList())); + } + + protected override async Task> UpsertWithPredicateAsync(TestableDocumentDto document, Expression> predicate, IClientSessionHandle? session) { + var existingDocument = _inMemoryCollection.FirstOrDefault(predicate.Compile()); + if (existingDocument != null) { + _inMemoryCollection.Remove(existingDocument); } + _inMemoryCollection.Add(document); + return await Task.FromResult(Result.Ok(document.Id)); + } - // Override protected methods to use in-memory list instead of a real database - protected override IQueryable GetQuery() => _inMemoryCollection.AsQueryable(); + protected override async Task?>> UpsertManyWithPredicateAsync(List documents, Expression> predicate, IClientSessionHandle? session) { + var existingDocuments = _inMemoryCollection.Where(predicate.Compile()).ToList(); + foreach (var doc in existingDocuments) { + _inMemoryCollection.Remove(doc); + } + _inMemoryCollection.AddRange(documents); + return await Task.FromResult(Result?>.Ok(documents.Select(d => d.Id).ToList())); + } - protected override async Task> InsertAsync(TestableDocumentDto document, IClientSessionHandle? session) { + protected override async Task> UpdateWithPredicateAsync(TestableDocumentDto document, Expression> predicate, IClientSessionHandle? session) { + var existingDocument = _inMemoryCollection.FirstOrDefault(predicate.Compile()); + if (existingDocument != null) { + _inMemoryCollection.Remove(existingDocument); _inMemoryCollection.Add(document); return await Task.FromResult(Result.Ok(document.Id)); } + return await Task.FromResult(Result.InternalServerError(default(Guid), "Update failed")); + } - protected override async Task?>> InsertManyAsync(List documents, IClientSessionHandle? session) { - _inMemoryCollection.AddRange(documents); - return await Task.FromResult(Result?>.Ok(documents.Select(d => d.Id).ToList())); - } - - protected override async Task> UpsertWithPredicateAsync(TestableDocumentDto document, Expression> predicate, IClientSessionHandle? session) { - var existingDocument = _inMemoryCollection.FirstOrDefault(predicate.Compile()); - if (existingDocument != null) { - _inMemoryCollection.Remove(existingDocument); - } - _inMemoryCollection.Add(document); - return await Task.FromResult(Result.Ok(document.Id)); - } - - protected override async Task?>> UpsertManyWithPredicateAsync(List documents, Expression> predicate, IClientSessionHandle? session) { - var existingDocuments = _inMemoryCollection.Where(predicate.Compile()).ToList(); + protected override async Task?>> UpdateManyWithPredicateAsync(List documents, Expression> 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?>.Ok(documents.Select(d => d.Id).ToList())); } - - protected override async Task> UpdateWithPredicateAsync(TestableDocumentDto document, Expression> predicate, IClientSessionHandle? session) { - var existingDocument = _inMemoryCollection.FirstOrDefault(predicate.Compile()); - if (existingDocument != null) { - _inMemoryCollection.Remove(existingDocument); - _inMemoryCollection.Add(document); - return await Task.FromResult(Result.Ok(document.Id)); - } - return await Task.FromResult(Result.InternalServerError(default(Guid), "Update failed")); - } - - protected override async Task?>> UpdateManyWithPredicateAsync(List documents, Expression> 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?>.Ok(documents.Select(d => d.Id).ToList())); - } - return await Task.FromResult(Result?>.InternalServerError(default, "UpdateMany failed")); - } - - protected override async Task DeleteWithPredicateAsync(Expression> 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 DeleteManyWithPredicateAsync(Expression> 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> TestInsertAsync(TestableDocumentDto document, IClientSessionHandle? session = null) { - return await InsertAsync(document, session); - } - - public async Task?>> TestInsertManyAsync(List documents, IClientSessionHandle? session = null) { - return await InsertManyAsync(documents, session); - } - - public async Task> TestUpsertWithPredicateAsync(TestableDocumentDto document, Expression> predicate, IClientSessionHandle? session = null) { - return await UpsertWithPredicateAsync(document, predicate, session); - } - - public async Task?>> TestUpsertManyWithPredicateAsync(List documents, Expression> predicate, IClientSessionHandle? session = null) { - return await UpsertManyWithPredicateAsync(documents, predicate, session); - } - - public async Task> TestUpdateWithPredicateAsync(TestableDocumentDto document, Expression> predicate, IClientSessionHandle? session = null) { - return await UpdateWithPredicateAsync(document, predicate, session); - } - - public async Task?>> TestUpdateManyWithPredicateAsync(List documents, Expression> predicate, IClientSessionHandle? session = null) { - return await UpdateManyWithPredicateAsync(documents, predicate, session); - } - - public async Task TestDeleteWithPredicateAsync(Expression> predicate, IClientSessionHandle? session = null) { - return await DeleteWithPredicateAsync(predicate, session); - } - - public async Task TestDeleteManyWithPredicateAsync(Expression> predicate, IClientSessionHandle? session = null) { - return await DeleteManyWithPredicateAsync(predicate, session); - } - - // Helper method to access the in-memory collection for validation - public IQueryable GetInMemoryCollection() { - return _inMemoryCollection.AsQueryable(); - } + return await Task.FromResult(Result?>.InternalServerError(default, "UpdateMany failed")); } - - - - - - public class TestableCollectionDataProviderTests { - private readonly TestableCollectionDataProvider _dataProvider; - - public TestableCollectionDataProviderTests() { - // Set up a mock logger - var logger = new LoggerFactory().CreateLogger(); - _dataProvider = new TestableCollectionDataProvider(logger); + protected override async Task DeleteWithPredicateAsync(Expression> predicate, IClientSessionHandle? session) { + var documentToRemove = _inMemoryCollection.FirstOrDefault(predicate.Compile()); + if (documentToRemove != null) { + _inMemoryCollection.Remove(documentToRemove); + return await Task.FromResult(Result.Ok()); } + return await Task.FromResult(Result.InternalServerError("Delete failed")); + } - [Fact] - public async Task TestInsertAsync_ShouldReturnOkResult_WhenDocumentIsInserted() { - // Arrange - var document = new TestableDocumentDto { - Id = CombGuidGenerator.CreateCombGuid(), - Name = "Test Document" - }; - - // Act - var result = await _dataProvider.TestInsertAsync(document, null); - - // Assert - Assert.True(result.IsSuccess); - Assert.Equal(document.Id, result.Value); + protected override async Task DeleteManyWithPredicateAsync(Expression> predicate, IClientSessionHandle? session) { + var documentsToRemove = _inMemoryCollection.Where(predicate.Compile()).ToList(); + if (documentsToRemove.Any()) { + foreach (var doc in documentsToRemove) { + _inMemoryCollection.Remove(doc); + } + return await Task.FromResult(Result.Ok()); } + return await Task.FromResult(Result.InternalServerError("DeleteMany failed")); + } - [Fact] - public async Task TestInsertManyAsync_ShouldReturnOkResult_WhenDocumentsAreInserted() { - // Arrange - var documents = new List - { + // Expose protected methods as public with different names for testing purposes + public async Task> TestInsertAsync(TestableDocumentDto document, IClientSessionHandle? session = null) { + return await InsertAsync(document, session); + } + + public async Task?>> TestInsertManyAsync(List documents, IClientSessionHandle? session = null) { + return await InsertManyAsync(documents, session); + } + + public async Task> TestUpsertWithPredicateAsync(TestableDocumentDto document, Expression> predicate, IClientSessionHandle? session = null) { + return await UpsertWithPredicateAsync(document, predicate, session); + } + + public async Task?>> TestUpsertManyWithPredicateAsync(List documents, Expression> predicate, IClientSessionHandle? session = null) { + return await UpsertManyWithPredicateAsync(documents, predicate, session); + } + + public async Task> TestUpdateWithPredicateAsync(TestableDocumentDto document, Expression> predicate, IClientSessionHandle? session = null) { + return await UpdateWithPredicateAsync(document, predicate, session); + } + + public async Task?>> TestUpdateManyWithPredicateAsync(List documents, Expression> predicate, IClientSessionHandle? session = null) { + return await UpdateManyWithPredicateAsync(documents, predicate, session); + } + + public async Task TestDeleteWithPredicateAsync(Expression> predicate, IClientSessionHandle? session = null) { + return await DeleteWithPredicateAsync(predicate, session); + } + + public async Task TestDeleteManyWithPredicateAsync(Expression> predicate, IClientSessionHandle? session = null) { + return await DeleteManyWithPredicateAsync(predicate, session); + } + + // Helper method to access the in-memory collection for validation + public IQueryable GetInMemoryCollection() { + return _inMemoryCollection.AsQueryable(); + } +} + + + + + + +public class TestableCollectionDataProviderTests { + private readonly TestableCollectionDataProvider _dataProvider; + + public TestableCollectionDataProviderTests() { + // Set up a mock logger + var logger = new LoggerFactory().CreateLogger(); + _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 + { new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" }, new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" } }; - // Act - var result = await _dataProvider.TestInsertManyAsync(documents, null); + // Act + var result = await _dataProvider.TestInsertManyAsync(documents, null); - // Assert - Assert.True(result.IsSuccess); - Assert.Equal(2, result.Value?.Count); - } + // Assert + Assert.True(result.IsSuccess); + Assert.Equal(2, result.Value?.Count); + } - [Fact] - public async Task TestUpsertWithPredicateAsync_ShouldInsertNewDocument_WhenNoMatchingDocumentExists() { - // Arrange - var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Test Document" }; + [Fact] + public async Task TestUpsertWithPredicateAsync_ShouldInsertNewDocument_WhenNoMatchingDocumentExists() { + // Arrange + var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Test Document" }; - // Act - var result = await _dataProvider.TestUpsertWithPredicateAsync(document, x => x.Id == document.Id, null); + // Act + var result = await _dataProvider.TestUpsertWithPredicateAsync(document, x => x.Id == document.Id, null); - // Assert - Assert.True(result.IsSuccess); - Assert.Equal(document.Id, result.Value); - } + // Assert + Assert.True(result.IsSuccess); + Assert.Equal(document.Id, result.Value); + } - [Fact] - public async Task TestUpsertWithPredicateAsync_ShouldUpdateExistingDocument_WhenMatchingDocumentExists() { - // Arrange - var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Initial Document" }; - await _dataProvider.TestInsertAsync(document, null); + [Fact] + public async Task TestUpsertWithPredicateAsync_ShouldUpdateExistingDocument_WhenMatchingDocumentExists() { + // Arrange + var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Initial Document" }; + await _dataProvider.TestInsertAsync(document, null); - var updatedDocument = new TestableDocumentDto { Id = document.Id, Name = "Updated Document" }; + var updatedDocument = new TestableDocumentDto { Id = document.Id, Name = "Updated Document" }; - // Act - var result = await _dataProvider.TestUpsertWithPredicateAsync(updatedDocument, x => x.Id == document.Id, null); + // Act + var result = await _dataProvider.TestUpsertWithPredicateAsync(updatedDocument, x => x.Id == document.Id, null); - // Assert - Assert.True(result.IsSuccess); - Assert.Equal(updatedDocument.Id, result.Value); + // Assert + Assert.True(result.IsSuccess); + Assert.Equal(updatedDocument.Id, result.Value); - var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == updatedDocument.Id); - Assert.NotNull(inMemoryCollection); - Assert.Equal("Updated Document", inMemoryCollection.Name); - } + var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == updatedDocument.Id); + Assert.NotNull(inMemoryCollection); + Assert.Equal("Updated Document", inMemoryCollection.Name); + } - [Fact] - public async Task TestUpsertManyWithPredicateAsync_ShouldInsertNewDocuments_WhenNoMatchingDocumentsExist() { - // Arrange - var documents = new List - { + [Fact] + public async Task TestUpsertManyWithPredicateAsync_ShouldInsertNewDocuments_WhenNoMatchingDocumentsExist() { + // Arrange + var documents = new List + { new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" }, new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" } }; - // Act - var result = await _dataProvider.TestUpsertManyWithPredicateAsync(documents, x => documents.Select(d => d.Id).Contains(x.Id), null); + // Act + var result = await _dataProvider.TestUpsertManyWithPredicateAsync(documents, x => documents.Select(d => d.Id).Contains(x.Id), null); - // Assert - Assert.True(result.IsSuccess); - Assert.Equal(2, result.Value?.Count); - } + // Assert + Assert.True(result.IsSuccess); + Assert.Equal(2, result.Value?.Count); + } - [Fact] - public async Task TestUpdateWithPredicateAsync_ShouldUpdateDocument_WhenMatchingDocumentExists() { - // Arrange - var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Initial Document" }; - await _dataProvider.TestInsertAsync(document, null); + [Fact] + public async Task TestUpdateWithPredicateAsync_ShouldUpdateDocument_WhenMatchingDocumentExists() { + // Arrange + var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Initial Document" }; + await _dataProvider.TestInsertAsync(document, null); - var updatedDocument = new TestableDocumentDto { Id = document.Id, Name = "Updated Document" }; + var updatedDocument = new TestableDocumentDto { Id = document.Id, Name = "Updated Document" }; - // Act - var result = await _dataProvider.TestUpdateWithPredicateAsync(updatedDocument, x => x.Id == document.Id, null); + // Act + var result = await _dataProvider.TestUpdateWithPredicateAsync(updatedDocument, x => x.Id == document.Id, null); - // Assert - Assert.True(result.IsSuccess); - Assert.Equal(updatedDocument.Id, result.Value); + // Assert + Assert.True(result.IsSuccess); + Assert.Equal(updatedDocument.Id, result.Value); - var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == updatedDocument.Id); - Assert.NotNull(inMemoryCollection); - Assert.Equal("Updated Document", inMemoryCollection.Name); - } + var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == updatedDocument.Id); + Assert.NotNull(inMemoryCollection); + Assert.Equal("Updated Document", inMemoryCollection.Name); + } - [Fact] - public async Task TestUpdateManyWithPredicateAsync_ShouldUpdateDocuments_WhenMatchingDocumentsExist() { - // Arrange - var documents = new List - { + [Fact] + public async Task TestUpdateManyWithPredicateAsync_ShouldUpdateDocuments_WhenMatchingDocumentsExist() { + // Arrange + var documents = new List + { new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" }, new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" } }; - await _dataProvider.TestInsertManyAsync(documents, null); + await _dataProvider.TestInsertManyAsync(documents, null); - var updatedDocuments = new List - { + var updatedDocuments = new List + { new TestableDocumentDto { Id = documents[0].Id, Name = "Updated Document 1" }, new TestableDocumentDto { Id = documents[1].Id, Name = "Updated Document 2" } }; - // Act - var result = await _dataProvider.TestUpdateManyWithPredicateAsync(updatedDocuments, x => updatedDocuments.Select(d => d.Id).Contains(x.Id), null); + // Act + var result = await _dataProvider.TestUpdateManyWithPredicateAsync(updatedDocuments, x => updatedDocuments.Select(d => d.Id).Contains(x.Id), null); - // Assert - Assert.True(result.IsSuccess); - Assert.Equal(2, result.Value?.Count); + // Assert + Assert.True(result.IsSuccess); + Assert.Equal(2, result.Value?.Count); - var inMemoryCollection = _dataProvider.GetInMemoryCollection().ToList(); - Assert.Equal("Updated Document 1", inMemoryCollection[0].Name); - Assert.Equal("Updated Document 2", inMemoryCollection[1].Name); - } - - [Fact] - public async Task TestDeleteWithPredicateAsync_ShouldDeleteDocument_WhenMatchingDocumentExists() { - // Arrange - var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Test Document" }; - await _dataProvider.TestInsertAsync(document, null); - - // Act - var result = await _dataProvider.TestDeleteWithPredicateAsync(x => x.Id == document.Id, null); - - // Assert - Assert.True(result.IsSuccess); - - var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == document.Id); - Assert.Null(inMemoryCollection); - } - - [Fact] - public async Task TestDeleteManyWithPredicateAsync_ShouldDeleteDocuments_WhenMatchingDocumentsExist() { - // Arrange - var documents = new List - { - 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 - { - new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 1" }, - new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Document 2" } - }; - - // Use 'await' to asynchronously wait for the operation - await _dataProvider.TestInsertManyAsync(documents, null); - - // Act - var queryResult = _dataProvider.GetInMemoryCollection().ToList(); - - // Assert - Assert.Equal(2, queryResult.Count); - Assert.Contains(queryResult, doc => doc.Name == "Document 1"); - Assert.Contains(queryResult, doc => doc.Name == "Document 2"); - } + var inMemoryCollection = _dataProvider.GetInMemoryCollection().ToList(); + Assert.Equal("Updated Document 1", inMemoryCollection[0].Name); + Assert.Equal("Updated Document 2", inMemoryCollection[1].Name); } + [Fact] + public async Task TestDeleteWithPredicateAsync_ShouldDeleteDocument_WhenMatchingDocumentExists() { + // Arrange + var document = new TestableDocumentDto { Id = CombGuidGenerator.CreateCombGuid(), Name = "Test Document" }; + await _dataProvider.TestInsertAsync(document, null); + // Act + var result = await _dataProvider.TestDeleteWithPredicateAsync(x => x.Id == document.Id, null); + // Assert + Assert.True(result.IsSuccess); + var inMemoryCollection = _dataProvider.GetInMemoryCollection().FirstOrDefault(x => x.Id == document.Id); + Assert.Null(inMemoryCollection); + } -} \ No newline at end of file + [Fact] + public async Task TestDeleteManyWithPredicateAsync_ShouldDeleteDocuments_WhenMatchingDocumentsExist() { + // Arrange + var documents = new List + { + 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 + { + 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"); + } +} diff --git a/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoAsyncCursorMock.cs b/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoAsyncCursorMock.cs index c5a8bff..94aaefe 100644 --- a/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoAsyncCursorMock.cs +++ b/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoAsyncCursorMock.cs @@ -1,20 +1,20 @@ using MongoDB.Driver; -namespace MaksIT.MongoDB.Linq.Tests.Mock { - internal class MongoAsyncCursorMock(List documents) : IAsyncCursor { - public IEnumerable Current => documents; +namespace MaksIT.MongoDB.Linq.Tests.Mock; +internal class MongoAsyncCursorMock(List documents) : IAsyncCursor { - public bool MoveNext(CancellationToken cancellationToken = default) { - return false; // Only one batch of data - } + public IEnumerable Current => documents; - public Task MoveNextAsync(CancellationToken cancellationToken = default) { - return Task.FromResult(false); - } + public bool MoveNext(CancellationToken cancellationToken = default) { + return false; // Only one batch of data + } - public void Dispose() { + public Task MoveNextAsync(CancellationToken cancellationToken = default) { + return Task.FromResult(false); + } + + public void Dispose() { - } } } diff --git a/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoClientMock.cs b/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoClientMock.cs index ab6b296..7cc77de 100644 --- a/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoClientMock.cs +++ b/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoClientMock.cs @@ -2,162 +2,161 @@ using MongoDB.Driver; using MongoDB.Driver.Core.Clusters; -namespace MaksIT.MongoDB.Linq.Tests.Mock { - internal class MongoClientMock : IMongoClient { +namespace MaksIT.MongoDB.Linq.Tests.Mock; +internal class MongoClientMock : IMongoClient { #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. - public IMongoDatabase GetDatabase(string name, MongoDatabaseSettings settings = null) { - return new MongoDatabaseMock(); - } + public IMongoDatabase GetDatabase(string name, MongoDatabaseSettings settings = null) { + return new MongoDatabaseMock(); + } - public IClientSessionHandle StartSession(ClientSessionOptions options = null, CancellationToken cancellationToken = default) { - return new MongoSessionMock(); - } + public IClientSessionHandle StartSession(ClientSessionOptions options = null, CancellationToken cancellationToken = default) { + return new MongoSessionMock(); + } - public Task StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default) { - return Task.FromResult((IClientSessionHandle)new MongoSessionMock()); - } + public Task StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default) { + return Task.FromResult((IClientSessionHandle)new MongoSessionMock()); + } - #region not implemented + #region not implemented - public ICluster Cluster => throw new NotImplementedException(); + public ICluster Cluster => throw new NotImplementedException(); - public MongoClientSettings Settings => throw new NotImplementedException(); + public MongoClientSettings Settings => throw new NotImplementedException(); - public void DropDatabase(string name, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void DropDatabase(string name, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void DropDatabase(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void DropDatabase(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task DropDatabaseAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task DropDatabaseAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor ListDatabaseNames(CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor ListDatabaseNames(CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor ListDatabaseNames(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor ListDatabaseNames(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor ListDatabaseNames(IClientSessionHandle session, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor ListDatabaseNames(IClientSessionHandle session, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor ListDatabaseNames(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor ListDatabaseNames(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> ListDatabaseNamesAsync(CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> ListDatabaseNamesAsync(CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> ListDatabaseNamesAsync(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> ListDatabaseNamesAsync(ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> ListDatabaseNamesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> ListDatabaseNamesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> ListDatabaseNamesAsync(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> ListDatabaseNamesAsync(IClientSessionHandle session, ListDatabaseNamesOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor ListDatabases(CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor ListDatabases(CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor ListDatabases(ListDatabasesOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor ListDatabases(ListDatabasesOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor ListDatabases(IClientSessionHandle session, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor ListDatabases(IClientSessionHandle session, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor ListDatabases(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor ListDatabases(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> ListDatabasesAsync(CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> ListDatabasesAsync(CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> ListDatabasesAsync(ListDatabasesOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> ListDatabasesAsync(ListDatabasesOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> ListDatabasesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> ListDatabasesAsync(IClientSessionHandle session, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> ListDatabasesAsync(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> ListDatabasesAsync(IClientSessionHandle session, ListDatabasesOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IChangeStreamCursor Watch(PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IChangeStreamCursor Watch(PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IChangeStreamCursor Watch(IClientSessionHandle session, PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IChangeStreamCursor Watch(IClientSessionHandle session, PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> WatchAsync(PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> WatchAsync(PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> WatchAsync(IClientSessionHandle session, PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> WatchAsync(IClientSessionHandle session, PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IMongoClient WithReadConcern(ReadConcern readConcern) { - throw new NotImplementedException(); - } + public IMongoClient WithReadConcern(ReadConcern readConcern) { + throw new NotImplementedException(); + } - public IMongoClient WithReadPreference(ReadPreference readPreference) { - throw new NotImplementedException(); - } + public IMongoClient WithReadPreference(ReadPreference readPreference) { + throw new NotImplementedException(); + } - public IMongoClient WithWriteConcern(WriteConcern writeConcern) { - throw new NotImplementedException(); - } + public IMongoClient WithWriteConcern(WriteConcern writeConcern) { + throw new NotImplementedException(); + } - public ClientBulkWriteResult BulkWrite(IReadOnlyList models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public ClientBulkWriteResult BulkWrite(IReadOnlyList models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public ClientBulkWriteResult BulkWrite(IClientSessionHandle session, IReadOnlyList models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public ClientBulkWriteResult BulkWrite(IClientSessionHandle session, IReadOnlyList models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task BulkWriteAsync(IReadOnlyList models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task BulkWriteAsync(IReadOnlyList models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task BulkWriteAsync(IClientSessionHandle session, IReadOnlyList models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task BulkWriteAsync(IClientSessionHandle session, IReadOnlyList models, ClientBulkWriteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void Dispose() { - throw new NotImplementedException(); - } + public void Dispose() { + throw new NotImplementedException(); + } - #endregion + #endregion #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. - } } diff --git a/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoCollectionMock.cs b/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoCollectionMock.cs index b9406f9..b79b3ab 100644 --- a/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoCollectionMock.cs +++ b/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoCollectionMock.cs @@ -2,408 +2,409 @@ using MongoDB.Driver; using MongoDB.Driver.Search; -namespace MaksIT.MongoDB.Linq.Tests.Mock { - internal class MongoCollectionMock : IMongoCollection { +namespace MaksIT.MongoDB.Linq.Tests.Mock; + +internal class MongoCollectionMock : IMongoCollection { #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning disable CS0618 // Type or member is obsolete - #region not implemented - public CollectionNamespace CollectionNamespace => throw new NotImplementedException(); + #region not implemented + public CollectionNamespace CollectionNamespace => throw new NotImplementedException(); - public IMongoDatabase Database => throw new NotImplementedException(); + public IMongoDatabase Database => throw new NotImplementedException(); - public global::MongoDB.Bson.Serialization.IBsonSerializer DocumentSerializer => throw new NotImplementedException(); + public global::MongoDB.Bson.Serialization.IBsonSerializer DocumentSerializer => throw new NotImplementedException(); - public IMongoIndexManager Indexes => throw new NotImplementedException(); + public IMongoIndexManager 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 Aggregate(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor Aggregate(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor Aggregate(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor Aggregate(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> AggregateAsync(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> AggregateAsync(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> AggregateAsync(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> AggregateAsync(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void AggregateToCollection(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void AggregateToCollection(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void AggregateToCollection(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void AggregateToCollection(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task AggregateToCollectionAsync(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task AggregateToCollectionAsync(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task AggregateToCollectionAsync(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task AggregateToCollectionAsync(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public BulkWriteResult BulkWrite(IEnumerable> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public BulkWriteResult BulkWrite(IEnumerable> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public BulkWriteResult BulkWrite(IClientSessionHandle session, IEnumerable> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public BulkWriteResult BulkWrite(IClientSessionHandle session, IEnumerable> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> BulkWriteAsync(IEnumerable> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> BulkWriteAsync(IEnumerable> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> BulkWriteAsync(IClientSessionHandle session, IEnumerable> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> BulkWriteAsync(IClientSessionHandle session, IEnumerable> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public long Count(FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public long Count(FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public long Count(IClientSessionHandle session, FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public long Count(IClientSessionHandle session, FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task CountAsync(FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task CountAsync(FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task CountAsync(IClientSessionHandle session, FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task CountAsync(IClientSessionHandle session, FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public long CountDocuments(FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public long CountDocuments(FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public long CountDocuments(IClientSessionHandle session, FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public long CountDocuments(IClientSessionHandle session, FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task CountDocumentsAsync(FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task CountDocumentsAsync(FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task CountDocumentsAsync(IClientSessionHandle session, FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task CountDocumentsAsync(IClientSessionHandle session, FilterDefinition filter, CountOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public DeleteResult DeleteMany(FilterDefinition filter, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public DeleteResult DeleteMany(FilterDefinition filter, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public DeleteResult DeleteMany(FilterDefinition filter, DeleteOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public DeleteResult DeleteMany(FilterDefinition filter, DeleteOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public DeleteResult DeleteMany(IClientSessionHandle session, FilterDefinition filter, DeleteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public DeleteResult DeleteMany(IClientSessionHandle session, FilterDefinition filter, DeleteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task DeleteManyAsync(FilterDefinition filter, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task DeleteManyAsync(FilterDefinition filter, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task DeleteManyAsync(FilterDefinition filter, DeleteOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task DeleteManyAsync(FilterDefinition filter, DeleteOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task DeleteManyAsync(IClientSessionHandle session, FilterDefinition filter, DeleteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task DeleteManyAsync(IClientSessionHandle session, FilterDefinition filter, DeleteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public DeleteResult DeleteOne(FilterDefinition filter, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public DeleteResult DeleteOne(FilterDefinition filter, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public DeleteResult DeleteOne(FilterDefinition filter, DeleteOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public DeleteResult DeleteOne(FilterDefinition filter, DeleteOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public DeleteResult DeleteOne(IClientSessionHandle session, FilterDefinition filter, DeleteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public DeleteResult DeleteOne(IClientSessionHandle session, FilterDefinition filter, DeleteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task DeleteOneAsync(FilterDefinition filter, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task DeleteOneAsync(FilterDefinition filter, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task DeleteOneAsync(FilterDefinition filter, DeleteOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task DeleteOneAsync(FilterDefinition filter, DeleteOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task DeleteOneAsync(IClientSessionHandle session, FilterDefinition filter, DeleteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task DeleteOneAsync(IClientSessionHandle session, FilterDefinition filter, DeleteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor Distinct(FieldDefinition field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor Distinct(FieldDefinition field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor Distinct(IClientSessionHandle session, FieldDefinition field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor Distinct(IClientSessionHandle session, FieldDefinition field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> DistinctAsync(FieldDefinition field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> DistinctAsync(FieldDefinition field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> DistinctAsync(IClientSessionHandle session, FieldDefinition field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> DistinctAsync(IClientSessionHandle session, FieldDefinition field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor DistinctMany(FieldDefinition> field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor DistinctMany(FieldDefinition> field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor DistinctMany(IClientSessionHandle session, FieldDefinition> field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor DistinctMany(IClientSessionHandle session, FieldDefinition> field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> DistinctManyAsync(FieldDefinition> field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> DistinctManyAsync(FieldDefinition> field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> DistinctManyAsync(IClientSessionHandle session, FieldDefinition> field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> DistinctManyAsync(IClientSessionHandle session, FieldDefinition> field, FilterDefinition filter, DistinctOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public long EstimatedDocumentCount(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public long EstimatedDocumentCount(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task EstimatedDocumentCountAsync(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task EstimatedDocumentCountAsync(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> FindAsync(FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> FindAsync(FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> FindAsync(IClientSessionHandle session, FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> FindAsync(IClientSessionHandle session, FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public TProjection FindOneAndDelete(FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public TProjection FindOneAndDelete(FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public TProjection FindOneAndDelete(IClientSessionHandle session, FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public TProjection FindOneAndDelete(IClientSessionHandle session, FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task FindOneAndDeleteAsync(FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task FindOneAndDeleteAsync(FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task FindOneAndDeleteAsync(IClientSessionHandle session, FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task FindOneAndDeleteAsync(IClientSessionHandle session, FilterDefinition filter, FindOneAndDeleteOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public TProjection FindOneAndReplace(FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public TProjection FindOneAndReplace(FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public TProjection FindOneAndReplace(IClientSessionHandle session, FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public TProjection FindOneAndReplace(IClientSessionHandle session, FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task FindOneAndReplaceAsync(FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task FindOneAndReplaceAsync(FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task FindOneAndReplaceAsync(IClientSessionHandle session, FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task FindOneAndReplaceAsync(IClientSessionHandle session, FilterDefinition filter, TDocument replacement, FindOneAndReplaceOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public TProjection FindOneAndUpdate(FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public TProjection FindOneAndUpdate(FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public TProjection FindOneAndUpdate(IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public TProjection FindOneAndUpdate(IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task FindOneAndUpdateAsync(FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task FindOneAndUpdateAsync(FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task FindOneAndUpdateAsync(IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task FindOneAndUpdateAsync(IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, FindOneAndUpdateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor FindSync(FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor FindSync(FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor FindSync(IClientSessionHandle session, FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor FindSync(IClientSessionHandle session, FilterDefinition filter, FindOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void InsertMany(IEnumerable documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void InsertMany(IEnumerable documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void InsertMany(IClientSessionHandle session, IEnumerable documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void InsertMany(IClientSessionHandle session, IEnumerable documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task InsertManyAsync(IEnumerable documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task InsertManyAsync(IEnumerable documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task InsertManyAsync(IClientSessionHandle session, IEnumerable documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task InsertManyAsync(IClientSessionHandle session, IEnumerable documents, InsertManyOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void InsertOne(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void InsertOne(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void InsertOne(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void InsertOne(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task InsertOneAsync(TDocument document, CancellationToken _cancellationToken) { - throw new NotImplementedException(); - } + public Task InsertOneAsync(TDocument document, CancellationToken _cancellationToken) { + throw new NotImplementedException(); + } - public Task InsertOneAsync(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task InsertOneAsync(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task InsertOneAsync(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task InsertOneAsync(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor MapReduce(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor MapReduce(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor MapReduce(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor MapReduce(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> MapReduceAsync(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> MapReduceAsync(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> MapReduceAsync(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> MapReduceAsync(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IFilteredMongoCollection OfType() where TDerivedDocument : TDocument { - throw new NotImplementedException(); - } + public IFilteredMongoCollection OfType() where TDerivedDocument : TDocument { + throw new NotImplementedException(); + } - public ReplaceOneResult ReplaceOne(FilterDefinition filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public ReplaceOneResult ReplaceOne(FilterDefinition filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public ReplaceOneResult ReplaceOne(FilterDefinition filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public ReplaceOneResult ReplaceOne(FilterDefinition filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task ReplaceOneAsync(FilterDefinition filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task ReplaceOneAsync(FilterDefinition filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task ReplaceOneAsync(FilterDefinition filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task ReplaceOneAsync(FilterDefinition filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task ReplaceOneAsync(IClientSessionHandle session, FilterDefinition filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task ReplaceOneAsync(IClientSessionHandle session, FilterDefinition filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task ReplaceOneAsync(IClientSessionHandle session, FilterDefinition filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task ReplaceOneAsync(IClientSessionHandle session, FilterDefinition filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public UpdateResult UpdateMany(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public UpdateResult UpdateMany(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public UpdateResult UpdateMany(IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public UpdateResult UpdateMany(IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task UpdateManyAsync(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task UpdateManyAsync(IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task UpdateManyAsync(IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public UpdateResult UpdateOne(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public UpdateResult UpdateOne(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public UpdateResult UpdateOne(IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public UpdateResult UpdateOne(IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task UpdateOneAsync(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task UpdateOneAsync(FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task UpdateOneAsync(IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task UpdateOneAsync(IClientSessionHandle session, FilterDefinition filter, UpdateDefinition update, UpdateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IChangeStreamCursor Watch(PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IChangeStreamCursor Watch(PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IChangeStreamCursor Watch(IClientSessionHandle session, PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IChangeStreamCursor Watch(IClientSessionHandle session, PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> WatchAsync(PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> WatchAsync(PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> WatchAsync(IClientSessionHandle session, PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> WatchAsync(IClientSessionHandle session, PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IMongoCollection WithReadConcern(ReadConcern readConcern) { - throw new NotImplementedException(); - } + public IMongoCollection WithReadConcern(ReadConcern readConcern) { + throw new NotImplementedException(); + } - public IMongoCollection WithReadPreference(ReadPreference readPreference) { - throw new NotImplementedException(); - } + public IMongoCollection WithReadPreference(ReadPreference readPreference) { + throw new NotImplementedException(); + } - public IMongoCollection WithWriteConcern(WriteConcern writeConcern) { - throw new NotImplementedException(); - } + public IMongoCollection WithWriteConcern(WriteConcern writeConcern) { + throw new NotImplementedException(); + } - #endregion + #endregion #pragma warning restore CS0618 // Type or member is obsolete #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. - } } + diff --git a/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoDatabaseMock.cs b/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoDatabaseMock.cs index 464d5f5..3990fc9 100644 --- a/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoDatabaseMock.cs +++ b/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoDatabaseMock.cs @@ -1,221 +1,222 @@ using MongoDB.Bson; using MongoDB.Driver; -namespace MaksIT.MongoDB.Linq.Tests.Mock { - internal class MongoDatabaseMock : IMongoDatabase { + +namespace MaksIT.MongoDB.Linq.Tests.Mock; + +internal class MongoDatabaseMock : IMongoDatabase { #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. - public IAsyncCursor ListCollectionNames(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) { - return new MongoAsyncCursorMock(new List() { "TestCollection" }); - } + public IAsyncCursor ListCollectionNames(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) { + return new MongoAsyncCursorMock(new List() { "TestCollection" }); + } - public void CreateCollection(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) { - return; - } + public void CreateCollection(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) { + return; + } - public IMongoCollection GetCollection(string name, MongoCollectionSettings settings = null) { - return new MongoCollectionMock(); - } + public IMongoCollection GetCollection(string name, MongoCollectionSettings settings = null) { + return new MongoCollectionMock(); + } - #region not implemented + #region not implemented - public IMongoCollection this[string name] => throw new NotImplementedException(); + public IMongoCollection 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 Aggregate(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor Aggregate(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor Aggregate(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor Aggregate(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> AggregateAsync(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> AggregateAsync(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> AggregateAsync(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> AggregateAsync(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void AggregateToCollection(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void AggregateToCollection(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void AggregateToCollection(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void AggregateToCollection(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task AggregateToCollectionAsync(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task AggregateToCollectionAsync(PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task AggregateToCollectionAsync(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task AggregateToCollectionAsync(IClientSessionHandle session, PipelineDefinition pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void CreateCollection(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void CreateCollection(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task CreateCollectionAsync(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task CreateCollectionAsync(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task CreateCollectionAsync(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task CreateCollectionAsync(IClientSessionHandle session, string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void CreateView(string viewName, string viewOn, PipelineDefinition pipeline, CreateViewOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void CreateView(string viewName, string viewOn, PipelineDefinition pipeline, CreateViewOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void CreateView(IClientSessionHandle session, string viewName, string viewOn, PipelineDefinition pipeline, CreateViewOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void CreateView(IClientSessionHandle session, string viewName, string viewOn, PipelineDefinition pipeline, CreateViewOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task CreateViewAsync(string viewName, string viewOn, PipelineDefinition pipeline, CreateViewOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task CreateViewAsync(string viewName, string viewOn, PipelineDefinition pipeline, CreateViewOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task CreateViewAsync(IClientSessionHandle session, string viewName, string viewOn, PipelineDefinition pipeline, CreateViewOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task CreateViewAsync(IClientSessionHandle session, string viewName, string viewOn, PipelineDefinition pipeline, CreateViewOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void DropCollection(string name, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void DropCollection(string name, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void DropCollection(string name, DropCollectionOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void DropCollection(string name, DropCollectionOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void DropCollection(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void DropCollection(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void DropCollection(IClientSessionHandle session, string name, DropCollectionOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void DropCollection(IClientSessionHandle session, string name, DropCollectionOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task DropCollectionAsync(string name, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task DropCollectionAsync(string name, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task DropCollectionAsync(string name, DropCollectionOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task DropCollectionAsync(string name, DropCollectionOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task DropCollectionAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task DropCollectionAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task DropCollectionAsync(IClientSessionHandle session, string name, DropCollectionOptions options, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task DropCollectionAsync(IClientSessionHandle session, string name, DropCollectionOptions options, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor ListCollectionNames(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor ListCollectionNames(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> ListCollectionNamesAsync(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> ListCollectionNamesAsync(ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> ListCollectionNamesAsync(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> ListCollectionNamesAsync(IClientSessionHandle session, ListCollectionNamesOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor ListCollections(ListCollectionsOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor ListCollections(ListCollectionsOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IAsyncCursor ListCollections(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IAsyncCursor ListCollections(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> ListCollectionsAsync(ListCollectionsOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> ListCollectionsAsync(ListCollectionsOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> ListCollectionsAsync(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> ListCollectionsAsync(IClientSessionHandle session, ListCollectionsOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void RenameCollection(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void RenameCollection(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public void RenameCollection(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public void RenameCollection(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task RenameCollectionAsync(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task RenameCollectionAsync(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task RenameCollectionAsync(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task RenameCollectionAsync(IClientSessionHandle session, string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public TResult RunCommand(Command command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public TResult RunCommand(Command command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public TResult RunCommand(IClientSessionHandle session, Command command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public TResult RunCommand(IClientSessionHandle session, Command command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task RunCommandAsync(Command command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task RunCommandAsync(Command command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task RunCommandAsync(IClientSessionHandle session, Command command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task RunCommandAsync(IClientSessionHandle session, Command command, ReadPreference readPreference = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IChangeStreamCursor Watch(PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IChangeStreamCursor Watch(PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IChangeStreamCursor Watch(IClientSessionHandle session, PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public IChangeStreamCursor Watch(IClientSessionHandle session, PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> WatchAsync(PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> WatchAsync(PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task> WatchAsync(IClientSessionHandle session, PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task> WatchAsync(IClientSessionHandle session, PipelineDefinition, TResult> pipeline, ChangeStreamOptions options = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public IMongoDatabase WithReadConcern(ReadConcern readConcern) { - throw new NotImplementedException(); - } + public IMongoDatabase WithReadConcern(ReadConcern readConcern) { + throw new NotImplementedException(); + } - public IMongoDatabase WithReadPreference(ReadPreference readPreference) { - throw new NotImplementedException(); - } + public IMongoDatabase WithReadPreference(ReadPreference readPreference) { + throw new NotImplementedException(); + } - public IMongoDatabase WithWriteConcern(WriteConcern writeConcern) { - throw new NotImplementedException(); - } + public IMongoDatabase WithWriteConcern(WriteConcern writeConcern) { + throw new NotImplementedException(); + } - #endregion + #endregion #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. - } } diff --git a/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoSessionMock.cs b/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoSessionMock.cs index 1d4a023..96d1829 100644 --- a/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoSessionMock.cs +++ b/src/MaksIT.MongoDB.Linq.Tests/Mock/MongoSessionMock.cs @@ -3,91 +3,92 @@ using MongoDB.Driver; using MongoDB.Driver.Core.Bindings; using MongoDB.Driver.Core.Clusters; -namespace MaksIT.MongoDB.Linq.Tests { - internal class MongoSessionMock : IClientSessionHandle { + +namespace MaksIT.MongoDB.Linq.Tests; + +internal class MongoSessionMock : IClientSessionHandle { #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. - public bool IsInTransaction { get; private set; } = false; + public bool IsInTransaction { get; private set; } = false; - public void StartTransaction(TransactionOptions transactionOptions = null) { - IsInTransaction = true; - } + public void StartTransaction(TransactionOptions transactionOptions = null) { + IsInTransaction = true; + } - public Task StartTransactionAsync(TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) { - IsInTransaction = true; - return Task.CompletedTask; - } + public Task StartTransactionAsync(TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) { + IsInTransaction = true; + return Task.CompletedTask; + } - public void AbortTransaction(CancellationToken cancellationToken = default) { - IsInTransaction = false; - } + public void AbortTransaction(CancellationToken cancellationToken = default) { + IsInTransaction = false; + } - public Task AbortTransactionAsync(CancellationToken cancellationToken = default) { - IsInTransaction = false; - return Task.CompletedTask; - } + public Task AbortTransactionAsync(CancellationToken cancellationToken = default) { + IsInTransaction = false; + return Task.CompletedTask; + } - public void CommitTransaction(CancellationToken cancellationToken = default) { - IsInTransaction = false; - } + public void CommitTransaction(CancellationToken cancellationToken = default) { + IsInTransaction = false; + } - public Task CommitTransactionAsync(CancellationToken cancellationToken = default) { - IsInTransaction = false; - return Task.CompletedTask; - } + public Task CommitTransactionAsync(CancellationToken cancellationToken = default) { + IsInTransaction = false; + return Task.CompletedTask; + } - #region not implemented + #region not implemented - public ClientSessionOptions Options => new ClientSessionOptions(); + public ClientSessionOptions Options => new ClientSessionOptions(); - public IMongoClient Client => throw new NotImplementedException(); + public IMongoClient Client => throw new NotImplementedException(); - public ICluster Cluster => throw new NotImplementedException(); + public ICluster Cluster => throw new NotImplementedException(); - public CoreSessionHandle WrappedCoreSession => throw new NotImplementedException(); + public CoreSessionHandle WrappedCoreSession => throw new NotImplementedException(); - public BsonDocument ClusterTime => throw new NotImplementedException(); + public BsonDocument ClusterTime => throw new NotImplementedException(); - public BsonDocument OperationTime => throw new NotImplementedException(); + public BsonDocument OperationTime => throw new NotImplementedException(); - public bool IsImplicit => throw new NotImplementedException(); + public bool IsImplicit => throw new NotImplementedException(); - BsonTimestamp IClientSession.OperationTime => throw new NotImplementedException(); + BsonTimestamp IClientSession.OperationTime => throw new NotImplementedException(); - public IServerSession ServerSession => throw new NotImplementedException(); + public IServerSession ServerSession => throw new NotImplementedException(); - ICoreSessionHandle IClientSession.WrappedCoreSession => throw new NotImplementedException(); + ICoreSessionHandle IClientSession.WrappedCoreSession => throw new NotImplementedException(); - public void Dispose() { - // Simulate disposing of the session - } + public void Dispose() { + // Simulate disposing of the session + } - public IClientSessionHandle Fork() { - throw new NotImplementedException(); - } + public IClientSessionHandle Fork() { + throw new NotImplementedException(); + } - public void AdvanceClusterTime(BsonDocument newClusterTime) { - throw new NotImplementedException(); - } + public void AdvanceClusterTime(BsonDocument newClusterTime) { + throw new NotImplementedException(); + } - public void AdvanceOperationTime(BsonTimestamp newOperationTime) { - throw new NotImplementedException(); - } + public void AdvanceOperationTime(BsonTimestamp newOperationTime) { + throw new NotImplementedException(); + } - public TResult WithTransaction(Func callback, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public TResult WithTransaction(Func callback, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - public Task WithTransactionAsync(Func> callbackAsync, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) { - throw new NotImplementedException(); - } + public Task WithTransactionAsync(Func> callbackAsync, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) { + throw new NotImplementedException(); + } - #endregion + #endregion #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. - } -} \ No newline at end of file +} diff --git a/src/MaksIT.MongoDB.Linq.Tests/MongoSessionManagerTests.cs b/src/MaksIT.MongoDB.Linq.Tests/MongoSessionManagerTests.cs index 54d134e..cb0920f 100644 --- a/src/MaksIT.MongoDB.Linq.Tests/MongoSessionManagerTests.cs +++ b/src/MaksIT.MongoDB.Linq.Tests/MongoSessionManagerTests.cs @@ -3,64 +3,65 @@ using MaksIT.Results; using MaksIT.MongoDB.Linq.Tests.Mock; -namespace MaksIT.MongoDB.Linq.Tests { - public class MongoSessionManagerTests { - private readonly MongoSessionManager _sessionManager; - private readonly ILogger _logger; +namespace MaksIT.MongoDB.Linq.Tests; - public MongoSessionManagerTests() { - _logger = new LoggerFactory().CreateLogger(); - var mockClient = new MongoClientMock(); - _sessionManager = new MongoSessionManager(_logger, mockClient); - } +public class MongoSessionManagerTests { - [Fact] - public void ExecuteInSession_ShouldCommitTransaction_WhenActionSucceeds() { - // Act - var result = _sessionManager.ExecuteInSession(session => { - // Simulate successful operation - return Result.Ok(); - }); + private readonly MongoSessionManager _sessionManager; + private readonly ILogger _logger; - // Assert - Assert.True(result.IsSuccess); - } + public MongoSessionManagerTests() { + _logger = new LoggerFactory().CreateLogger(); + var mockClient = new MongoClientMock(); + _sessionManager = new MongoSessionManager(_logger, mockClient); + } - [Fact] - public void ExecuteInSession_ShouldAbortTransaction_WhenActionFails() { - // Act - var result = _sessionManager.ExecuteInSession(session => { - // Simulate failed operation - return Result.InternalServerError("Simulated failure"); - }); + [Fact] + public void ExecuteInSession_ShouldCommitTransaction_WhenActionSucceeds() { + // Act + var result = _sessionManager.ExecuteInSession(session => { + // Simulate successful operation + return Result.Ok(); + }); - // Assert - Assert.False(result.IsSuccess); - } + // Assert + Assert.True(result.IsSuccess); + } - [Fact] - public async Task ExecuteInSessionAsync_ShouldCommitTransaction_WhenActionSucceeds() { - // Act - var result = await _sessionManager.ExecuteInSessionAsync(async session => { - // Simulate successful operation - return await Task.FromResult(Result.Ok()); - }); + [Fact] + public void ExecuteInSession_ShouldAbortTransaction_WhenActionFails() { + // Act + var result = _sessionManager.ExecuteInSession(session => { + // Simulate failed operation + return Result.InternalServerError("Simulated failure"); + }); - // Assert - Assert.True(result.IsSuccess); - } + // Assert + Assert.False(result.IsSuccess); + } - [Fact] - public async Task ExecuteInSessionAsync_ShouldAbortTransaction_WhenActionFails() { - // Act - var result = await _sessionManager.ExecuteInSessionAsync(async session => { - // Simulate failed operation - return await Task.FromResult(Result.InternalServerError("Simulated failure")); - }); + [Fact] + public async Task ExecuteInSessionAsync_ShouldCommitTransaction_WhenActionSucceeds() { + // Act + var result = await _sessionManager.ExecuteInSessionAsync(async session => { + // Simulate successful operation + return await Task.FromResult(Result.Ok()); + }); - // Assert - Assert.False(result.IsSuccess); - } + // Assert + Assert.True(result.IsSuccess); + } + + [Fact] + public async Task ExecuteInSessionAsync_ShouldAbortTransaction_WhenActionFails() { + // Act + var result = await _sessionManager.ExecuteInSessionAsync(async session => { + // Simulate failed operation + return await Task.FromResult(Result.InternalServerError("Simulated failure")); + }); + + // Assert + Assert.False(result.IsSuccess); } } diff --git a/src/MaksIT.MongoDB.Linq.Tests/Utilities/CombGuidGeneratorTests.cs b/src/MaksIT.MongoDB.Linq.Tests/Utilities/CombGuidGeneratorTests.cs index 82b951e..3be1102 100644 --- a/src/MaksIT.MongoDB.Linq.Tests/Utilities/CombGuidGeneratorTests.cs +++ b/src/MaksIT.MongoDB.Linq.Tests/Utilities/CombGuidGeneratorTests.cs @@ -1,81 +1,82 @@ using MaksIT.MongoDB.Linq.Utilities; -namespace MaksIT.MongoDB.Linq.Tests.Utilities { - public class CombGuidGeneratorTests { - [Fact] - public void CreateCombGuid_WithCurrentTimestamp_ShouldGenerateGuid() { - // Act - Guid combGuid = CombGuidGenerator.CreateCombGuid(); - // Assert - Assert.NotEqual(Guid.Empty, combGuid); - } +namespace MaksIT.MongoDB.Linq.Tests.Utilities; - [Fact] - public void CreateCombGuid_WithSpecificGuidAndCurrentTimestamp_ShouldEmbedTimestamp() { - // Arrange - Guid inputGuid = Guid.NewGuid(); +public class CombGuidGeneratorTests { + [Fact] + public void CreateCombGuid_WithCurrentTimestamp_ShouldGenerateGuid() { + // Act + Guid combGuid = CombGuidGenerator.CreateCombGuid(); - // Act - Guid combGuid = CombGuidGenerator.CreateCombGuid(inputGuid); - DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid); + // Assert + Assert.NotEqual(Guid.Empty, combGuid); + } - // Assert - Assert.NotEqual(Guid.Empty, combGuid); - Assert.True(extractedTimestamp <= DateTime.UtcNow, "The extracted timestamp should not be in the future."); - Assert.True(extractedTimestamp >= DateTime.UtcNow.AddSeconds(-5), "The extracted timestamp should be recent."); - } + [Fact] + public void CreateCombGuid_WithSpecificGuidAndCurrentTimestamp_ShouldEmbedTimestamp() { + // Arrange + Guid inputGuid = Guid.NewGuid(); - [Fact] - public void CreateCombGuid_WithSpecificTimestamp_ShouldGenerateGuidWithEmbeddedTimestamp() { - // Arrange - DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc); + // Act + Guid combGuid = CombGuidGenerator.CreateCombGuid(inputGuid); + DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid); - // Act - Guid combGuid = CombGuidGenerator.CreateCombGuid(timestamp); - DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid); + // Assert + Assert.NotEqual(Guid.Empty, combGuid); + Assert.True(extractedTimestamp <= DateTime.UtcNow, "The extracted timestamp should not be in the future."); + Assert.True(extractedTimestamp >= DateTime.UtcNow.AddSeconds(-5), "The extracted timestamp should be recent."); + } - // Assert - Assert.NotEqual(Guid.Empty, combGuid); - Assert.Equal(timestamp, extractedTimestamp); - } + [Fact] + public void CreateCombGuid_WithSpecificTimestamp_ShouldGenerateGuidWithEmbeddedTimestamp() { + // Arrange + DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc); - [Fact] - public void CreateCombGuid_WithGuidAndSpecificTimestamp_ShouldGenerateGuidWithEmbeddedTimestamp() { - // Arrange - Guid inputGuid = Guid.NewGuid(); - DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc); + // Act + Guid combGuid = CombGuidGenerator.CreateCombGuid(timestamp); + DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid); - // Act - Guid combGuid = CombGuidGenerator.CreateCombGuidWithTimestamp(inputGuid, timestamp); - DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid); + // Assert + Assert.NotEqual(Guid.Empty, combGuid); + Assert.Equal(timestamp, extractedTimestamp); + } - // Assert - Assert.NotEqual(Guid.Empty, combGuid); - Assert.Equal(timestamp, extractedTimestamp); - } + [Fact] + public void CreateCombGuid_WithGuidAndSpecificTimestamp_ShouldGenerateGuidWithEmbeddedTimestamp() { + // Arrange + Guid inputGuid = Guid.NewGuid(); + DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc); - [Fact] - public void ExtractTimestamp_ShouldExtractCorrectTimestampFromCombGuid() { - // Arrange - DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc); - Guid combGuid = CombGuidGenerator.CreateCombGuid(timestamp); + // Act + Guid combGuid = CombGuidGenerator.CreateCombGuidWithTimestamp(inputGuid, timestamp); + DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid); - // Act - DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid); + // Assert + Assert.NotEqual(Guid.Empty, combGuid); + Assert.Equal(timestamp, extractedTimestamp); + } - // Assert - Assert.Equal(timestamp, extractedTimestamp); - } + [Fact] + public void ExtractTimestamp_ShouldExtractCorrectTimestampFromCombGuid() { + // Arrange + DateTime timestamp = new DateTime(2024, 8, 30, 12, 0, 0, DateTimeKind.Utc); + Guid combGuid = CombGuidGenerator.CreateCombGuid(timestamp); - [Fact] - public void ExtractTimestamp_WithInvalidGuid_ShouldThrowException() { - // Arrange - Guid invalidGuid = Guid.NewGuid(); + // Act + DateTime extractedTimestamp = CombGuidGenerator.ExtractTimestamp(combGuid); - // Act & Assert - var exception = Record.Exception(() => CombGuidGenerator.ExtractTimestamp(invalidGuid)); - Assert.Null(exception); // Adjusted expectation based on behavior of `ExtractTimestamp` with a regular GUID - } + // Assert + Assert.Equal(timestamp, extractedTimestamp); + } + + [Fact] + public void ExtractTimestamp_WithInvalidGuid_ShouldThrowException() { + // Arrange + Guid invalidGuid = Guid.NewGuid(); + + // Act & Assert + var exception = Record.Exception(() => CombGuidGenerator.ExtractTimestamp(invalidGuid)); + Assert.Null(exception); // Adjusted expectation based on behavior of `ExtractTimestamp` with a regular GUID } } diff --git a/src/MaksIT.MongoDB.Linq/Abstractions/BaseCollectionDataProviderBase.cs b/src/MaksIT.MongoDB.Linq/Abstractions/BaseCollectionDataProviderBase.cs index 74d91ad..8017c54 100644 --- a/src/MaksIT.MongoDB.Linq/Abstractions/BaseCollectionDataProviderBase.cs +++ b/src/MaksIT.MongoDB.Linq/Abstractions/BaseCollectionDataProviderBase.cs @@ -7,234 +7,235 @@ using MaksIT.Core.Abstractions.Dto; using MaksIT.Results; -namespace MaksIT.MongoDB.Linq.Abstractions { - public abstract class BaseCollectionDataProviderBase : DataProviderBase - where TDtoDocument : DtoDocumentBase { +namespace MaksIT.MongoDB.Linq.Abstractions; - protected readonly IMongoCollection Collection; - protected readonly string _errorMessage = "MaksIT.MongoDB.Linq - Data provider error"; +public abstract class BaseCollectionDataProviderBase : DataProviderBase + where TDtoDocument : DtoDocumentBase { - protected BaseCollectionDataProviderBase( - ILogger logger, - IMongoClient client, - string databaseName, - string collectionName - ) : base(logger, client, databaseName) { - if (!Database.ListCollectionNames().ToList().Contains(collectionName)) - Database.CreateCollection(collectionName); + protected readonly IMongoCollection Collection; + protected readonly string _errorMessage = "MaksIT.MongoDB.Linq - Data provider error"; - Collection = Database.GetCollection(collectionName); - } + protected BaseCollectionDataProviderBase( + ILogger logger, + IMongoClient client, + string databaseName, + string collectionName + ) : base(logger, client, databaseName) { + if (!Database.ListCollectionNames().ToList().Contains(collectionName)) + Database.CreateCollection(collectionName); - #region Insert - protected virtual async Task> InsertAsync(TDtoDocument document, IClientSessionHandle? session) { - try { - if (session != null) - await Collection.InsertOneAsync(session, document); - else - await Collection.InsertOneAsync(document); - - return Result.Ok(document.Id); - } - catch (Exception ex) { - Logger.LogError(ex, _errorMessage); - return Result.InternalServerError(default(TDtoKey?), _errorMessage); - } - } - #endregion - - #region InsertMany - protected virtual async Task?>> InsertManyAsync(List documents, IClientSessionHandle? session) { - try { - // Check if the documents list is empty - if (documents.Count == 0) { - return Result?>.Ok(new List()); - } - - if (session != null) - await Collection.InsertManyAsync(session, documents); - else - await Collection.InsertManyAsync(documents); - - return Result?>.Ok(documents.Select(x => x.Id).ToList()); - } - catch (Exception ex) { - Logger.LogError(ex, _errorMessage); - return Result?>.InternalServerError(default, _errorMessage); - } - } - #endregion - - #region Get - protected virtual IQueryable GetQuery() => Collection.AsQueryable(); - #endregion - - #region Update - protected virtual async Task> UpdateWithPredicateAsync( - TDtoDocument document, - Expression> predicate, - IClientSessionHandle? session) { - try { - if (session != null) - await Collection.ReplaceOneAsync(session, predicate, document); - else - await Collection.ReplaceOneAsync(predicate, document); - - return Result.Ok(document.Id); - } - catch (Exception ex) { - Logger.LogError(ex, _errorMessage); - return Result.InternalServerError(default(TDtoKey?), _errorMessage); - } - } - #endregion - - #region UpdateMany - protected virtual async Task?>> UpdateManyWithPredicateAsync( - List documents, - Expression> predicate, - IClientSessionHandle? session) { - try { - // Check if the documents list is empty - if (documents.Count == 0) { - return Result?>.Ok(new List()); - } - - // Step 1: Find the documents that already exist based on the predicate - List 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>)(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?>.Ok(updatedIds); - } - catch (Exception ex) { - Logger.LogError(ex, _errorMessage); - return Result?>.InternalServerError(default, _errorMessage); - } - } - #endregion - - #region Upsert - protected virtual async Task> UpsertWithPredicateAsync( - TDtoDocument document, - Expression> 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.Ok(document.Id); - } - catch (Exception ex) { - Logger.LogError(ex, _errorMessage); - return Result.InternalServerError(default(TDtoKey?), _errorMessage); - } - } - #endregion - - #region UpsertMany - protected virtual async Task?>> UpsertManyWithPredicateAsync( - List documents, - Expression> predicate, - IClientSessionHandle? session) { - try { - // Check if the documents list is empty - if (documents.Count == 0) { - return Result?>.Ok(new List()); - } - - // 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?>.Ok(upsertedIds); - } - catch (Exception ex) { - Logger.LogError(ex, _errorMessage); - return Result?>.InternalServerError(default, _errorMessage); - } - } - #endregion - - #region Delete - protected virtual async Task DeleteWithPredicateAsync( - Expression> 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 DeleteManyWithPredicateAsync( - Expression> predicate, - IClientSessionHandle? session) { - try { - if (session != null) - await Collection.DeleteManyAsync(session, predicate); - else - await Collection.DeleteManyAsync(predicate); - - return Result.Ok(); - } - catch (Exception ex) { - Logger.LogError(ex, _errorMessage); - return Result.InternalServerError(_errorMessage); - } - } - #endregion + Collection = Database.GetCollection(collectionName); } + + #region Insert + protected virtual async Task> InsertAsync(TDtoDocument document, IClientSessionHandle? session) { + try { + if (session != null) + await Collection.InsertOneAsync(session, document); + else + await Collection.InsertOneAsync(document); + + return Result.Ok(document.Id); + } + catch (Exception ex) { + Logger.LogError(ex, _errorMessage); + return Result.InternalServerError(default(TDtoKey?), _errorMessage); + } + } + #endregion + + #region InsertMany + protected virtual async Task?>> InsertManyAsync(List documents, IClientSessionHandle? session) { + try { + // Check if the documents list is empty + if (documents.Count == 0) { + return Result?>.Ok(new List()); + } + + if (session != null) + await Collection.InsertManyAsync(session, documents); + else + await Collection.InsertManyAsync(documents); + + return Result?>.Ok(documents.Select(x => x.Id).ToList()); + } + catch (Exception ex) { + Logger.LogError(ex, _errorMessage); + return Result?>.InternalServerError(default, _errorMessage); + } + } + #endregion + + #region Get + protected virtual IQueryable GetQuery() => Collection.AsQueryable(); + #endregion + + #region Update + protected virtual async Task> UpdateWithPredicateAsync( + TDtoDocument document, + Expression> predicate, + IClientSessionHandle? session) { + try { + if (session != null) + await Collection.ReplaceOneAsync(session, predicate, document); + else + await Collection.ReplaceOneAsync(predicate, document); + + return Result.Ok(document.Id); + } + catch (Exception ex) { + Logger.LogError(ex, _errorMessage); + return Result.InternalServerError(default(TDtoKey?), _errorMessage); + } + } + #endregion + + #region UpdateMany + protected virtual async Task?>> UpdateManyWithPredicateAsync( + List documents, + Expression> predicate, + IClientSessionHandle? session) { + try { + // Check if the documents list is empty + if (documents.Count == 0) { + return Result?>.Ok(new List()); + } + + // Step 1: Find the documents that already exist based on the predicate + List 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>)(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?>.Ok(updatedIds); + } + catch (Exception ex) { + Logger.LogError(ex, _errorMessage); + return Result?>.InternalServerError(default, _errorMessage); + } + } + #endregion + + #region Upsert + protected virtual async Task> UpsertWithPredicateAsync( + TDtoDocument document, + Expression> 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.Ok(document.Id); + } + catch (Exception ex) { + Logger.LogError(ex, _errorMessage); + return Result.InternalServerError(default(TDtoKey?), _errorMessage); + } + } + #endregion + + #region UpsertMany + protected virtual async Task?>> UpsertManyWithPredicateAsync( + List documents, + Expression> predicate, + IClientSessionHandle? session) { + try { + // Check if the documents list is empty + if (documents.Count == 0) { + return Result?>.Ok(new List()); + } + + // 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?>.Ok(upsertedIds); + } + catch (Exception ex) { + Logger.LogError(ex, _errorMessage); + return Result?>.InternalServerError(default, _errorMessage); + } + } + #endregion + + #region Delete + protected virtual async Task DeleteWithPredicateAsync( + Expression> 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 DeleteManyWithPredicateAsync( + Expression> 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 } + diff --git a/src/MaksIT.MongoDB.Linq/Abstractions/CollectionDataProviderBase.cs b/src/MaksIT.MongoDB.Linq/Abstractions/CollectionDataProviderBase.cs index a0c6906..458b89c 100644 --- a/src/MaksIT.MongoDB.Linq/Abstractions/CollectionDataProviderBase.cs +++ b/src/MaksIT.MongoDB.Linq/Abstractions/CollectionDataProviderBase.cs @@ -7,120 +7,120 @@ using MongoDB.Driver; using MaksIT.Results; using MaksIT.Core.Abstractions.Dto; -namespace MaksIT.MongoDB.Linq.Abstractions { - public abstract class CollectionDataProviderBase : BaseCollectionDataProviderBase - where TDtoDocument : DtoDocumentBase { +namespace MaksIT.MongoDB.Linq.Abstractions; - protected CollectionDataProviderBase( - ILogger logger, - IMongoClient client, - string databaseName, - string collectionName - ) : base(logger, client, databaseName, collectionName) { } +public abstract class CollectionDataProviderBase : BaseCollectionDataProviderBase + where TDtoDocument : DtoDocumentBase { - #region Insert - public Result Insert(TDtoDocument obj, IClientSessionHandle? session) => - InsertAsync(obj, session).Result; - #endregion + protected CollectionDataProviderBase( + ILogger logger, + IMongoClient client, + string databaseName, + string collectionName + ) : base(logger, client, databaseName, collectionName) { } - #region InsertMany - public Result?> InsertMany(List objList, IClientSessionHandle? session) => - InsertManyAsync(objList, session).Result; - #endregion + #region Insert + public Result Insert(TDtoDocument obj, IClientSessionHandle? session) => + InsertAsync(obj, session).Result; + #endregion - #region Count - protected Result CountWithPredicate(Expression> predicate) => - CountWithPredicate(new List>> { predicate }); + #region InsertMany + public Result?> InsertMany(List objList, IClientSessionHandle? session) => + InsertManyAsync(objList, session).Result; + #endregion - private protected Result CountWithPredicate(List>> predicates) { - try { - var query = GetWithPredicate(predicates); + #region Count + protected Result CountWithPredicate(Expression> predicate) => + CountWithPredicate(new List>> { predicate }); - var result = query.Count(); + private protected Result CountWithPredicate(List>> predicates) { + try { + var query = GetWithPredicate(predicates); - return Result.Ok(result); - } - catch (Exception ex) { - Logger.LogError(ex, _errorMessage); - return Result.InternalServerError(null, _errorMessage); - } + var result = query.Count(); + + return Result.Ok(result); } - #endregion - - #region Get - protected Result?> GetWithPredicate(Expression> predicate, Expression> selector) => - GetWithPredicate(new List>> { predicate }, selector, null, null); - - protected Result?> GetWithPredicate(Expression> predicate, Expression> selector, int? skip, int? limit) => - GetWithPredicate(new List>> { predicate }, selector, skip, limit); - - protected Result?> GetWithPredicate( - List>> predicates, - Expression> 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?>.Ok(result) - : Result?>.NotFound(null); - } - catch (Exception ex) { - Logger.LogError(ex, _errorMessage); - return Result?>.InternalServerError(null, _errorMessage); - } + catch (Exception ex) { + Logger.LogError(ex, _errorMessage); + return Result.InternalServerError(null, _errorMessage); } - - protected IQueryable GetWithPredicate(List>> predicates) { - var query = GetQuery(); - - foreach (var predicate in predicates) - query = query.Where(predicate); - - return query; - } - #endregion - - #region Update - protected Result UpdateWithPredicate(TDtoDocument obj, Expression> predicate, IClientSessionHandle? session) => - UpdateWithPredicateAsync(obj, predicate, session).Result; - #endregion - - #region UpdateMany - public Result?> UpdateManyWithPredicate(Expression> predicate, List objList, IClientSessionHandle? session) => - UpdateManyWithPredicateAsync(objList, predicate, session).Result; - #endregion - - #region Upsert - protected Result UpsertWithPredicate(TDtoDocument obj, Expression> predicate, IClientSessionHandle? session) => - UpsertWithPredicateAsync(obj, predicate, session).Result; - #endregion - - #region UpsertMany - public Result?> UpsertManyWithPredicate(List objList, Expression> predicate, IClientSessionHandle? session) => - UpsertManyWithPredicateAsync(objList, predicate, session).Result; - #endregion - - #region Delete - protected Result DeleteWithPredicate(Expression> predicate, IClientSessionHandle? session) => - DeleteWithPredicateAsync(predicate, session).Result; - #endregion - - #region DeleteMany - protected Result DeleteManyWithPredicate(Expression> predicate, IClientSessionHandle? session) => - DeleteManyWithPredicateAsync(predicate, session).Result; - #endregion } + #endregion + + #region Get + protected Result?> GetWithPredicate(Expression> predicate, Expression> selector) => + GetWithPredicate(new List>> { predicate }, selector, null, null); + + protected Result?> GetWithPredicate(Expression> predicate, Expression> selector, int? skip, int? limit) => + GetWithPredicate(new List>> { predicate }, selector, skip, limit); + + protected Result?> GetWithPredicate( + List>> predicates, + Expression> 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?>.Ok(result) + : Result?>.NotFound(null); + } + catch (Exception ex) { + Logger.LogError(ex, _errorMessage); + return Result?>.InternalServerError(null, _errorMessage); + } + } + + protected IQueryable GetWithPredicate(List>> predicates) { + var query = GetQuery(); + + foreach (var predicate in predicates) + query = query.Where(predicate); + + return query; + } + #endregion + + #region Update + protected Result UpdateWithPredicate(TDtoDocument obj, Expression> predicate, IClientSessionHandle? session) => + UpdateWithPredicateAsync(obj, predicate, session).Result; + #endregion + + #region UpdateMany + public Result?> UpdateManyWithPredicate(Expression> predicate, List objList, IClientSessionHandle? session) => + UpdateManyWithPredicateAsync(objList, predicate, session).Result; + #endregion + + #region Upsert + protected Result UpsertWithPredicate(TDtoDocument obj, Expression> predicate, IClientSessionHandle? session) => + UpsertWithPredicateAsync(obj, predicate, session).Result; + #endregion + + #region UpsertMany + public Result?> UpsertManyWithPredicate(List objList, Expression> predicate, IClientSessionHandle? session) => + UpsertManyWithPredicateAsync(objList, predicate, session).Result; + #endregion + + #region Delete + protected Result DeleteWithPredicate(Expression> predicate, IClientSessionHandle? session) => + DeleteWithPredicateAsync(predicate, session).Result; + #endregion + + #region DeleteMany + protected Result DeleteManyWithPredicate(Expression> predicate, IClientSessionHandle? session) => + DeleteManyWithPredicateAsync(predicate, session).Result; + #endregion } diff --git a/src/MaksIT.MongoDB.Linq/Abstractions/DataProviderBase.cs b/src/MaksIT.MongoDB.Linq/Abstractions/DataProviderBase.cs index 510f521..00d2cee 100644 --- a/src/MaksIT.MongoDB.Linq/Abstractions/DataProviderBase.cs +++ b/src/MaksIT.MongoDB.Linq/Abstractions/DataProviderBase.cs @@ -1,19 +1,20 @@ using Microsoft.Extensions.Logging; using MongoDB.Driver; -namespace MaksIT.MongoDB.Linq.Abstractions { - public abstract class DataProviderBase { - protected readonly ILogger Logger; - protected readonly IMongoDatabase Database; - private readonly IMongoClient _client; - protected DataProviderBase( - ILogger logger, - IMongoClient client, - string databaseName) { - Logger = logger; - _client = client; - Database = _client.GetDatabase(databaseName); - } +namespace MaksIT.MongoDB.Linq.Abstractions; + +public abstract class DataProviderBase { + protected readonly ILogger Logger; + protected readonly IMongoDatabase Database; + private readonly IMongoClient _client; + + protected DataProviderBase( + ILogger logger, + IMongoClient client, + string databaseName) { + Logger = logger; + _client = client; + Database = _client.GetDatabase(databaseName); } } diff --git a/src/MaksIT.MongoDB.Linq/MaksIT.MongoDB.Linq.csproj b/src/MaksIT.MongoDB.Linq/MaksIT.MongoDB.Linq.csproj index aed4c0b..9984afa 100644 --- a/src/MaksIT.MongoDB.Linq/MaksIT.MongoDB.Linq.csproj +++ b/src/MaksIT.MongoDB.Linq/MaksIT.MongoDB.Linq.csproj @@ -4,11 +4,11 @@ net8.0 enable enable - MaksIT.$(MSBuildProjectName.Replace(" ", "_")) + $(MSBuildProjectName.Replace(" ", "_")) MaksIT.MongoDB.Linq - 1.1.1 + 1.1.2 Maksym Sadovnychyy MAKS-IT MaksIT.MongoDB.Linq diff --git a/src/MaksIT.MongoDB.Linq/MongoSession.cs b/src/MaksIT.MongoDB.Linq/MongoSession.cs index 4c19ae2..5a3a283 100644 --- a/src/MaksIT.MongoDB.Linq/MongoSession.cs +++ b/src/MaksIT.MongoDB.Linq/MongoSession.cs @@ -1,5 +1,5 @@ using MongoDB.Driver; -using System; + namespace MaksIT.MongoDB.Linq { public class DisposableMongoSession : IDisposable { diff --git a/src/MaksIT.MongoDB.Linq/Serializers/GuidKeyDictionarySerializer.cs b/src/MaksIT.MongoDB.Linq/Serializers/GuidKeyDictionarySerializer.cs index f446fdf..9df3d64 100644 --- a/src/MaksIT.MongoDB.Linq/Serializers/GuidKeyDictionarySerializer.cs +++ b/src/MaksIT.MongoDB.Linq/Serializers/GuidKeyDictionarySerializer.cs @@ -4,7 +4,7 @@ using MongoDB.Bson.Serialization; using MongoDB.Bson.Serialization.Serializers; -namespace MaksIT.MaksIT.MongoDB.Linq.Serializers; +namespace MaksIT.MongoDB.Linq.Serializers; public class GuidKeyDictionarySerializer : SerializerBase> { public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, Dictionary value) { diff --git a/src/MaksIT.MongoDB.Linq/Utilities/CombGuidGenerator.cs b/src/MaksIT.MongoDB.Linq/Utilities/CombGuidGenerator.cs index c919217..6c4c8d8 100644 --- a/src/MaksIT.MongoDB.Linq/Utilities/CombGuidGenerator.cs +++ b/src/MaksIT.MongoDB.Linq/Utilities/CombGuidGenerator.cs @@ -1,5 +1,4 @@ -using System; -using System.Buffers.Binary; +using System.Buffers.Binary; namespace MaksIT.MongoDB.Linq.Utilities { public static class CombGuidGenerator {