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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"image": "mcr.microsoft.com/devcontainers/dotnet:2-10.0-noble",
"features": {
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"dockerDashComposeVersion": "none",
"installDockerBuildx": false
}
},
"postCreateCommand": "dotnet restore"
}
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,67 @@ jobs:
name: Container Test Results (${{ matrix.database }})
path: ./test-results/**/*.trx
reporter: dotnet-trx

mongodb-tests:
name: Container Tests (MongoDB)
runs-on: ubuntu-latest
needs: build-and-test
timeout-minutes: 10

env:
CI: true

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET SDKs
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x

- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-MongoDB-${{ hashFiles('**/*.csproj', 'Directory.Packages.props') }}
restore-keys: |
nuget-${{ runner.os }}-MongoDB-
nuget-${{ runner.os }}-

- name: Restore
run: >-
dotnet restore
tests/ExpressiveSharp.MongoDB.IntegrationTests/ExpressiveSharp.MongoDB.IntegrationTests.csproj

- name: Build
run: >-
dotnet build --no-restore -c Release
tests/ExpressiveSharp.MongoDB.IntegrationTests/ExpressiveSharp.MongoDB.IntegrationTests.csproj

- name: Test
run: >-
dotnet test --no-build -c Release
--project tests/ExpressiveSharp.MongoDB.IntegrationTests
--
--report-trx --report-trx-filename results.trx
--results-directory ./test-results

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: container-test-results-MongoDB
path: ./test-results/**/*.trx
retention-days: 14

- name: Test report
if: always()
uses: dorny/test-reporter@v1
with:
name: Container Test Results (MongoDB)
path: ./test-results/**/*.trx
reporter: dotnet-trx
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
<PackageVersion Include="Testcontainers.CosmosDb" Version="4.3.0" />
<PackageVersion Include="Testcontainers.MySql" Version="4.3.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Cosmos" Version="8.0.25" />
<PackageVersion Include="MongoDB.Driver" Version="3.0.0" />
<PackageVersion Include="Testcontainers.MongoDb" Version="4.3.0" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions ExpressiveSharp.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
<Project Path="src/ExpressiveSharp.Generator/ExpressiveSharp.Generator.csproj" />
<Project Path="src/ExpressiveSharp.Abstractions/ExpressiveSharp.Abstractions.csproj" />
<Project Path="src/ExpressiveSharp/ExpressiveSharp.csproj" />
<Project Path="src/ExpressiveSharp.MongoDB/ExpressiveSharp.MongoDB.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/ExpressiveSharp.Generator.Tests/ExpressiveSharp.Generator.Tests.csproj" />
<Project Path="tests/ExpressiveSharp.IntegrationTests/ExpressiveSharp.IntegrationTests.csproj" />
<Project Path="tests/ExpressiveSharp.EntityFrameworkCore.IntegrationTests/ExpressiveSharp.EntityFrameworkCore.IntegrationTests.csproj" />
<Project Path="tests/ExpressiveSharp.Tests/ExpressiveSharp.Tests.csproj" />
<Project Path="tests/ExpressiveSharp.MongoDB.IntegrationTests/ExpressiveSharp.MongoDB.IntegrationTests.csproj" />
</Folder>
</Solution>
56 changes: 56 additions & 0 deletions src/ExpressiveSharp.MongoDB/ExpressiveMongoCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using ExpressiveSharp.MongoDB.Extensions;
using ExpressiveSharp.Services;
using MongoDB.Driver;

namespace ExpressiveSharp.MongoDB;

/// <summary>
/// A wrapper around <see cref="IMongoCollection{TDocument}"/> that provides an
/// <see cref="IExpressiveMongoQueryable{T}"/> for delegate-based LINQ queries
/// with automatic <c>[Expressive]</c> member expansion.
/// </summary>
/// <remarks>
/// Analogous to <c>ExpressiveDbSet&lt;TEntity&gt;</c> in the EF Core integration.
/// CRUD operations delegate directly to the inner collection.
/// </remarks>
/// <example>
/// <code>
/// var orders = new ExpressiveMongoCollection&lt;Order&gt;(collection);
/// var results = await orders.AsQueryable()
/// .Where(o => o.Customer?.Name == "Alice")
/// .ToListAsync();
/// </code>
/// </example>
public class ExpressiveMongoCollection<TDocument>
{
private readonly IMongoCollection<TDocument> _inner;
private readonly ExpressiveOptions _options;

/// <summary>
/// Creates a new <see cref="ExpressiveMongoCollection{TDocument}"/> wrapping the specified collection.
/// </summary>
/// <param name="inner">The underlying MongoDB collection.</param>
/// <param name="options">
/// Optional <see cref="ExpressiveOptions"/> controlling the transformer pipeline.
/// When <c>null</c>, <see cref="MongoExpressiveOptions.CreateDefault"/> is used.
/// </param>
public ExpressiveMongoCollection(IMongoCollection<TDocument> inner, ExpressiveOptions? options = null)
{
_inner = inner ?? throw new ArgumentNullException(nameof(inner));
_options = options ?? MongoExpressiveOptions.CreateDefault();
}

/// <summary>
/// Gets the underlying <see cref="IMongoCollection{TDocument}"/> for direct access
/// to non-LINQ operations (inserts, updates, deletes, aggregation pipeline, etc.).
/// </summary>
public IMongoCollection<TDocument> Inner => _inner;

/// <summary>
/// Returns an <see cref="IExpressiveMongoQueryable{T}"/> that supports delegate-based
/// LINQ with modern C# syntax and automatic <c>[Expressive]</c> expansion.
/// </summary>
/// <param name="aggregateOptions">Optional MongoDB aggregation options.</param>
public IExpressiveMongoQueryable<TDocument> AsQueryable(AggregateOptions? aggregateOptions = null)
=> _inner.AsExpressive(_options, aggregateOptions);
}
19 changes: 19 additions & 0 deletions src/ExpressiveSharp.MongoDB/ExpressiveSharp.MongoDB.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>MongoDB Driver integration for ExpressiveSharp — automatically expands [Expressive] members in MongoDB LINQ queries</Description>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="ExpressiveSharp.MongoDB.IntegrationTests" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ExpressiveSharp\ExpressiveSharp.csproj" />
</ItemGroup>

</Project>
Loading
Loading