Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build -c Release --no-restore
- name: Test
run: dotnet test -c Release --no-build --framework net9.0
run: dotnet test -c Release --no-build --framework net10.0
6 changes: 3 additions & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
- name: Set VERSION variable from tag
run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
- name: Build
run: dotnet build -c Release /p:Version=${VERSION}
- name: Test
run: dotnet test -c Release /p:Version=${VERSION} --no-build --framework net9.0
run: dotnet test -c Release /p:Version=${VERSION} --no-build --framework net10.0
- name: Pack
run: dotnet pack -c Release /p:Version=${VERSION} --no-build --output .
- name: Push
Expand Down
4 changes: 2 additions & 2 deletions LICENSE.txt → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Sean Roddis
Copyright (c) 2026 Rafael Pallares

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static BsonDocumentReader CreateVersionReader(BsonDocument document)

private static BsonDocumentWriter CreateVersionWriter()
{
var writer = new BsonDocumentWriter(new BsonDocument());
var writer = new BsonDocumentWriter([]);
writer.WriteStartDocument();
writer.WriteName("version");
return writer;
Expand Down
2 changes: 1 addition & 1 deletion Mongo.Migration.Tests/IntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Mongo.Migration.Tests;

[TestFixture]
public class IntegrationTest
public abstract class IntegrationTest
{
private const string DatabaseName = "IntegrationTest";
private const string CollectionName = "Test";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Mongo.Migration.Tests.Migrations.Database;

[TestFixture]
internal class DatabaseIntegrationTest
internal abstract class DatabaseIntegrationTest
{
private const string MigrationsCollectionName = "_migrations";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public async Task When_database_has_no_migrations_Then_all_migrations_are_used()
// Assert
var migrations = GetMigrationHistory();

Assert.Multiple(() =>
using (Assert.EnterMultipleScope())
{
Assert.That(migrations, Is.Not.Empty);
Assert.That(migrations[0].Version.ToString(), Is.EqualTo("0.0.1"));
Assert.That(migrations[1].Version.ToString(), Is.EqualTo("0.0.2"));
Assert.That(migrations[2].Version.ToString(), Is.EqualTo("0.0.3"));
});
}
}

[Test]
Expand All @@ -45,11 +45,11 @@ public async Task When_database_has_migrations_Then_latest_migrations_are_used()
// Assert
var migrations = GetMigrationHistory();

Assert.Multiple(() =>
using (Assert.EnterMultipleScope())
{
Assert.That(migrations, Is.Not.Empty);
Assert.That(migrations[2].Version.ToString(), Is.EqualTo("0.0.3"));
});
}
}

[Test]
Expand All @@ -71,12 +71,12 @@ public async Task When_database_has_latest_version_Then_nothing_happens()
// Assert
var migrations = GetMigrationHistory();

Assert.Multiple(() =>
using (Assert.EnterMultipleScope())
{
Assert.That(migrations, Is.Not.Empty);
Assert.That(migrations[0].Version.ToString(), Is.EqualTo("0.0.1"));
Assert.That(migrations[1].Version.ToString(), Is.EqualTo("0.0.2"));
Assert.That(migrations[2].Version.ToString(), Is.EqualTo("0.0.3"));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public void When_migrating_down_Then_all_migrations_are_used()
runner.Run(typeof(TestDocumentWithTwoMigration), document);

// Assert
Assert.Multiple(() =>
using (Assert.EnterMultipleScope())
{
Assert.That(document.Names.ToList()[1], Is.EqualTo("Dors"));
Assert.That(document.Values.ToList()[0].AsString, Is.EqualTo("0.0.0"));
});
}
}

[Test]
Expand All @@ -46,10 +46,10 @@ public void When_document_has_Then_all_migrations_are_used_to_that_version()
runner.Run(typeof(TestDocumentWithTwoMigrationMiddleVersion), document);

// Assert
Assert.Multiple(() =>
using (Assert.EnterMultipleScope())
{
Assert.That(document.Names.ToList()[1], Is.EqualTo("Doors1"));
Assert.That(document.Values.ToList()[0].AsString, Is.EqualTo("0.0.1"));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public void When_migrate_up_the_lowest_version_Then_all_migrations_are_used()
runner.Run(typeof(TestDocumentWithTwoMigrationHighestVersion), document);

// Assert
Assert.Multiple(() =>
using (Assert.EnterMultipleScope())
{
Assert.That(document.Names.ToList()[1], Is.EqualTo("Door"));
Assert.That(document.Values.ToList()[0].AsString, Is.EqualTo("0.0.2"));
});
}
}

[Test]
Expand All @@ -45,11 +45,11 @@ public void When_document_has_no_version_Then_all_migrations_are_used()
runner.Run(typeof(TestDocumentWithTwoMigrationHighestVersion), document);

// Assert
Assert.Multiple(() =>
using (Assert.EnterMultipleScope())
{
Assert.That(document["Door"].AsInt32, Is.EqualTo(3));
Assert.That(document["Version"].AsString, Is.EqualTo("0.0.2"));
});
}
}

[Test]
Expand All @@ -67,10 +67,10 @@ public void When_document_has_current_version_Then_nothing_happens()
runner.Run(typeof(TestDocumentWithTwoMigrationHighestVersion), document);

// Assert
Assert.Multiple(() =>
using (Assert.EnterMultipleScope())
{
Assert.That(document.Names.ToList()[1], Is.EqualTo("Door"));
Assert.That(document.Values.ToList()[0].AsString, Is.EqualTo("0.0.2"));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public void Then_migration_should_be_created()
var migration = new TestDocumentWithOneMigration001();

// Assert
Assert.That(migration, Is.TypeOf(typeof(TestDocumentWithOneMigration001)));
Assert.That(migration, Is.TypeOf<TestDocumentWithOneMigration001>());
}
}
64 changes: 28 additions & 36 deletions Mongo.Migration.Tests/Migrations/Interceptor/InterceptorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,45 +38,41 @@ public async Task TestDeserializationIntercepted()
IMongoCollection<TestDocumentWithTwoMigrationMiddleVersion> testDocumentCollection =
GetCollection<TestDocumentWithTwoMigrationMiddleVersion>();

await untypedCollection.InsertManyAsync(new[]
{
new BsonDocument
{
await untypedCollection.InsertManyAsync(
[
[
new("Doors0", new BsonInt32(0))
},
new BsonDocument
{
],
[
new("Doors0", new BsonInt32(1)),
new("Version", new BsonString("0.0.0"))
},
new BsonDocument
{
],
[
new("Doors1", new BsonInt32(2)),
new("Version", new BsonString("0.0.1"))
},
new BsonDocument
{
],
[
new("Doors2", new BsonInt32(3)),
new("Version", new BsonString("0.0.2"))
}
});
]
]);

var asyncCursor = await testDocumentCollection
.FindAsync(FilterDefinition<TestDocumentWithTwoMigrationMiddleVersion>.Empty);
List<TestDocumentWithTwoMigrationMiddleVersion> documents = await asyncCursor.ToListAsync();

Assert.Multiple(() =>
using (Assert.EnterMultipleScope())
{
Assert.That(documents, Has.Count.EqualTo(4));
Assert.That(
documents.Select(d => d.Version.ToString()),
Is.All.EqualTo("0.0.1"));

Assert.That(documents[0].Doors1, Is.EqualTo(0));
Assert.That(documents[0].Doors1, Is.Zero);
Assert.That(documents[1].Doors1, Is.EqualTo(1));
Assert.That(documents[2].Doors1, Is.EqualTo(2));
Assert.That(documents[3].Doors1, Is.EqualTo(3));
});
}
}

[Test]
Expand Down Expand Up @@ -106,45 +102,41 @@ public async Task TestDeserializationVersionAsStringIntercepted()
IMongoCollection<TestClassWithTwoMigrationMiddleVersion> testDocumentCollection =
GetCollection<TestClassWithTwoMigrationMiddleVersion>();

await untypedCollection.InsertManyAsync(new[]
{
new BsonDocument
{
await untypedCollection.InsertManyAsync(
[
[
new("Doors0", new BsonInt32(0))
},
new BsonDocument
{
],
[
new("Doors0", new BsonInt32(1)),
new("Version", new BsonString("0.0.0"))
},
new BsonDocument
{
],
[
new("Doors1", new BsonInt32(2)),
new("Version", new BsonString("0.0.1"))
},
new BsonDocument
{
],
[
new("Doors2", new BsonInt32(3)),
new("Version", new BsonString("0.0.2"))
}
});
]
]);

var asyncCursor = await testDocumentCollection
.FindAsync(FilterDefinition<TestClassWithTwoMigrationMiddleVersion>.Empty);
List<TestClassWithTwoMigrationMiddleVersion> documents = await asyncCursor.ToListAsync();

Assert.Multiple(() =>
using (Assert.EnterMultipleScope())
{
Assert.That(documents, Has.Count.EqualTo(4));
Assert.That(
documents.Select(d => d.Version.ToString()),
Is.All.EqualTo("0.0.1"));

Assert.That(documents[0].Doors1, Is.EqualTo(0));
Assert.That(documents[0].Doors1, Is.Zero);
Assert.That(documents[1].Doors1, Is.EqualTo(1));
Assert.That(documents[2].Doors1, Is.EqualTo(2));
Assert.That(documents[3].Doors1, Is.EqualTo(3));
});
}
}


Expand Down
18 changes: 9 additions & 9 deletions Mongo.Migration.Tests/Mongo.Migration.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<LangVersion>13.0</LangVersion>
<TargetFrameworks>net10.0;net9.0;net8.0</TargetFrameworks>
<LangVersion>14.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand All @@ -17,16 +17,16 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.7.0">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.11.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
<PackageReference Include="Testcontainers.MongoDb" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.1.0" />
<PackageReference Include="Testcontainers.MongoDb" Version="4.10.0" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 10 additions & 4 deletions Mongo.Migration.Tests/MongoDB/VariousCrudOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ public async Task TestRead()
.Where(d => d.Doors >= 98)
.Single();

Assert.That(documentById.Id, Is.EqualTo(id));
Assert.That(documentByExpression.Id, Is.EqualTo(id));
using (Assert.EnterMultipleScope())
{
Assert.That(documentById.Id, Is.EqualTo(id));
Assert.That(documentByExpression.Id, Is.EqualTo(id));
}
}

[Test]
Expand Down Expand Up @@ -95,8 +98,11 @@ public async Task TestUpdate()
.Where(d => d.Id == id)
.Single();

Assert.That(documentUpdated.Id, Is.EqualTo(id));
Assert.That(documentUpdated.Doors, Is.EqualTo(8));
using (Assert.EnterMultipleScope())
{
Assert.That(documentUpdated.Id, Is.EqualTo(id));
Assert.That(documentUpdated.Doors, Is.EqualTo(8));
}
}

[Test]
Expand Down
4 changes: 2 additions & 2 deletions Mongo.Migration.Tests/Performance/PerformanceOnStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ private static async Task<List<object>> QueryAllAsync(bool withVersion)
var versionedCollection = client.GetDatabase(DatabaseName)
.GetCollection<TestDocumentWithTwoMigrationHighestVersion>(CollectionName);
var versionedResult = await (await versionedCollection.FindAsync(_ => true)).ToListAsync();
return versionedResult.Cast<object>().ToList();
return [.. versionedResult.Cast<object>()];
}

var collection = client.GetDatabase(DatabaseName)
.GetCollection<TestClassNoMigration>(CollectionName);
var result = await (await collection.FindAsync(_ => true)).ToListAsync();
return result.Cast<object>().ToList();
return [.. result.Cast<object>()];
}

private static async Task AddDocumentsToCacheAsync()
Expand Down
Loading