(refactor): review namespaces

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

View File

@ -10,15 +10,15 @@ using MaksIT.MongoDB.Linq.Utilities;
using MaksIT.MongoDB.Linq.Tests.Mock; using MaksIT.MongoDB.Linq.Tests.Mock;
namespace MaksIT.MongoDB.Tests { namespace MaksIT.MongoDB.Tests;
// Sample DTO class for testing // Sample DTO class for testing
public class TestableDocumentDto : DtoDocumentBase<Guid> { public class TestableDocumentDto : DtoDocumentBase<Guid> {
public required string Name { get; set; } public required string Name { get; set; }
} }
// Generalized Testable class to simulate MongoDB operations using an in-memory list // Generalized Testable class to simulate MongoDB operations using an in-memory list
public class TestableCollectionDataProvider : BaseCollectionDataProviderBase<TestableCollectionDataProvider, TestableDocumentDto, Guid> { public class TestableCollectionDataProvider : BaseCollectionDataProviderBase<TestableCollectionDataProvider, TestableDocumentDto, Guid> {
private readonly List<TestableDocumentDto> _inMemoryCollection; private readonly List<TestableDocumentDto> _inMemoryCollection;
public TestableCollectionDataProvider(ILogger<TestableCollectionDataProvider> logger) public TestableCollectionDataProvider(ILogger<TestableCollectionDataProvider> logger)
@ -138,14 +138,14 @@ namespace MaksIT.MongoDB.Tests {
public IQueryable<TestableDocumentDto> GetInMemoryCollection() { public IQueryable<TestableDocumentDto> GetInMemoryCollection() {
return _inMemoryCollection.AsQueryable(); return _inMemoryCollection.AsQueryable();
} }
} }
public class TestableCollectionDataProviderTests { public class TestableCollectionDataProviderTests {
private readonly TestableCollectionDataProvider _dataProvider; private readonly TestableCollectionDataProvider _dataProvider;
public TestableCollectionDataProviderTests() { public TestableCollectionDataProviderTests() {
@ -341,10 +341,4 @@ namespace MaksIT.MongoDB.Tests {
Assert.Contains(queryResult, doc => doc.Name == "Document 1"); Assert.Contains(queryResult, doc => doc.Name == "Document 1");
Assert.Contains(queryResult, doc => doc.Name == "Document 2"); Assert.Contains(queryResult, doc => doc.Name == "Document 2");
} }
}
} }

View File

@ -1,7 +1,8 @@
using MongoDB.Driver; using MongoDB.Driver;
namespace MaksIT.MongoDB.Linq.Tests.Mock {
internal class MongoAsyncCursorMock<T>(List<T> documents) : IAsyncCursor<T> { namespace MaksIT.MongoDB.Linq.Tests.Mock;
internal class MongoAsyncCursorMock<T>(List<T> documents) : IAsyncCursor<T> {
public IEnumerable<T> Current => documents; public IEnumerable<T> Current => documents;
@ -16,5 +17,4 @@ namespace MaksIT.MongoDB.Linq.Tests.Mock {
public void Dispose() { public void Dispose() {
} }
}
} }

View File

@ -2,8 +2,8 @@
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Core.Clusters; using MongoDB.Driver.Core.Clusters;
namespace MaksIT.MongoDB.Linq.Tests.Mock { namespace MaksIT.MongoDB.Linq.Tests.Mock;
internal class MongoClientMock : IMongoClient { internal class MongoClientMock : IMongoClient {
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
@ -159,5 +159,4 @@ namespace MaksIT.MongoDB.Linq.Tests.Mock {
#endregion #endregion
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
} }

View File

@ -2,8 +2,9 @@
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.Driver.Search; using MongoDB.Driver.Search;
namespace MaksIT.MongoDB.Linq.Tests.Mock { namespace MaksIT.MongoDB.Linq.Tests.Mock;
internal class MongoCollectionMock<TDocument> : IMongoCollection<TDocument> {
internal class MongoCollectionMock<TDocument> : IMongoCollection<TDocument> {
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
#pragma warning disable CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete
@ -405,5 +406,5 @@ namespace MaksIT.MongoDB.Linq.Tests.Mock {
#pragma warning restore CS0618 // Type or member is obsolete #pragma warning restore CS0618 // Type or member is obsolete
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
} }

View File

@ -1,8 +1,10 @@
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Driver; using MongoDB.Driver;
namespace MaksIT.MongoDB.Linq.Tests.Mock {
internal class MongoDatabaseMock : IMongoDatabase { namespace MaksIT.MongoDB.Linq.Tests.Mock;
internal class MongoDatabaseMock : IMongoDatabase {
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
@ -217,5 +219,4 @@ namespace MaksIT.MongoDB.Linq.Tests.Mock {
#endregion #endregion
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
} }

View File

@ -3,8 +3,10 @@ using MongoDB.Driver;
using MongoDB.Driver.Core.Bindings; using MongoDB.Driver.Core.Bindings;
using MongoDB.Driver.Core.Clusters; using MongoDB.Driver.Core.Clusters;
namespace MaksIT.MongoDB.Linq.Tests {
internal class MongoSessionMock : IClientSessionHandle { namespace MaksIT.MongoDB.Linq.Tests;
internal class MongoSessionMock : IClientSessionHandle {
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
@ -89,5 +91,4 @@ namespace MaksIT.MongoDB.Linq.Tests {
#endregion #endregion
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
} }

View File

@ -3,8 +3,10 @@
using MaksIT.Results; using MaksIT.Results;
using MaksIT.MongoDB.Linq.Tests.Mock; using MaksIT.MongoDB.Linq.Tests.Mock;
namespace MaksIT.MongoDB.Linq.Tests {
public class MongoSessionManagerTests { namespace MaksIT.MongoDB.Linq.Tests;
public class MongoSessionManagerTests {
private readonly MongoSessionManager _sessionManager; private readonly MongoSessionManager _sessionManager;
private readonly ILogger<MongoSessionManager> _logger; private readonly ILogger<MongoSessionManager> _logger;
@ -62,5 +64,4 @@ namespace MaksIT.MongoDB.Linq.Tests {
// Assert // Assert
Assert.False(result.IsSuccess); Assert.False(result.IsSuccess);
} }
}
} }

View File

@ -1,7 +1,9 @@
using MaksIT.MongoDB.Linq.Utilities; using MaksIT.MongoDB.Linq.Utilities;
namespace MaksIT.MongoDB.Linq.Tests.Utilities {
public class CombGuidGeneratorTests { namespace MaksIT.MongoDB.Linq.Tests.Utilities;
public class CombGuidGeneratorTests {
[Fact] [Fact]
public void CreateCombGuid_WithCurrentTimestamp_ShouldGenerateGuid() { public void CreateCombGuid_WithCurrentTimestamp_ShouldGenerateGuid() {
// Act // Act
@ -77,5 +79,4 @@ namespace MaksIT.MongoDB.Linq.Tests.Utilities {
var exception = Record.Exception(() => CombGuidGenerator.ExtractTimestamp(invalidGuid)); var exception = Record.Exception(() => CombGuidGenerator.ExtractTimestamp(invalidGuid));
Assert.Null(exception); // Adjusted expectation based on behavior of `ExtractTimestamp` with a regular GUID Assert.Null(exception); // Adjusted expectation based on behavior of `ExtractTimestamp` with a regular GUID
} }
}
} }

View File

@ -7,8 +7,9 @@ using MaksIT.Core.Abstractions.Dto;
using MaksIT.Results; using MaksIT.Results;
namespace MaksIT.MongoDB.Linq.Abstractions { namespace MaksIT.MongoDB.Linq.Abstractions;
public abstract class BaseCollectionDataProviderBase<T, TDtoDocument, TDtoKey> : DataProviderBase<T>
public abstract class BaseCollectionDataProviderBase<T, TDtoDocument, TDtoKey> : DataProviderBase<T>
where TDtoDocument : DtoDocumentBase<TDtoKey> { where TDtoDocument : DtoDocumentBase<TDtoKey> {
protected readonly IMongoCollection<TDtoDocument> Collection; protected readonly IMongoCollection<TDtoDocument> Collection;
@ -236,5 +237,5 @@ namespace MaksIT.MongoDB.Linq.Abstractions {
} }
} }
#endregion #endregion
}
} }

View File

@ -7,9 +7,10 @@ using MongoDB.Driver;
using MaksIT.Results; using MaksIT.Results;
using MaksIT.Core.Abstractions.Dto; using MaksIT.Core.Abstractions.Dto;
namespace MaksIT.MongoDB.Linq.Abstractions {
public abstract class CollectionDataProviderBase<T, TDtoDocument, TDtoKey> : BaseCollectionDataProviderBase<T, TDtoDocument, TDtoKey> namespace MaksIT.MongoDB.Linq.Abstractions;
public abstract class CollectionDataProviderBase<T, TDtoDocument, TDtoKey> : BaseCollectionDataProviderBase<T, TDtoDocument, TDtoKey>
where TDtoDocument : DtoDocumentBase<TDtoKey> { where TDtoDocument : DtoDocumentBase<TDtoKey> {
protected CollectionDataProviderBase( protected CollectionDataProviderBase(
@ -122,5 +123,4 @@ namespace MaksIT.MongoDB.Linq.Abstractions {
protected Result DeleteManyWithPredicate(Expression<Func<TDtoDocument, bool>> predicate, IClientSessionHandle? session) => protected Result DeleteManyWithPredicate(Expression<Func<TDtoDocument, bool>> predicate, IClientSessionHandle? session) =>
DeleteManyWithPredicateAsync(predicate, session).Result; DeleteManyWithPredicateAsync(predicate, session).Result;
#endregion #endregion
}
} }

View File

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

View File

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

View File

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

View File

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

View File

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