diff --git a/.build/NuGet.config b/.build/NuGet.config
deleted file mode 100644
index 21a6bf8..0000000
--- a/.build/NuGet.config
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
deleted file mode 100644
index 09faa15..0000000
--- a/.github/CODEOWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-# Make the Turing team owner of the entire repo
-* @sherweb/dothraki
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
deleted file mode 100644
index 0c2fc8d..0000000
--- a/.github/dependabot.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-# To get started with Dependabot version updates, you'll need to specify which
-# package ecosystems to update and where the package manifests are located.
-# Please see the documentation for all configuration options:
-# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
-
-version: 2
-registries:
- nuget-org:
- type: nuget-feed
- url: https://api.nuget.org/v3/index.json
- sherweb:
- type: nuget-feed
- url: https://nuget.pkg.github.com/Sherweb/index.json
- username: op-github-svc
- password: ${{secrets.OP_GITHUB_SVC_PAT}}
-updates:
- - package-ecosystem: "nuget" # See documentation for possible values
- directory: "/" # Location of package manifests
- registries:
- - nuget-org
- - sherweb
- schedule:
- interval: "daily"
- time: "00:00"
\ No newline at end of file
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
deleted file mode 100644
index 81a831b..0000000
--- a/.github/pull_request_template.md
+++ /dev/null
@@ -1,43 +0,0 @@
-## Summary of changes[^practices]
-
-````text
-This section is where you explain the changes you made.
-
-Remove this block when done.
-````
-
-Related Work Item: AB#xxxxx
-
-## Dependencies
-
-````text
-This section is where you list all the dependencies of this PR.
-
-Remove this block when done.
-Remove this section if empty.
-````
-
-## Dependents[^deps]
-
-````text
-This section is where you list all the changes to be done after this PR
-(breaking changes in contracts, consumers to update, etc.).
-
-Remove this block when done.
-Remove this section if empty.
-````
-
-### Checks
-
-- [ ] I have labeled the PR correctly
-- [ ] I have set the PR title with the proper versioning[^versioning] prefix (will help for the merge commit message)
-- [ ] I have added tests that prove my fix is effective or that my feature works
-- [ ] I have maximized the division of this story and could not make multiple smaller PRs
-- [ ] I have used stable versions for every package in this PR (if not dependending on an unclosed PR)
-- [ ] The changelog is written in the story
-
-
-
-[^practices]: https://wiki.sherweb.com/display/TUR/Meilleures+pratiques+pour+la+revue+de+pull+requests
-[^deps]: https://github.com/sherweb/OfficeProtect.Utils/blob/master/dependencies/README.md
-[^versioning]: https://github.com/sherweb/OfficeProtect.Application/blob/master/docs/software/application-versioning.md
diff --git a/.github/release.yml b/.github/release.yml
deleted file mode 100644
index 08793e7..0000000
--- a/.github/release.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-changelog:
- categories:
- - title: Breaking changes
- labels:
- - breaking change
- - title: Features
- labels:
- - feature
- - title: Changes
- labels:
- - change
- - title: Fixes
- labels:
- - bug
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
new file mode 100644
index 0000000..4f08da3
--- /dev/null
+++ b/.github/workflows/build.yaml
@@ -0,0 +1,23 @@
+name: Build and test
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+
+env:
+ DOTNET_NOLOGO: true
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - 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 net10.0
diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml
new file mode 100644
index 0000000..ebf65ac
--- /dev/null
+++ b/.github/workflows/publish.yaml
@@ -0,0 +1,33 @@
+name: Publish
+
+on:
+ push:
+ tags:
+ - "v[0-9]+.[0-9]+.[0-9]+"
+ - "v[0-9]+.[0-9]+.[0-9]+-[a-z]+[0-9]+"
+
+env:
+ DOTNET_NOLOGO: true
+
+jobs:
+ publish:
+ runs-on: ubuntu-latest
+ permissions:
+ packages: write
+ contents: read
+ steps:
+ - 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 net10.0
+ - name: Pack
+ run: dotnet pack -c Release /p:Version=${VERSION} --no-build --output .
+ - name: Push
+ env:
+ NUGET_SOURCE: ${{ vars.NUGET_SOURCE }}
+ NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
+ run: dotnet nuget push Mongo.Migration.${VERSION}.nupkg --source $NUGET_SOURCE --api-key "$NUGET_API_KEY"
diff --git a/.pipelines/azure-pipelines-pr.yaml b/.pipelines/azure-pipelines-pr.yaml
deleted file mode 100644
index 0b9f09e..0000000
--- a/.pipelines/azure-pipelines-pr.yaml
+++ /dev/null
@@ -1,53 +0,0 @@
-parameters:
- - name: arrayExecs
- type: object
- default:
- - none
- - name: arrayPackages
- type: object
- default:
- - Mongo.Migration
- - name: arrayTests
- type: object
- default:
- - none
- - name: dockerfilePath
- type: string
- default: "none"
- - name: dotNetSdkVersion
- type: string
- default: '6.x'
- - name: gitRepoName
- type: string
- default: "Mongo.Migration"
-
-variables:
- - group: github-credentials
-
-pr:
- - main
- - master
-trigger: none
-
-pool:
- vmImage: 'ubuntu-latest'
-
-resources:
- repositories:
- - repository: tools
- type: git
- name: OfficeProtect/tools
- ref: main
-
-stages:
- - stage: PR_Analysis
- displayName: Lint, Tests and Static Analysis
- jobs:
- - template: azdoTemplates/workflows/pr-dotnet.yaml@tools
- parameters:
- arrayExecs: ${{ parameters.arrayExecs }}
- arrayPackages: ${{ parameters.arrayPackages }}
- arrayTests: ${{ parameters.arrayTests }}
- dockerfilePath: "${{ parameters.dockerfilePath }}"
- dotNetSdkVersion: "${{ parameters.dotNetSdkVersion }}"
- projectPath: "$(System.DefaultWorkingDirectory)/${{ parameters.gitRepoName }}"
diff --git a/.pipelines/azure-pipelines.yaml b/.pipelines/azure-pipelines.yaml
deleted file mode 100644
index 36cd355..0000000
--- a/.pipelines/azure-pipelines.yaml
+++ /dev/null
@@ -1,69 +0,0 @@
-parameters:
- - name: acrRepoURI
- type: string
- default: 'acr0opp0dev0root0sw.azurecr.io'
- - name: arrayExecs
- type: object
- default:
- - none
- - name: arrayPackages
- type: object
- default:
- - Mongo.Migration
- - name: arrayTests
- type: object
- default:
- - none
- - name: dockerfilePath
- type: string
- default: "none"
- - name: dotNetSdkVersion
- type: string
- default: '6.x'
- - name: gitRepoName
- type: string
- default: "Mongo.Migration"
-
-variables:
- - group: DatadogCI
- - group: github-credentials
-
-pr: none
-trigger:
- branches:
- include:
- - 'main'
- - 'master'
-
-pool:
- vmImage: 'ubuntu-latest'
-
-resources:
- repositories:
- - repository: tools
- type: git
- name: OfficeProtect/tools
- ref: main
- - repository: kube-services
- type: github
- endpoint: op-github-svc
- name: sherweb/kube-services
- ref: dev
-
-stages:
- - stage: CI_CD
- displayName: DotNet Continuous Integration & Deployment
- jobs:
- - template: azdoTemplates/workflows/ci-dotnet.yaml@tools
- parameters:
- acrRepoURI: "${{ parameters.acrRepoURI }}"
- arrayExecs: ${{ parameters.arrayExecs }}
- arrayPackages: ${{ parameters.arrayPackages }}
- arrayTests: ${{ parameters.arrayTests }}
- dockerfilePath: "${{ parameters.dockerfilePath }}"
- dotNetSdkVersion: "${{ parameters.dotNetSdkVersion }}"
- projectPath: "$(System.DefaultWorkingDirectory)/${{ parameters.gitRepoName }}"
- - template: azdoTemplates/workflows/cd-docker.yaml@tools
- parameters:
- env: "dev"
- imageNames: ${{ parameters.arrayExecs }}
diff --git a/LICENSE.txt b/LICENSE.md
similarity index 95%
rename from LICENSE.txt
rename to LICENSE.md
index 6442aad..cfd64ed 100644
--- a/LICENSE.txt
+++ b/LICENSE.md
@@ -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
@@ -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.
\ No newline at end of file
+SOFTWARE.
diff --git a/Mongo.Migration.Test.Core/Mongo.Migration.Test.Core.csproj b/Mongo.Migration.Test.Core/Mongo.Migration.Test.Core.csproj
deleted file mode 100644
index d4abe21..0000000
--- a/Mongo.Migration.Test.Core/Mongo.Migration.Test.Core.csproj
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
- false
- Library
- net6.0
- x64
-
-
-
-
-
-
-
-
-
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Documents/DocumentVersion_When_casting.cs b/Mongo.Migration.Test/Documents/DocumentVersion_When_casting.cs
deleted file mode 100644
index dfb20ed..0000000
--- a/Mongo.Migration.Test/Documents/DocumentVersion_When_casting.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using FluentAssertions;
-
-using Mongo.Migration.Documents;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Documents
-{
- [TestFixture]
- public class DocumentVersion_When_casting
- {
- [Test]
- public void If_implicit_string_to_version_Then_cast_should_work()
- {
- DocumentVersion version = "1.0.2";
-
- version.ToString().Should().Be("1.0.2");
- }
-
- [Test]
- public void If_implicit_version_to_string_Then_cast_should_work()
- {
- var version = new DocumentVersion("1.0.2");
-
- string versionString = version;
-
- versionString.Should().Be("1.0.2");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Documents/DocumentVersion_When_compare.cs b/Mongo.Migration.Test/Documents/DocumentVersion_When_compare.cs
deleted file mode 100644
index 3cd31c3..0000000
--- a/Mongo.Migration.Test/Documents/DocumentVersion_When_compare.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-using FluentAssertions;
-
-using Mongo.Migration.Documents;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Documents
-{
- [TestFixture]
- public class DocumentVersion_When_compare
- {
- private readonly DocumentVersion equalLowerVersion = new DocumentVersion("0.0.1");
-
- private readonly DocumentVersion higherVersion = new DocumentVersion("0.0.2");
-
- private readonly DocumentVersion lowerVersion = new DocumentVersion("0.0.1");
-
- [Test]
- public void If_higherVersion_lte_equalLowerVersion_Then_false()
- {
- bool result = this.higherVersion <= this.lowerVersion;
-
- result.Should().BeFalse();
- }
-
- [Test]
- public void If_lowerVersion_gt_higherVersion_Then_false()
- {
- bool result = this.lowerVersion > this.higherVersion;
-
- result.Should().BeFalse();
- }
-
- [Test]
- public void If_lowerVersion_gte_equalLowerVersion_Then_true()
- {
- bool result = this.lowerVersion >= this.equalLowerVersion;
-
- result.Should().BeTrue();
- }
-
- [Test]
- public void If_lowerVersion_gte_higherVersion_Then_false()
- {
- bool result = this.lowerVersion >= this.higherVersion;
-
- result.Should().BeFalse();
- }
-
- [Test]
- public void If_lowerVersion_lt_higherVersion_Then_true()
- {
- bool result = this.lowerVersion < this.higherVersion;
-
- result.Should().BeTrue();
- }
-
- [Test]
- public void If_lowerVersion_lte_equalLowerVersion_Then_true()
- {
- bool result = this.lowerVersion <= this.equalLowerVersion;
-
- result.Should().BeTrue();
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Documents/DocumentVersion_When_creating.cs b/Mongo.Migration.Test/Documents/DocumentVersion_When_creating.cs
deleted file mode 100644
index a3ff804..0000000
--- a/Mongo.Migration.Test/Documents/DocumentVersion_When_creating.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-using System;
-
-using FluentAssertions;
-
-using Mongo.Migration.Documents;
-using Mongo.Migration.Exceptions;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Documents
-{
- [TestFixture]
- public class DocumentVersion_When_creating
- {
- [Test]
- public void If_Default_Then_version_is_default_value()
- {
- DocumentVersion version = DocumentVersion.Default();
-
- version.ToString().Should().Be("0.0.0");
- }
-
- [Test]
- public void If_first_part_contains_char_Then_exception_is_thrown()
- {
- Action act = () => new DocumentVersion("a.0.0");
-
- act.Should().Throw();
- }
-
- [Test]
- public void If_new_version_with_int_Then_version_string_should_be_same()
- {
- var version = new DocumentVersion(1, 0, 2);
-
- version.ToString().Should().Be("1.0.2");
- }
-
- [Test]
- public void If_new_version_with_string_Then_version_string_should_be_same()
- {
- var version = new DocumentVersion("1.0.2");
-
- version.ToString().Should().Be("1.0.2");
- }
-
- [Test]
- public void If_second_part_contains_char_Then_exception_is_thrown()
- {
- Action act = () => new DocumentVersion("0.a.0");
-
- act.Should().Throw();
- }
-
- [Test]
- public void If_third_part_contains_char_Then_exception_is_thrown()
- {
- Action act = () => new DocumentVersion("0.0.a");
-
- act.Should().Throw();
- }
-
- [Test]
- public void If_version_string_is_to_long_Then_exception_is_thrown()
- {
- Action act = () => new DocumentVersion("0.0.0.0");
-
- act.Should().Throw();
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Documents/Document_when_creating.cs b/Mongo.Migration.Test/Documents/Document_when_creating.cs
deleted file mode 100644
index 3fc4797..0000000
--- a/Mongo.Migration.Test/Documents/Document_when_creating.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using FluentAssertions;
-
-using Mongo.Migration.Documents;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Documents
-{
- [TestFixture]
- public class Document_when_creating
- {
- [Test]
- public void Then_document_can_be_created()
- {
- // Arrange Act
- IDocument document = new Document();
-
- // Assert
- document.Should().BeOfType();
- }
-
- [Test]
- public void Then_document_has_a_version()
- {
- // Arrange
- IDocument document = new Document();
-
- // Act
- var version = document.Version;
-
- // Assert
- version.Should().Be("0.0.0");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Documents/Locators/AttributeMigrationLocator_when_locate.cs b/Mongo.Migration.Test/Documents/Locators/AttributeMigrationLocator_when_locate.cs
deleted file mode 100644
index dd6cb8c..0000000
--- a/Mongo.Migration.Test/Documents/Locators/AttributeMigrationLocator_when_locate.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using FluentAssertions;
-
-using Mongo.Migration.Documents.Locators;
-using Mongo.Migration.Test.TestDoubles;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Documents.Locators
-{
- [TestFixture]
- internal class VersionLocator_when_locate
- {
- [Test]
- public void Then_find_current_version_of_document()
- {
- // Arrange
- var locator = new RuntimeVersionLocator();
-
- // Act
- var currentVersion = locator.GetLocateOrNull(typeof(TestDocumentWithOneMigration));
-
- // Assert
- currentVersion.ToString().Should().Be("0.0.1");
- }
-
- [Test]
- public void When_document_has_no_attribute_Then_return_null()
- {
- // Arrange
- var locator = new RuntimeVersionLocator();
-
- // Act
- var currentVersion = locator.GetLocateOrNull(typeof(TestDocumentWithoutAttribute));
-
- // Assert
- currentVersion.Should().BeNull();
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Documents/Serializers/DocumentVersionSerializer_when_serialize_and_deserialize.cs b/Mongo.Migration.Test/Documents/Serializers/DocumentVersionSerializer_when_serialize_and_deserialize.cs
deleted file mode 100644
index 0439e97..0000000
--- a/Mongo.Migration.Test/Documents/Serializers/DocumentVersionSerializer_when_serialize_and_deserialize.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-using FluentAssertions;
-
-using Mongo.Migration.Documents;
-using Mongo.Migration.Documents.Serializers;
-
-using MongoDB.Bson;
-using MongoDB.Bson.IO;
-using MongoDB.Bson.Serialization;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Documents.Serializers
-{
- [TestFixture]
- public class DocumentVersionSerializer_when_serialize_and_deserialize
- {
- private DocumentVersionSerializer _serializer;
-
- [Test]
- public void Then_version_is_deserialized_correct()
- {
- // Arrange
- var document = new BsonDocument { { "version", "0.1.1" } };
- BsonDocumentReader reader = CreateVersionReader(document);
-
- BsonDeserializationContext context = BsonDeserializationContext.CreateRoot(reader);
- var args = new BsonDeserializationArgs { NominalType = typeof(DocumentVersion) };
-
- // Act
- DocumentVersion result = this._serializer.Deserialize(context, args);
-
- // Assert
- result.Should().BeOfType();
- result.Should().Be("0.1.1");
- }
-
- [Test]
- public void Then_version_is_serialized_correct()
- {
- // Arrange
- BsonDocumentWriter writer = CreateVersionWriter();
- BsonSerializationContext context = BsonSerializationContext.CreateRoot(writer);
- var args = new BsonSerializationArgs { NominalType = typeof(DocumentVersion) };
- var version = new DocumentVersion("0.0.1");
-
- // Act
- this._serializer.Serialize(context, args, version);
-
- // Assert
- BsonDocument document = writer.Document;
- document.ToString().Should().Be("{ \"version\" : \"0.0.1\" }");
- }
-
- [SetUp]
- public void SetUp()
- {
- this._serializer = new DocumentVersionSerializer();
- }
-
- private static BsonDocumentReader CreateVersionReader(BsonDocument document)
- {
- var reader = new BsonDocumentReader(document);
- reader.ReadStartDocument();
- reader.ReadName();
- return reader;
- }
-
- private static BsonDocumentWriter CreateVersionWriter()
- {
- var writer = new BsonDocumentWriter(new BsonDocument());
- writer.WriteStartDocument();
- writer.WriteName("version");
- return writer;
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/IntegrationTest.cs b/Mongo.Migration.Test/IntegrationTest.cs
deleted file mode 100644
index 418d395..0000000
--- a/Mongo.Migration.Test/IntegrationTest.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-using System;
-
-using Mongo.Migration.Startup;
-using Mongo.Migration.Startup.Static;
-
-using Mongo2Go;
-
-using MongoDB.Driver;
-
-namespace Mongo.Migration.Test
-{
- public class IntegrationTest : IDisposable
- {
- protected IMongoClient _client;
-
- protected IComponentRegistry _components;
-
- protected MongoDbRunner _mongoToGoRunner;
-
- public void Dispose()
- {
- this._mongoToGoRunner?.Dispose();
- }
-
- protected void OnSetUp()
- {
- this._mongoToGoRunner = MongoDbRunner.Start();
- this._client = new MongoClient(this._mongoToGoRunner.ConnectionString);
-
- this._client.GetDatabase("PerformanceTest").CreateCollection("Test");
-
- this._components = new ComponentRegistry(
- new MongoMigrationSettings
- { ConnectionString = this._mongoToGoRunner.ConnectionString, Database = "PerformanceTest" });
- this._components.RegisterComponents(this._client);
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Migrations/Database/DatabaseIntegrationTest.cs b/Mongo.Migration.Test/Migrations/Database/DatabaseIntegrationTest.cs
deleted file mode 100644
index 07f8933..0000000
--- a/Mongo.Migration.Test/Migrations/Database/DatabaseIntegrationTest.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-using Mongo.Migration.Documents;
-using Mongo.Migration.Migrations.Database;
-using Mongo.Migration.Startup;
-using Mongo.Migration.Startup.Static;
-
-using Mongo2Go;
-
-using MongoDB.Bson;
-using MongoDB.Driver;
-
-namespace Mongo.Migration.Test.Migrations.Database
-{
- internal class DatabaseIntegrationTest : IDisposable
- {
- private const string MigrationsCollectionName = "_migrations";
-
- protected IMongoClient _client;
-
- protected IComponentRegistry _components;
-
- protected IMongoDatabase _db;
-
- protected MongoDbRunner _mongoToGoRunner;
-
- protected virtual string DatabaseName { get; set; } = "DatabaseMigration";
-
- protected virtual string CollectionName { get; set; } = "Test";
-
- public void Dispose()
- {
- this._mongoToGoRunner?.Dispose();
- }
-
- protected virtual void OnSetUp(DocumentVersion databaseMigrationVersion)
- {
- this._mongoToGoRunner = MongoDbRunner.Start();
- this._client = new MongoClient(this._mongoToGoRunner.ConnectionString);
- this._db = this._client.GetDatabase(this.DatabaseName);
- this._db.CreateCollection(this.CollectionName);
-
- this._components = new ComponentRegistry(
- new MongoMigrationSettings
- {
- ConnectionString = this._mongoToGoRunner.ConnectionString,
- Database = this.DatabaseName,
- DatabaseMigrationVersion = databaseMigrationVersion
- });
- this._components.RegisterComponents(this._client);
- }
-
- protected void InsertMigrations(IEnumerable migrations)
- {
- var list = migrations.Select(m => new BsonDocument { { "MigrationId", m.GetType().ToString() }, { "Version", m.Version.ToString() } });
- this._db.GetCollection(MigrationsCollectionName).InsertManyAsync(list).Wait();
- }
-
- protected List GetMigrationHistory()
- {
- var migrationHistoryCollection = this._db.GetCollection(MigrationsCollectionName);
- return migrationHistoryCollection.Find(m => true).ToList();
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Migrations/Database/DatabaseMigrationRunnerSetup.cs b/Mongo.Migration.Test/Migrations/Database/DatabaseMigrationRunnerSetup.cs
deleted file mode 100644
index d35f768..0000000
--- a/Mongo.Migration.Test/Migrations/Database/DatabaseMigrationRunnerSetup.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-using Mongo.Migration.Documents.Serializers;
-
-using MongoDB.Bson;
-using MongoDB.Bson.Serialization;
-
-using NLog;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Migrations.Database
-{
- [SetUpFixture]
- public class DatabaseMigrationRunnerSetup
- {
- private readonly Logger _logger = LogManager.GetCurrentClassLogger();
-
- [OneTimeSetUp]
- public void GlobalSetup()
- {
- try
- {
- var documentSerializaer = new DocumentVersionSerializer();
- BsonSerializer.RegisterSerializer(documentSerializaer.ValueType, documentSerializaer);
- }
- catch (BsonSerializationException ex)
- {
- this._logger.Warn(ex);
- }
- }
-
- [OneTimeTearDown]
- public void GlobalTeardown()
- {
- // Do logout here
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Migrations/Database/DatabaseMigrationRunner_when_migrating_down.cs b/Mongo.Migration.Test/Migrations/Database/DatabaseMigrationRunner_when_migrating_down.cs
deleted file mode 100644
index 96e4f3e..0000000
--- a/Mongo.Migration.Test/Migrations/Database/DatabaseMigrationRunner_when_migrating_down.cs
+++ /dev/null
@@ -1,74 +0,0 @@
-using FluentAssertions;
-
-using Mongo.Migration.Documents;
-using Mongo.Migration.Migrations.Database;
-using Mongo.Migration.Test.TestDoubles;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Migrations.Database
-{
- [TestFixture]
- internal class DatabaseMigrationRunner_when_migrating_down : DatabaseIntegrationTest
- {
- private IDatabaseMigrationRunner _runner;
-
- protected override void OnSetUp(DocumentVersion databaseMigrationVersion)
- {
- base.OnSetUp(databaseMigrationVersion);
-
- this._runner = this._components.Get();
- }
-
- [TearDown]
- public void TearDown()
- {
- this.Dispose();
- }
-
- [Test]
- public void When_database_has_migrations_Then_down_all_migrations()
- {
- this.OnSetUp(DocumentVersion.Default());
-
- // Arrange
- this.InsertMigrations(
- new DatabaseMigration[]
- {
- new TestDatabaseMigration_0_0_1(),
- new TestDatabaseMigration_0_0_2(),
- new TestDatabaseMigration_0_0_3()
- });
-
- // Act
- this._runner.Run(this._db);
-
- // Assert
- var migrations = this.GetMigrationHistory();
- migrations.Should().BeEmpty();
- }
-
- [Test]
- public void When_database_has_migrations_Then_down_to_selected_migration()
- {
- this.OnSetUp(new DocumentVersion("0.0.1"));
-
- // Arrange
- this.InsertMigrations(
- new DatabaseMigration[]
- {
- new TestDatabaseMigration_0_0_1(),
- new TestDatabaseMigration_0_0_2(),
- new TestDatabaseMigration_0_0_3()
- });
-
- // Act
- this._runner.Run(this._db);
-
- // Assert
- var migrations = this.GetMigrationHistory();
- migrations.Should().NotBeEmpty();
- migrations.Should().OnlyContain(m => m.Version == "0.0.1");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Migrations/Database/DatabaseMigrationRunner_when_migrating_up.cs b/Mongo.Migration.Test/Migrations/Database/DatabaseMigrationRunner_when_migrating_up.cs
deleted file mode 100644
index 7a03cf0..0000000
--- a/Mongo.Migration.Test/Migrations/Database/DatabaseMigrationRunner_when_migrating_up.cs
+++ /dev/null
@@ -1,77 +0,0 @@
-using FluentAssertions;
-
-using Mongo.Migration.Documents;
-using Mongo.Migration.Migrations.Database;
-using Mongo.Migration.Test.TestDoubles;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Migrations.Database
-{
- [TestFixture]
- internal class DatabaseMigrationRunner_when_migrating_up : DatabaseIntegrationTest
- {
- private IDatabaseMigrationRunner _runner;
-
- [SetUp]
- public void SetUp()
- {
- base.OnSetUp(DocumentVersion.Empty());
-
- this._runner = this._components.Get();
- }
-
- [TearDown]
- public void TearDown()
- {
- this.Dispose();
- }
-
- [Test]
- public void When_database_has_no_migrations_Then_all_migrations_are_used()
- {
- // Act
- this._runner.Run(this._db);
-
- // Assert
- var migrations = this.GetMigrationHistory();
- migrations.Should().NotBeEmpty();
- migrations[0].Version.ToString().Should().BeEquivalentTo("0.0.1");
- migrations[1].Version.ToString().Should().BeEquivalentTo("0.0.2");
- migrations[2].Version.ToString().Should().BeEquivalentTo("0.0.3");
- }
-
- [Test]
- public void When_database_has_migrations_Then_latest_migrations_are_used()
- {
- // Arrange
- this.InsertMigrations(new DatabaseMigration[] { new TestDatabaseMigration_0_0_1(), new TestDatabaseMigration_0_0_2() });
-
- // Act
- this._runner.Run(this._db);
-
- // Assert
- var migrations = this.GetMigrationHistory();
- migrations.Should().NotBeEmpty();
- migrations[2].Version.ToString().Should().BeEquivalentTo("0.0.3");
- }
-
- [Test]
- public void When_database_has_latest_version_Then_nothing_happens()
- {
- // Arrange
- this.InsertMigrations(
- new DatabaseMigration[] { new TestDatabaseMigration_0_0_1(), new TestDatabaseMigration_0_0_2(), new TestDatabaseMigration_0_0_3() });
-
- // Act
- this._runner.Run(this._db);
-
- // Assert
- var migrations = this.GetMigrationHistory();
- migrations.Should().NotBeEmpty();
- migrations[0].Version.ToString().Should().BeEquivalentTo("0.0.1");
- migrations[1].Version.ToString().Should().BeEquivalentTo("0.0.2");
- migrations[2].Version.ToString().Should().BeEquivalentTo("0.0.3");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Migrations/Database/DatabaseMigration_when_creating.cs b/Mongo.Migration.Test/Migrations/Database/DatabaseMigration_when_creating.cs
deleted file mode 100644
index 1e3cc95..0000000
--- a/Mongo.Migration.Test/Migrations/Database/DatabaseMigration_when_creating.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-using FluentAssertions;
-
-using Mongo.Migration.Migrations.Database;
-using Mongo.Migration.Test.TestDoubles;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Migrations.Database
-{
- [TestFixture]
- public class DatabaseMigration_when_creating
- {
- [Test]
- public void Then_migration_has_type_DatabaseMigration()
- {
- // Arrange Act
- var migration = new TestDatabaseMigration_0_0_1();
-
- // Assert
- migration.Type.Should().Be(typeof(DatabaseMigration));
- }
-
- [Test]
- public void Then_migration_have_version()
- {
- // Arrange Act
- var migration = new TestDatabaseMigration_0_0_1();
-
- // Assert
- migration.Version.Should().Be("0.0.1");
- }
-
- [Test]
- public void Then_migration_should_be_created()
- {
- // Arrange Act
- var migration = new TestDatabaseMigration_0_0_1();
-
- // Assert
- migration.Should().BeOfType();
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Migrations/Document/DocumentMigrationRunner_when_migrating_down.cs b/Mongo.Migration.Test/Migrations/Document/DocumentMigrationRunner_when_migrating_down.cs
deleted file mode 100644
index 8f6e382..0000000
--- a/Mongo.Migration.Test/Migrations/Document/DocumentMigrationRunner_when_migrating_down.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-using System.Linq;
-
-using FluentAssertions;
-
-using Mongo.Migration.Migrations.Document;
-using Mongo.Migration.Test.TestDoubles;
-
-using MongoDB.Bson;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Migrations.Document
-{
- [TestFixture]
- internal class DocumentMigrationRunner_when_migrating_down : IntegrationTest
- {
- private IDocumentMigrationRunner _runner;
-
- [SetUp]
- public void SetUp()
- {
- this.OnSetUp();
-
- this._runner = this._components.Get();
- }
-
- [TearDown]
- public void TearDown()
- {
- this.Dispose();
- }
-
- [Test]
- public void When_migrating_down_Then_all_migrations_are_used()
- {
- // Arrange
- BsonDocument document = new BsonDocument
- {
- { "Version", "0.0.2" },
- { "Door", 3 }
- };
-
- // Act
- this._runner.Run(typeof(TestDocumentWithTwoMigration), document);
-
- // Assert
- document.Names.ToList()[1].Should().Be("Dors");
- document.Values.ToList()[0].AsString.Should().Be("0.0.0");
- }
-
- [Test]
- public void When_document_has_Then_all_migrations_are_used_to_that_version()
- {
- // Arrange
- // Arrange
- BsonDocument document = new BsonDocument
- {
- { "Version", "0.0.2" },
- { "Door", 3 }
- };
-
- // Act
- this._runner.Run(typeof(TestDocumentWithTwoMigrationMiddleVersion), document);
-
- // Assert
- document.Names.ToList()[1].Should().Be("Doors");
- document.Values.ToList()[0].AsString.Should().Be("0.0.1");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Migrations/Document/DocumentMigrationRunner_when_migrating_up.cs b/Mongo.Migration.Test/Migrations/Document/DocumentMigrationRunner_when_migrating_up.cs
deleted file mode 100644
index 7a1b466..0000000
--- a/Mongo.Migration.Test/Migrations/Document/DocumentMigrationRunner_when_migrating_up.cs
+++ /dev/null
@@ -1,86 +0,0 @@
-using System.Linq;
-
-using FluentAssertions;
-
-using Mongo.Migration.Migrations.Document;
-using Mongo.Migration.Test.TestDoubles;
-
-using MongoDB.Bson;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Migrations.Document
-{
- [TestFixture]
- internal class DocumentMigrationRunner_when_migrating_up : IntegrationTest
- {
- private IDocumentMigrationRunner _runner;
-
- [SetUp]
- public void SetUp()
- {
- this.OnSetUp();
-
- this._runner = this._components.Get();
- }
-
- [TearDown]
- public void TearDown()
- {
- this.Dispose();
- }
-
- [Test]
- public void When_migrate_up_the_lowest_version_Then_all_migrations_are_used()
- {
- // Arrange
- BsonDocument document = new BsonDocument
- {
- { "Version", "0.0.0" },
- { "Dors", 3 }
- };
-
- // Act
- this._runner.Run(typeof(TestDocumentWithTwoMigrationHighestVersion), document);
-
- // Assert
- document.Names.ToList()[1].Should().Be("Door");
- document.Values.ToList()[0].AsString.Should().Be("0.0.2");
- }
-
- [Test]
- public void When_document_has_no_version_Then_all_migrations_are_used()
- {
- // Arrange
- BsonDocument document = new BsonDocument
- {
- { "Dors", 3 }
- };
-
- // Act
- this._runner.Run(typeof(TestDocumentWithTwoMigrationHighestVersion), document);
-
- // Assert
- document.Names.ToList()[1].Should().Be("Door");
- document.Values.ToList()[0].AsString.Should().Be("0.0.2");
- }
-
- [Test]
- public void When_document_has_current_version_Then_nothing_happens()
- {
- // Arrange
- BsonDocument document = new BsonDocument
- {
- { "Version", "0.0.2" },
- { "Door", 3 }
- };
-
- // Act
- this._runner.Run(typeof(TestDocumentWithTwoMigrationHighestVersion), document);
-
- // Assert
- document.Names.ToList()[1].Should().Be("Door");
- document.Values.ToList()[0].AsString.Should().Be("0.0.2");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Migrations/Document/DocumentMigration_when_creating.cs b/Mongo.Migration.Test/Migrations/Document/DocumentMigration_when_creating.cs
deleted file mode 100644
index 610f5fa..0000000
--- a/Mongo.Migration.Test/Migrations/Document/DocumentMigration_when_creating.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-using FluentAssertions;
-
-using Mongo.Migration.Test.TestDoubles;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Migrations.Document
-{
- [TestFixture]
- public class DocumentMigration_when_creating
- {
- [Test]
- public void Then_migration_has_type_testClass()
- {
- // Arrange Act
- var migration = new TestDocumentWithOneMigration_0_0_1();
-
- // Assert
- migration.Type.Should().Be(typeof(TestDocumentWithOneMigration));
- }
-
- [Test]
- public void Then_migration_have_version()
- {
- // Arrange Act
- var migration = new TestDocumentWithOneMigration_0_0_1();
-
- // Assert
- migration.Version.Should().Be("0.0.1");
- }
-
- [Test]
- public void Then_migration_should_be_created()
- {
- // Arrange Act
- var migration = new TestDocumentWithOneMigration_0_0_1();
-
- // Assert
- migration.Should().BeOfType();
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Migrations/Document/DocumentMigration_when_migrating.cs b/Mongo.Migration.Test/Migrations/Document/DocumentMigration_when_migrating.cs
deleted file mode 100644
index 830dbb2..0000000
--- a/Mongo.Migration.Test/Migrations/Document/DocumentMigration_when_migrating.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-using FluentAssertions;
-
-using Mongo.Migration.Test.TestDoubles;
-
-using MongoDB.Bson;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Migrations.Document
-{
- [TestFixture]
- public class DocumentMigration_when_migrating
- {
- [Test]
- public void When_migrating_down_Then_document_changes()
- {
- // Arrange
- var migration = new TestDocumentWithOneMigration_0_0_1();
- var document = new BsonDocument { { "Doors", 3 } };
-
- // Act
- migration.Down(document);
-
- // Assert
- document.Should().BeEquivalentTo(new BsonDocument { { "Dors", 3 } });
- }
-
- [Test]
- public void When_migrating_up_Then_document_changes()
- {
- // Arrange
- var migration = new TestDocumentWithOneMigration_0_0_1();
- var document = new BsonDocument { { "Dors", 3 } };
-
- // Act
- migration.Up(document);
-
- // Assert
- document.Should().BeEquivalentTo(new BsonDocument { { "Doors", 3 } });
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Migrations/Locators/TypeMigrationLocator_when_locate.cs b/Mongo.Migration.Test/Migrations/Locators/TypeMigrationLocator_when_locate.cs
deleted file mode 100644
index 0bb8deb..0000000
--- a/Mongo.Migration.Test/Migrations/Locators/TypeMigrationLocator_when_locate.cs
+++ /dev/null
@@ -1,75 +0,0 @@
-using System.Linq;
-
-using FluentAssertions;
-
-using Mongo.Migration.Migrations.Locators;
-using Mongo.Migration.Test.TestDoubles;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Migrations.Locators
-{
- [TestFixture]
- public class TypeMigrationLocator_when_locate
- {
- private TypeMigrationLocator _locator;
-
- [OneTimeSetUp]
- public void OneTimeSetUp()
- {
- // Arrange
- this._locator = new TypeMigrationLocator();
- }
-
- [Test]
- public void When_document_has_one_migration_Then_migrations_count_should_be_one()
- {
- // Act
- var result = this._locator.GetMigrations(typeof(TestDocumentWithOneMigration));
-
- // Assert
- result.Count().Should().Be(1);
- }
-
- [Test]
- public void When_document_has_two_migration_Then_migrations_count_should_be_two()
- {
- // Act
- var result = this._locator.GetMigrations(typeof(TestDocumentWithTwoMigration));
-
- // Assert
- result.Count().Should().Be(2);
- }
-
- [Test]
- public void When_get_latest_version_of_migrations()
- {
- // Act
- var version = this._locator.GetLatestVersion(typeof(TestDocumentWithTwoMigration));
-
- // Assert
- version.Should().Be("0.0.2");
- }
-
- [Test]
- public void When_get_migrations_gt_and_equal_version()
- {
- // Act
- var result = this._locator.GetMigrationsGtEq(typeof(TestDocumentWithTwoMigration), "0.0.1").ToList();
-
- // Assert
- result[0].Should().BeOfType();
- result[1].Should().BeOfType();
- }
-
- [Test]
- public void When_get_migrations_gt_version()
- {
- // Act
- var result = this._locator.GetMigrationsGt(typeof(TestDocumentWithTwoMigration), "0.0.1").ToList();
-
- // Assert
- result[0].Should().BeOfType();
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Mongo.Migration.Test.csproj b/Mongo.Migration.Test/Mongo.Migration.Test.csproj
deleted file mode 100644
index cb0686d..0000000
--- a/Mongo.Migration.Test/Mongo.Migration.Test.csproj
+++ /dev/null
@@ -1,170 +0,0 @@
-
-
-
-
-
- Debug
- AnyCPU
- {8EDF4429-251A-416D-BB68-93F227191BCF}
- Library
- Properties
- Mongo.Migration.Test
- Mongo.Migration.Test
- v4.8
- 512
-
- default
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll
- True
-
-
- ..\packages\DnsClient.1.2.0\lib\net45\DnsClient.dll
- True
-
-
- ..\packages\FluentAssertions.5.6.0\lib\net47\FluentAssertions.dll
- True
-
-
-
- ..\packages\Mongo2Go.2.2.11\lib\netstandard1.6\Mongo2Go.dll
- True
-
-
- ..\packages\MongoDB.Bson.2.8.0\lib\net452\MongoDB.Bson.dll
- True
-
-
- ..\packages\MongoDB.Driver.2.8.0\lib\net452\MongoDB.Driver.dll
- True
-
-
- ..\packages\MongoDB.Driver.Core.2.8.0\lib\net452\MongoDB.Driver.Core.dll
- True
-
-
-
- ..\packages\NSubstitute.4.1.0\lib\net46\NSubstitute.dll
- True
-
-
- ..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll
- True
-
-
-
- ..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll
- True
-
-
-
- ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll
- True
-
-
- ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll
- True
-
-
- ..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll
- True
-
-
- ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {8dffd615-1e1a-4bed-8a96-caf4c3637e81}
- Mongo.Migration
-
-
-
-
-
- This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.
-
-
-
-
-
\ No newline at end of file
diff --git a/Mongo.Migration.Test/MongoDB/MongoRegistrater_when_registrating.cs b/Mongo.Migration.Test/MongoDB/MongoRegistrater_when_registrating.cs
deleted file mode 100644
index 370e559..0000000
--- a/Mongo.Migration.Test/MongoDB/MongoRegistrater_when_registrating.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-using FluentAssertions;
-
-using Mongo.Migration.Documents;
-using Mongo.Migration.Services;
-
-using MongoDB.Bson.Serialization;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.MongoDB
-{
- [TestFixture]
- internal class MongoRegistrator_when_registrating : IntegrationTest
- {
- [SetUp]
- public void SetUp()
- {
- this.OnSetUp();
- }
-
- [TearDown]
- public void TearDown()
- {
- this.Dispose();
- }
-
- [Test]
- public void Then_serializer_is_registered()
- {
- // Arrange
- var migrationService = this._components.Get();
-
- // Act
- migrationService.Migrate();
-
- // Arrange
- BsonSerializer.LookupSerializer().ValueType.Should().Be(typeof(DocumentVersion));
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Performance/PerformanceOnStartup.cs b/Mongo.Migration.Test/Performance/PerformanceOnStartup.cs
deleted file mode 100644
index d675dd8..0000000
--- a/Mongo.Migration.Test/Performance/PerformanceOnStartup.cs
+++ /dev/null
@@ -1,133 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-using FluentAssertions;
-
-using Mongo.Migration.Startup.Static;
-using Mongo.Migration.Test.TestDoubles;
-
-using Mongo2Go;
-
-using MongoDB.Bson;
-using MongoDB.Driver;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Performance
-{
- [TestFixture]
- public class PerformanceTestOnStartup
- {
- private const int DOCUMENT_COUNT = 10000;
-
- private const string DATABASE_NAME = "PerformanceTest";
-
- private const string COLLECTION_NAME = "Test";
-
- private const int TOLERANCE_MS = 2800;
-
- private MongoClient _client;
-
- private MongoDbRunner _runner;
-
- [TearDown]
- public void TearDown()
- {
- MongoMigrationClient.Reset();
- this._client = null;
- this._runner.Dispose();
- }
-
- [SetUp]
- public void SetUp()
- {
- this._runner = MongoDbRunner.Start();
- this._client = new MongoClient(this._runner.ConnectionString);
- }
-
- [Test]
- public void When_migrating_number_of_documents()
- {
- // Arrange
- // Worm up MongoCache
- this.ClearCollection();
- this.AddDocumentsToCache();
- this.ClearCollection();
-
- // Act
- // Measure time of MongoDb processing without Mongo.Migration
- this.InsertMany(DOCUMENT_COUNT, false);
- var sw = new Stopwatch();
- sw.Start();
- this.MigrateAll(false);
- sw.Stop();
-
- this.ClearCollection();
-
- // Measure time of MongoDb processing without Mongo.Migration
- this.InsertMany(DOCUMENT_COUNT, true);
- var swWithMigration = new Stopwatch();
- swWithMigration.Start();
- MongoMigrationClient.Initialize(this._client);
- swWithMigration.Stop();
-
- this.ClearCollection();
-
- var result = swWithMigration.ElapsedMilliseconds - sw.ElapsedMilliseconds;
-
- Console.WriteLine(
- $"MongoDB: {sw.ElapsedMilliseconds}ms, Mongo.Migration: {swWithMigration.ElapsedMilliseconds}ms, Diff: {result}ms (Tolerance: {TOLERANCE_MS}ms), Documents: {DOCUMENT_COUNT}, Migrations per Document: 2");
-
- // Assert
- result.Should().BeLessThan(TOLERANCE_MS);
- }
-
- private void InsertMany(int number, bool withVersion)
- {
- var documents = new List();
- for (var n = 0; n < number; n++)
- {
- var document = new BsonDocument
- {
- { "Dors", 3 }
- };
- if (withVersion)
- {
- document.Add("Version", "0.0.0");
- }
-
- documents.Add(document);
- }
-
- this._client.GetDatabase(DATABASE_NAME).GetCollection(COLLECTION_NAME).InsertManyAsync(documents)
- .Wait();
- }
-
- private void MigrateAll(bool withVersion)
- {
- if (withVersion)
- {
- var versionedCollectin = this._client.GetDatabase(DATABASE_NAME)
- .GetCollection(COLLECTION_NAME);
- var versionedResult = versionedCollectin.FindAsync(_ => true).Result.ToListAsync().Result;
- return;
- }
-
- var collection = this._client.GetDatabase(DATABASE_NAME)
- .GetCollection(COLLECTION_NAME);
- var result = collection.FindAsync(_ => true).Result.ToListAsync().Result;
- }
-
- private void AddDocumentsToCache()
- {
- this.InsertMany(DOCUMENT_COUNT, false);
- this.MigrateAll(false);
- }
-
- private void ClearCollection()
- {
- this._client.GetDatabase(DATABASE_NAME).DropCollection(COLLECTION_NAME);
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Properties/AssemblyInfo.cs b/Mongo.Migration.Test/Properties/AssemblyInfo.cs
deleted file mode 100644
index 5edd146..0000000
--- a/Mongo.Migration.Test/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("Mongo.Migration.Test")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("nunit.tests")]
-[assembly: AssemblyCopyright("Copyright © 2017")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Mongo.Migration.Test/Services/DatabaseVersionService_when_determine_version.cs b/Mongo.Migration.Test/Services/DatabaseVersionService_when_determine_version.cs
deleted file mode 100644
index 77d6a81..0000000
--- a/Mongo.Migration.Test/Services/DatabaseVersionService_when_determine_version.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-using FluentAssertions;
-
-using Mongo.Migration.Documents;
-using Mongo.Migration.Services;
-using Mongo.Migration.Test.Migrations.Database;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Services
-{
- [TestFixture]
- internal class DatabaseVersionService_when_determine_version : DatabaseIntegrationTest
- {
- private IDatabaseVersionService _service;
-
- protected override void OnSetUp(DocumentVersion version)
- {
- base.OnSetUp(version);
-
- this._service = this._components.Get();
- }
-
- [TearDown]
- public void TearDown()
- {
- this.Dispose();
- }
-
- [Test]
- public void When_project_has_migrations_Then_get_latest_version()
- {
- // Arrange
- this.OnSetUp(DocumentVersion.Empty());
-
- // Act
- var migrationVersion = this._service.GetCurrentOrLatestMigrationVersion();
-
- // Assert
- migrationVersion.ToString().Should().Be("0.0.3");
- }
-
- [Test]
- public void When_version_set_on_startup_Then_use_startup_version()
- {
- // Arrange
- this.OnSetUp(new DocumentVersion(0, 0, 2));
-
- // Act
- var migrationVersion = this._service.GetCurrentOrLatestMigrationVersion();
-
- // Assert
- migrationVersion.ToString().Should().Be("0.0.2");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Services/DocumentVersionService_when_determine_version.cs b/Mongo.Migration.Test/Services/DocumentVersionService_when_determine_version.cs
deleted file mode 100644
index 219ce0b..0000000
--- a/Mongo.Migration.Test/Services/DocumentVersionService_when_determine_version.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-using System;
-
-using FluentAssertions;
-
-using Mongo.Migration.Exceptions;
-using Mongo.Migration.Services;
-using Mongo.Migration.Test.TestDoubles;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Services
-{
- [TestFixture]
- internal class DocumentVersionService_when_determine_version : IntegrationTest
- {
- private IDocumentVersionService _service;
-
- [SetUp]
- public void SetUp()
- {
- this.OnSetUp();
-
- this._service = this._components.Get();
- }
-
- [TearDown]
- public void TearDown()
- {
- this.Dispose();
- }
-
- [Test]
- public void When_document_has_current_version_Then_current_version_is_set()
- {
- // Arrange
- var document = new TestDocumentWithTwoMigrationMiddleVersion();
-
- // Act
- this._service.DetermineVersion(document);
-
- // Assert
- document.Version.Should().Be("0.0.1");
- }
-
- [Test]
- public void When_document_has_highest_version_Then_highest_version_is_set()
- {
- // Arrange
- var document = new TestDocumentWithTwoMigrationHighestVersion();
-
- // Act
- this._service.DetermineVersion(document);
-
- // Assert
- document.Version.Should().Be("0.0.2");
- }
-
- [Test]
- public void When_document_has_version_that_should_not_be_Then_throw_exception()
- {
- // Arrange
- var document = new TestDocumentWithTwoMigrationHighestVersion { Version = "0.0.1" };
-
- // Act// Act
- Action checkAction = () => { this._service.DetermineVersion(document); };
-
- // Assert
- checkAction.Should().Throw();
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Services/Initializers/MongoMigration_when_initialize.cs b/Mongo.Migration.Test/Services/Initializers/MongoMigration_when_initialize.cs
deleted file mode 100644
index 8a125b5..0000000
--- a/Mongo.Migration.Test/Services/Initializers/MongoMigration_when_initialize.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using System;
-
-using FluentAssertions;
-
-using Mongo.Migration.Exceptions;
-using Mongo.Migration.Startup.Static;
-
-using NSubstitute;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Services.Initializers
-{
- [TestFixture]
- public class MongoMigration_when_initialize
- {
- [TearDown]
- public void TearDown()
- {
- MongoMigrationClient.Reset();
- }
-
- [Test]
- public void When_inizialize_twice_Then_throw_exception()
- {
- // Arrange
- var registry = Substitute.For();
- var mongoMigration = Substitute.For();
-
- registry.Get().Returns(mongoMigration);
-
- // Act
- MongoMigrationClient.Initialize(registry);
-
- Action comparison = () => MongoMigrationClient.Initialize(registry);
-
- // Assert
- comparison.Should().Throw();
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Services/Interceptors/MigrationInterceptorFactory_when_creating.cs b/Mongo.Migration.Test/Services/Interceptors/MigrationInterceptorFactory_when_creating.cs
deleted file mode 100644
index a94c12b..0000000
--- a/Mongo.Migration.Test/Services/Interceptors/MigrationInterceptorFactory_when_creating.cs
+++ /dev/null
@@ -1,66 +0,0 @@
-using System;
-
-using FluentAssertions;
-
-using Mongo.Migration.Services.Interceptors;
-using Mongo.Migration.Test.TestDoubles;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Services.Interceptors
-{
- [TestFixture]
- internal class MigrationInterceptorFactory_when_creating : IntegrationTest
- {
- [SetUp]
- public void SetUp()
- {
- this.OnSetUp();
- }
-
- [TearDown]
- public void TearDown()
- {
- this.Dispose();
- }
-
- [Test]
- public void If_type_is_assignable_to_document_Then_interceptor_is_created()
- {
- // Arrange
- var factory = this._components.Get();
-
- // Act
- var interceptor = factory.Create(typeof(TestDocumentWithOneMigration));
-
- // Assert
- interceptor.ValueType.Should().Be();
- }
-
- [Test]
- public void If_type_is_not_assignable_to_document_Then_exception_is_thrown()
- {
- // Arrange
- var factory = this._components.Get();
-
- // Act
- Action act = () => factory.Create(typeof(TestClass));
-
- // Assert
- act.Should().ThrowExactly();
- }
-
- [Test]
- public void If_type_is_null_Then_exception_is_thrown()
- {
- // Arrange
- var factory = this._components.Get();
-
- // Act
- Action act = () => factory.Create(null);
-
- // Assert
- act.Should().ThrowExactly();
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/Services/Interceptors/MigrationInterceptorProvider_when_get_serializer.cs b/Mongo.Migration.Test/Services/Interceptors/MigrationInterceptorProvider_when_get_serializer.cs
deleted file mode 100644
index 7e48b69..0000000
--- a/Mongo.Migration.Test/Services/Interceptors/MigrationInterceptorProvider_when_get_serializer.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-using FluentAssertions;
-
-using Mongo.Migration.Services.Interceptors;
-using Mongo.Migration.Test.TestDoubles;
-
-using NUnit.Framework;
-
-namespace Mongo.Migration.Test.Services.Interceptors
-{
- [TestFixture]
- internal class MigrationInterceptorProvider_when_get_serializer : IntegrationTest
- {
- [SetUp]
- public void SetUp()
- {
- this.OnSetUp();
- }
-
- [TearDown]
- public void TearDown()
- {
- this.Dispose();
- }
-
- [Test]
- public void When_entity_is_document_Then_provide_serializer()
- {
- // Arrange
- var provider = this._components.Get();
-
- // Act
- var serializer = provider.GetSerializer(typeof(TestDocumentWithOneMigration));
-
- // Assert
- serializer.ValueType.Should().Be(typeof(TestDocumentWithOneMigration));
- }
-
- [Test]
- public void When_entity_is_not_document_Then_provide_null()
- {
- // Arrange
- var provider = this._components.Get();
-
- // Act
- var serializer = provider.GetSerializer(typeof(TestClass));
-
- // Assert
- serializer.Should().BeNull();
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/Database/TestDatabaseMigration_0_0_1.cs b/Mongo.Migration.Test/TestDoubles/Database/TestDatabaseMigration_0_0_1.cs
deleted file mode 100644
index 64ecd6e..0000000
--- a/Mongo.Migration.Test/TestDoubles/Database/TestDatabaseMigration_0_0_1.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using Mongo.Migration.Migrations.Database;
-
-using MongoDB.Driver;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- internal class TestDatabaseMigration_0_0_1 : DatabaseMigration
- {
- public TestDatabaseMigration_0_0_1()
- : base("0.0.1")
- {
- }
-
- public override void Up(IMongoDatabase db)
- {
- }
-
- public override void Down(IMongoDatabase db)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/Database/TestDatabaseMigration_0_0_2.cs b/Mongo.Migration.Test/TestDoubles/Database/TestDatabaseMigration_0_0_2.cs
deleted file mode 100644
index 5e260a7..0000000
--- a/Mongo.Migration.Test/TestDoubles/Database/TestDatabaseMigration_0_0_2.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using Mongo.Migration.Migrations.Database;
-
-using MongoDB.Driver;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- internal class TestDatabaseMigration_0_0_2 : DatabaseMigration
- {
- public TestDatabaseMigration_0_0_2()
- : base("0.0.2")
- {
- }
-
- public override void Up(IMongoDatabase db)
- {
- }
-
- public override void Down(IMongoDatabase db)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/Database/TestDatabaseMigration_0_0_3.cs b/Mongo.Migration.Test/TestDoubles/Database/TestDatabaseMigration_0_0_3.cs
deleted file mode 100644
index 7658858..0000000
--- a/Mongo.Migration.Test/TestDoubles/Database/TestDatabaseMigration_0_0_3.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using Mongo.Migration.Migrations.Database;
-
-using MongoDB.Driver;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- internal class TestDatabaseMigration_0_0_3 : DatabaseMigration
- {
- public TestDatabaseMigration_0_0_3()
- : base("0.0.3")
- {
- }
-
- public override void Up(IMongoDatabase db)
- {
- }
-
- public override void Down(IMongoDatabase db)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/TestClass.cs b/Mongo.Migration.Test/TestDoubles/TestClass.cs
deleted file mode 100644
index a2cd389..0000000
--- a/Mongo.Migration.Test/TestDoubles/TestClass.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using MongoDB.Bson;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- public class TestClass
- {
- public ObjectId Id { get; set; }
-
- public int Dors { get; set; }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/TestDocumentWithOneMigration.cs b/Mongo.Migration.Test/TestDoubles/TestDocumentWithOneMigration.cs
deleted file mode 100644
index 58ddf83..0000000
--- a/Mongo.Migration.Test/TestDoubles/TestDocumentWithOneMigration.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Mongo.Migration.Documents;
-using Mongo.Migration.Documents.Attributes;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- [RuntimeVersion("0.0.1")]
- internal class TestDocumentWithOneMigration : Document
- {
- public int Doors { get; set; }
- }
-
- internal class TestDocumentWithoutAttribute : Document
- {
- public int Doors { get; set; }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/TestDocumentWithOneMigration_0_0_1.cs b/Mongo.Migration.Test/TestDoubles/TestDocumentWithOneMigration_0_0_1.cs
deleted file mode 100644
index d5ef2d3..0000000
--- a/Mongo.Migration.Test/TestDoubles/TestDocumentWithOneMigration_0_0_1.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Mongo.Migration.Migrations.Document;
-
-using MongoDB.Bson;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- internal class TestDocumentWithOneMigration_0_0_1 : DocumentMigration
- {
- public TestDocumentWithOneMigration_0_0_1()
- : base("0.0.1")
- {
- }
-
- public override void Up(BsonDocument document)
- {
- var doors = document["Dors"].ToInt32();
- document.Add("Doors", doors);
- document.Remove("Dors");
- }
-
- public override void Down(BsonDocument document)
- {
- var doors = document["Doors"].ToInt32();
- document.Add("Dors", doors);
- document.Remove("Doors");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigration.cs b/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigration.cs
deleted file mode 100644
index 20dc81b..0000000
--- a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigration.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using Mongo.Migration.Documents;
-using Mongo.Migration.Documents.Attributes;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- [RuntimeVersion("0.0.0")]
- internal class TestDocumentWithTwoMigration : Document
- {
- public int Dors { get; set; }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationHighestVersion.cs b/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationHighestVersion.cs
deleted file mode 100644
index 71c355d..0000000
--- a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationHighestVersion.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Mongo.Migration.Documents;
-using Mongo.Migration.Documents.Attributes;
-
-using MongoDB.Bson;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- [RuntimeVersion("0.0.2")]
- [CollectionLocation("Test", "PerformanceTest")]
- internal class TestDocumentWithTwoMigrationHighestVersion : Document
- {
- public ObjectId Id { get; set; }
-
- public int Door { get; set; }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationHighestVersion_0_0_1.cs b/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationHighestVersion_0_0_1.cs
deleted file mode 100644
index b5ebed9..0000000
--- a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationHighestVersion_0_0_1.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Mongo.Migration.Migrations.Document;
-
-using MongoDB.Bson;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- internal class TestDocumentWithTwoMigrationHighestVersion_0_0_1 : DocumentMigration
- {
- public TestDocumentWithTwoMigrationHighestVersion_0_0_1()
- : base("0.0.1")
- {
- }
-
- public override void Up(BsonDocument document)
- {
- var doors = document["Dors"].ToInt32();
- document.Add("Doors", doors);
- document.Remove("Dors");
- }
-
- public override void Down(BsonDocument document)
- {
- var doors = document["Doors"].ToInt32();
- document.Add("Dors", doors);
- document.Remove("Doors");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationHighestVersion_0_0_2.cs b/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationHighestVersion_0_0_2.cs
deleted file mode 100644
index 4226663..0000000
--- a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationHighestVersion_0_0_2.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Mongo.Migration.Migrations.Document;
-
-using MongoDB.Bson;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- internal class TestDocumentWithTwoMigrationHighestVersion_0_0_2 : DocumentMigration
- {
- public TestDocumentWithTwoMigrationHighestVersion_0_0_2()
- : base("0.0.2")
- {
- }
-
- public override void Up(BsonDocument document)
- {
- var doors = document["Doors"].ToInt32();
- document.Add("Door", doors);
- document.Remove("Doors");
- }
-
- public override void Down(BsonDocument document)
- {
- var doors = document["Door"].ToInt32();
- document.Add("Doors", doors);
- document.Remove("Door");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationMiddleVersion.cs b/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationMiddleVersion.cs
deleted file mode 100644
index 8c567b4..0000000
--- a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationMiddleVersion.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using Mongo.Migration.Documents;
-using Mongo.Migration.Documents.Attributes;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- [RuntimeVersion("0.0.1")]
- internal class TestDocumentWithTwoMigrationMiddleVersion : Document
- {
- public int Door { get; set; }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationMiddleVersion_0_0_1.cs b/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationMiddleVersion_0_0_1.cs
deleted file mode 100644
index 77bb0cb..0000000
--- a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationMiddleVersion_0_0_1.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Mongo.Migration.Migrations.Document;
-
-using MongoDB.Bson;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- internal class TestDocumentWithTwoMigrationMiddleVersion_0_0_1 : DocumentMigration
- {
- public TestDocumentWithTwoMigrationMiddleVersion_0_0_1()
- : base("0.0.1")
- {
- }
-
- public override void Up(BsonDocument document)
- {
- var doors = document["Dors"].ToInt32();
- document.Add("Doors", doors);
- document.Remove("Dors");
- }
-
- public override void Down(BsonDocument document)
- {
- var doors = document["Doors"].ToInt32();
- document.Add("Dors", doors);
- document.Remove("Doors");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationMiddleVersion_0_0_2.cs b/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationMiddleVersion_0_0_2.cs
deleted file mode 100644
index 413cd36..0000000
--- a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigrationMiddleVersion_0_0_2.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Mongo.Migration.Migrations.Document;
-
-using MongoDB.Bson;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- internal class TestDocumentWithTwoMigrationMiddleVersion_0_0_2 : DocumentMigration
- {
- public TestDocumentWithTwoMigrationMiddleVersion_0_0_2()
- : base("0.0.2")
- {
- }
-
- public override void Up(BsonDocument document)
- {
- var doors = document["Doors"].ToInt32();
- document.Add("Door", doors);
- document.Remove("Doors");
- }
-
- public override void Down(BsonDocument document)
- {
- var doors = document["Door"].ToInt32();
- document.Add("Doors", doors);
- document.Remove("Door");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigration_0_0_1.cs b/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigration_0_0_1.cs
deleted file mode 100644
index 813fe9d..0000000
--- a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigration_0_0_1.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Mongo.Migration.Migrations.Document;
-
-using MongoDB.Bson;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- internal class TestDocumentWithTwoMigration_0_0_1 : DocumentMigration
- {
- public TestDocumentWithTwoMigration_0_0_1()
- : base("0.0.1")
- {
- }
-
- public override void Up(BsonDocument document)
- {
- var doors = document["Dors"].ToInt32();
- document.Add("Doors", doors);
- document.Remove("Dors");
- }
-
- public override void Down(BsonDocument document)
- {
- var doors = document["Doors"].ToInt32();
- document.Add("Dors", doors);
- document.Remove("Doors");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigration_0_0_2.cs b/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigration_0_0_2.cs
deleted file mode 100644
index 6531a2c..0000000
--- a/Mongo.Migration.Test/TestDoubles/TestDocumentWithTwoMigration_0_0_2.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Mongo.Migration.Migrations.Document;
-
-using MongoDB.Bson;
-
-namespace Mongo.Migration.Test.TestDoubles
-{
- internal class TestDocumentWithTwoMigration_0_0_2 : DocumentMigration
- {
- public TestDocumentWithTwoMigration_0_0_2()
- : base("0.0.2")
- {
- }
-
- public override void Up(BsonDocument document)
- {
- var doors = document["Doors"].ToInt32();
- document.Add("Door", doors);
- document.Remove("Doors");
- }
-
- public override void Down(BsonDocument document)
- {
- var doors = document["Door"].ToInt32();
- document.Add("Doors", doors);
- document.Remove("Door");
- }
- }
-}
\ No newline at end of file
diff --git a/Mongo.Migration.Test/packages.config b/Mongo.Migration.Test/packages.config
deleted file mode 100644
index 25ca16e..0000000
--- a/Mongo.Migration.Test/packages.config
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Documents/DocumentVersion_When_casting.cs b/Mongo.Migration.Tests/Documents/DocumentVersion_When_casting.cs
new file mode 100644
index 0000000..4710144
--- /dev/null
+++ b/Mongo.Migration.Tests/Documents/DocumentVersion_When_casting.cs
@@ -0,0 +1,24 @@
+using Mongo.Migration.Documents;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Documents;
+
+[TestFixture]
+public class DocumentVersionWhenCasting
+{
+ [Test]
+ public void If_implicit_string_to_version_Then_cast_should_work()
+ {
+ DocumentVersion version = new(1,0,2);
+ Assert.That(version.ToString(), Is.EqualTo("1.0.2"));
+ }
+
+ [Test]
+ public void If_implicit_version_to_string_Then_cast_should_work()
+ {
+ var version = new DocumentVersion(1,0,2);
+
+ string versionString = version.ToString();
+ Assert.That(versionString, Is.EqualTo("1.0.2"));
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Documents/DocumentVersion_When_compare.cs b/Mongo.Migration.Tests/Documents/DocumentVersion_When_compare.cs
new file mode 100644
index 0000000..ae98c3c
--- /dev/null
+++ b/Mongo.Migration.Tests/Documents/DocumentVersion_When_compare.cs
@@ -0,0 +1,62 @@
+using Mongo.Migration.Documents;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Documents;
+
+[TestFixture]
+public class DocumentVersionWhenCompare
+{
+ private readonly DocumentVersion _equalLowerVersion = new(0,0,1);
+
+ private readonly DocumentVersion _higherVersion = new(0, 0, 2);
+
+ private readonly DocumentVersion _lowerVersion = new(0, 0, 1);
+
+ [Test]
+ public void If_higherVersion_lte_equalLowerVersion_Then_false()
+ {
+ bool result = _higherVersion <= _lowerVersion;
+
+ Assert.That(result, Is.False);
+ }
+
+ [Test]
+ public void If_lowerVersion_gt_higherVersion_Then_false()
+ {
+ bool result = _lowerVersion > _higherVersion;
+
+ Assert.That(result, Is.False);
+ }
+
+ [Test]
+ public void If_lowerVersion_gte_equalLowerVersion_Then_true()
+ {
+ bool result = _lowerVersion >= _equalLowerVersion;
+
+ Assert.That(result, Is.True);
+ }
+
+ [Test]
+ public void If_lowerVersion_gte_higherVersion_Then_false()
+ {
+ bool result = _lowerVersion >= _higherVersion;
+
+ Assert.That(result, Is.False);
+ }
+
+ [Test]
+ public void If_lowerVersion_lt_higherVersion_Then_true()
+ {
+ bool result = _lowerVersion < _higherVersion;
+
+ Assert.That(result, Is.True);
+ }
+
+ [Test]
+ public void If_lowerVersion_lte_equalLowerVersion_Then_true()
+ {
+ bool result = _lowerVersion <= _equalLowerVersion;
+
+ Assert.That(result, Is.True);
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Documents/DocumentVersion_When_creating.cs b/Mongo.Migration.Tests/Documents/DocumentVersion_When_creating.cs
new file mode 100644
index 0000000..b347bdc
--- /dev/null
+++ b/Mongo.Migration.Tests/Documents/DocumentVersion_When_creating.cs
@@ -0,0 +1,75 @@
+using Mongo.Migration.Documents;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Documents;
+
+[TestFixture]
+public class DocumentVersionWhenCreating
+{
+ [Test]
+ public void If_Empty_Then_version_is_empty_value()
+ {
+ DocumentVersion version = DocumentVersion.Empty;
+ Assert.That(version.ToString(), Is.EqualTo("-1.0.0"));
+ }
+
+ [Test]
+ public void If_Default_Then_version_is_default_value()
+ {
+ DocumentVersion version = DocumentVersion.Default;
+
+ Assert.That(version.ToString(), Is.EqualTo("0.0.0"));
+ }
+
+ [Test]
+ public void If_first_part_contains_char_Then_exception_is_thrown()
+ {
+ Assert.Throws(() => DocumentVersion.Parse("a.0.0"));
+ }
+
+ [Test]
+ public void If_new_version_with_int_Then_version_string_should_be_same()
+ {
+ var version = new DocumentVersion(1, 0, 2);
+ Assert.That(version.ToString(), Is.EqualTo("1.0.2"));
+ }
+
+ [Test]
+ public void If_new_version_with_string_Then_version_string_should_be_same()
+ {
+ var version = DocumentVersion.Parse("1.0.2");
+ Assert.That(version.ToString(), Is.EqualTo("1.0.2"));
+ }
+
+ [Test]
+ public void If_second_part_contains_char_Then_exception_is_thrown()
+ {
+ Assert.Throws(() => DocumentVersion.Parse("0.a.0"));
+ }
+
+ [Test]
+ public void If_third_part_contains_char_Then_exception_is_thrown()
+ {
+ Assert.Throws(() => DocumentVersion.Parse("0.0.a"));
+ }
+
+ [Test]
+ public void If_version_string_is_too_long_Then_exception_is_thrown()
+ {
+ Assert.Throws(() => DocumentVersion.Parse("0.0.0.0"));
+ }
+
+ [Test]
+ public void If_version_string_is_too_short1_then_default()
+ {
+ var version = DocumentVersion.Parse("33");
+ Assert.That(version.ToString(), Is.EqualTo("33.0.0"));
+ }
+
+ [Test]
+ public void If_version_string_is_too_short2_then_default()
+ {
+ var version = DocumentVersion.Parse("42.27");
+ Assert.That(version.ToString(), Is.EqualTo("42.27.0"));
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Documents/Document_when_creating.cs b/Mongo.Migration.Tests/Documents/Document_when_creating.cs
new file mode 100644
index 0000000..69f588d
--- /dev/null
+++ b/Mongo.Migration.Tests/Documents/Document_when_creating.cs
@@ -0,0 +1,31 @@
+using Mongo.Migration.Documents;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Documents;
+
+[TestFixture]
+public class DocumentWhenCreating
+{
+ [Test]
+ public void Then_document_can_be_created()
+ {
+ // Arrange Act
+ Document document = new();
+
+ // Assert
+ Assert.That(document, Is.TypeOf());
+ }
+
+ [Test]
+ public void Then_document_has_a_version()
+ {
+ // Arrange
+ Document document = new();
+
+ // Act
+ var version = document.Version;
+
+ // Assert
+ Assert.That(version.ToString(), Is.EqualTo("0.0.0"));
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Documents/Locators/AttributeMigrationLocator_when_locate.cs b/Mongo.Migration.Tests/Documents/Locators/AttributeMigrationLocator_when_locate.cs
new file mode 100644
index 0000000..be8d6dd
--- /dev/null
+++ b/Mongo.Migration.Tests/Documents/Locators/AttributeMigrationLocator_when_locate.cs
@@ -0,0 +1,35 @@
+using Mongo.Migration.Documents.Locators;
+using Mongo.Migration.Tests.TestDoubles;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Documents.Locators;
+
+[TestFixture]
+internal class VersionLocatorWhenLocate
+{
+ [Test]
+ public void Then_find_current_version_of_document()
+ {
+ // Arrange
+ var locator = new RuntimeVersionLocator([]);
+
+ // Act
+ var currentVersion = locator.GetLocateOrNull(typeof(TestDocumentWithOneMigration));
+
+ // Assert
+ Assert.That(currentVersion.ToString(), Is.EqualTo("0.0.1"));
+ }
+
+ [Test]
+ public void When_document_has_no_attribute_Then_return_null()
+ {
+ // Arrange
+ var locator = new RuntimeVersionLocator([]);
+
+ // Act
+ var currentVersion = locator.GetLocateOrNull(typeof(TestDocumentWithoutAttribute));
+
+ // Assert
+ Assert.That(currentVersion, Is.Null);
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Documents/Serializers/DocumentVersionSerializer_when_serialize_and_deserialize.cs b/Mongo.Migration.Tests/Documents/Serializers/DocumentVersionSerializer_when_serialize_and_deserialize.cs
new file mode 100644
index 0000000..5a89afe
--- /dev/null
+++ b/Mongo.Migration.Tests/Documents/Serializers/DocumentVersionSerializer_when_serialize_and_deserialize.cs
@@ -0,0 +1,71 @@
+using Mongo.Migration.Documents;
+using Mongo.Migration.Documents.Serializers;
+using MongoDB.Bson;
+using MongoDB.Bson.IO;
+using MongoDB.Bson.Serialization;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Documents.Serializers;
+
+[TestFixture]
+public class DocumentVersionSerializerWhenSerializeAndDeserialize
+{
+ private DocumentVersionSerializer _serializer;
+
+ [Test]
+ public void Then_version_is_deserialized_correct()
+ {
+ // Arrange
+ var document = new BsonDocument { { "version", "0.1.1" } };
+ BsonDocumentReader reader = CreateVersionReader(document);
+
+ BsonDeserializationContext context = BsonDeserializationContext.CreateRoot(reader);
+ var args = new BsonDeserializationArgs { NominalType = typeof(DocumentVersion) };
+
+ // Act
+ DocumentVersion result = _serializer.Deserialize(context, args);
+
+ // Assert
+ Assert.That(result, Is.TypeOf());
+ Assert.That(result.ToString(), Is.EqualTo("0.1.1"));
+ }
+
+ [Test]
+ public void Then_version_is_serialized_correct()
+ {
+ // Arrange
+ BsonDocumentWriter writer = CreateVersionWriter();
+ BsonSerializationContext context = BsonSerializationContext.CreateRoot(writer);
+ var args = new BsonSerializationArgs { NominalType = typeof(DocumentVersion) };
+ var version = new DocumentVersion(0,0,1);
+
+ // Act
+ _serializer.Serialize(context, args, version);
+
+ // Assert
+ BsonDocument document = writer.Document;
+ Assert.That(document.ToString(), Is.EqualTo("{ \"version\" : \"0.0.1\" }"));
+ }
+
+ [SetUp]
+ public void SetUp()
+ {
+ _serializer = new();
+ }
+
+ private static BsonDocumentReader CreateVersionReader(BsonDocument document)
+ {
+ var reader = new BsonDocumentReader(document);
+ reader.ReadStartDocument();
+ reader.ReadName();
+ return reader;
+ }
+
+ private static BsonDocumentWriter CreateVersionWriter()
+ {
+ var writer = new BsonDocumentWriter([]);
+ writer.WriteStartDocument();
+ writer.WriteName("version");
+ return writer;
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/IntegrationTest.cs b/Mongo.Migration.Tests/IntegrationTest.cs
new file mode 100644
index 0000000..00ce512
--- /dev/null
+++ b/Mongo.Migration.Tests/IntegrationTest.cs
@@ -0,0 +1,27 @@
+using MongoDB.Bson;
+using MongoDB.Driver;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests;
+
+[TestFixture]
+public abstract class IntegrationTest
+{
+ private const string DatabaseName = "IntegrationTest";
+ private const string CollectionName = "Test";
+
+ [SetUp]
+ protected void SetUp()
+ {
+ IMongoClient client = TestcontainersContext.MongoClient;
+ client.GetDatabase(DatabaseName).GetCollection(CollectionName);
+ }
+
+ [TearDown]
+ protected async Task TearDownAsync()
+ {
+ IMongoClient client = TestcontainersContext.MongoClient;
+ await client.GetDatabase(DatabaseName)
+ .DropCollectionAsync(CollectionName);
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Migrations/Database/DatabaseIntegrationTest.cs b/Mongo.Migration.Tests/Migrations/Database/DatabaseIntegrationTest.cs
new file mode 100644
index 0000000..f1d6172
--- /dev/null
+++ b/Mongo.Migration.Tests/Migrations/Database/DatabaseIntegrationTest.cs
@@ -0,0 +1,48 @@
+using Mongo.Migration.Migrations.Database;
+using MongoDB.Bson;
+using MongoDB.Driver;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Migrations.Database;
+
+[TestFixture]
+internal abstract class DatabaseIntegrationTest
+{
+ private const string MigrationsCollectionName = "_migrations";
+
+ private IMongoDatabase? _db;
+ protected IMongoDatabase Db => _db ?? throw new InvalidOperationException("Must be setup");
+
+ protected virtual string DatabaseName { get; set; } = "DatabaseMigration";
+
+ protected virtual string CollectionName { get; set; } = "Test";
+
+ protected async Task OnSetUpAsync()
+ {
+ IMongoClient client = TestcontainersContext.MongoClient;
+ _db = client.GetDatabase(DatabaseName);
+ await _db.CreateCollectionAsync(CollectionName);
+ }
+
+ [TearDown]
+ public async Task TearDownAsync()
+ {
+ IMongoClient client = TestcontainersContext.MongoClient;
+ IMongoDatabase database = client.GetDatabase(DatabaseName);
+ await database.DropCollectionAsync(CollectionName);
+ await database.DropCollectionAsync(MigrationsCollectionName);
+ }
+
+ protected void InsertMigrations(IEnumerable migrations)
+ {
+ var list = migrations.Select(m => new BsonDocument { { "MigrationId", m.GetType().ToString() }, { "Version", m.Version.ToString() } });
+ Db.GetCollection(MigrationsCollectionName)
+ .InsertManyAsync(list).Wait();
+ }
+
+ protected List GetMigrationHistory()
+ {
+ var migrationHistoryCollection = Db.GetCollection(MigrationsCollectionName);
+ return migrationHistoryCollection.Find(m => true).ToList();
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Migrations/Database/DatabaseMigrationRunner_when_migrating_down.cs b/Mongo.Migration.Tests/Migrations/Database/DatabaseMigrationRunner_when_migrating_down.cs
new file mode 100644
index 0000000..0eef9c1
--- /dev/null
+++ b/Mongo.Migration.Tests/Migrations/Database/DatabaseMigrationRunner_when_migrating_down.cs
@@ -0,0 +1,56 @@
+using Microsoft.Extensions.DependencyInjection;
+using Mongo.Migration.Documents;
+using Mongo.Migration.Migrations.Database;
+using Mongo.Migration.Tests.TestDoubles.Database;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Migrations.Database;
+
+[TestFixture]
+internal class DatabaseMigrationRunnerWhenMigratingDown : DatabaseIntegrationTest
+{
+ [Test]
+ public async Task When_database_has_migrations_Then_down_all_migrations()
+ {
+ await OnSetUpAsync();
+ IDatabaseMigrationRunner runner = TestcontainersContext.Provider.GetRequiredService();
+
+ // Arrange
+ InsertMigrations(
+ [
+ new TestDatabaseMigration001(),
+ new TestDatabaseMigration002(),
+ new TestDatabaseMigration003()
+ ]);
+
+ // Act
+ await runner.RunAsync(Db, DocumentVersion.Default);
+
+ // Assert
+ var migrations = GetMigrationHistory();
+ Assert.That(migrations, Is.Empty);
+ }
+
+ [Test]
+ public async Task When_database_has_migrations_Then_down_to_selected_migration()
+ {
+ await OnSetUpAsync();
+ IDatabaseMigrationRunner runner = TestcontainersContext.Provider.GetRequiredService();
+
+ // Arrange
+ InsertMigrations(
+ [
+ new TestDatabaseMigration001(),
+ new TestDatabaseMigration002(),
+ new TestDatabaseMigration003()
+ ]);
+
+ // Act
+ await runner.RunAsync(Db, new DocumentVersion(0, 0, 1));
+
+ // Assert
+ List migrations = GetMigrationHistory();
+ Assert.That(migrations, Is.Not.Empty);
+ Assert.That(migrations, Has.One.Matches(m => m.Version == new DocumentVersion(0, 0, 1)));
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Migrations/Database/DatabaseMigrationRunner_when_migrating_up.cs b/Mongo.Migration.Tests/Migrations/Database/DatabaseMigrationRunner_when_migrating_up.cs
new file mode 100644
index 0000000..bea4bd8
--- /dev/null
+++ b/Mongo.Migration.Tests/Migrations/Database/DatabaseMigrationRunner_when_migrating_up.cs
@@ -0,0 +1,82 @@
+using Microsoft.Extensions.DependencyInjection;
+using Mongo.Migration.Documents;
+using Mongo.Migration.Migrations.Database;
+using Mongo.Migration.Tests.TestDoubles.Database;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Migrations.Database;
+
+[TestFixture]
+internal class DatabaseMigrationRunnerWhenMigratingUp : DatabaseIntegrationTest
+{
+ [Test]
+ public async Task When_database_has_no_migrations_Then_all_migrations_are_used()
+ {
+ // Arrange
+ await OnSetUpAsync();
+ IDatabaseMigrationRunner runner = TestcontainersContext.Provider.GetRequiredService();
+
+ // Act
+ await runner.RunAsync(Db, DocumentVersion.Empty);
+
+ // Assert
+ var migrations = GetMigrationHistory();
+
+ 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]
+ public async Task When_database_has_migrations_Then_latest_migrations_are_used()
+ {
+ // Arrange
+ await OnSetUpAsync();
+ IDatabaseMigrationRunner runner = TestcontainersContext.Provider.GetRequiredService();
+ InsertMigrations([new TestDatabaseMigration001(), new TestDatabaseMigration002()]);
+
+ // Act
+ await runner.RunAsync(Db, DocumentVersion.Empty);
+
+ // Assert
+ var migrations = GetMigrationHistory();
+
+ using (Assert.EnterMultipleScope())
+ {
+ Assert.That(migrations, Is.Not.Empty);
+ Assert.That(migrations[2].Version.ToString(), Is.EqualTo("0.0.3"));
+ }
+ }
+
+ [Test]
+ public async Task When_database_has_latest_version_Then_nothing_happens()
+ {
+ // Arrange
+ await OnSetUpAsync();
+ IDatabaseMigrationRunner runner = TestcontainersContext.Provider.GetRequiredService();
+ InsertMigrations(
+ [
+ new TestDatabaseMigration001(),
+ new TestDatabaseMigration002(),
+ new TestDatabaseMigration003()
+ ]);
+
+ // Act
+ await runner.RunAsync(Db, DocumentVersion.Empty, CancellationToken.None);
+
+ // Assert
+ var migrations = GetMigrationHistory();
+
+ 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"));
+ }
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Migrations/Database/DatabaseMigration_when_creating.cs b/Mongo.Migration.Tests/Migrations/Database/DatabaseMigration_when_creating.cs
new file mode 100644
index 0000000..25e9402
--- /dev/null
+++ b/Mongo.Migration.Tests/Migrations/Database/DatabaseMigration_when_creating.cs
@@ -0,0 +1,39 @@
+using Mongo.Migration.Migrations.Database;
+using Mongo.Migration.Tests.TestDoubles.Database;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Migrations.Database;
+
+[TestFixture]
+public class DatabaseMigrationWhenCreating
+{
+ [Test]
+ public void Then_migration_has_type_DatabaseMigration()
+ {
+ // Arrange Act
+ var migration = new TestDatabaseMigration001();
+
+ // Assert
+ Assert.That(migration.Type, Is.EqualTo(typeof(DatabaseMigration)));
+ }
+
+ [Test]
+ public void Then_migration_have_version()
+ {
+ // Arrange Act
+ var migration = new TestDatabaseMigration001();
+
+ // Assert
+ Assert.That(migration.Version.ToString(), Is.EqualTo("0.0.1"));
+ }
+
+ [Test]
+ public void Then_migration_should_be_created()
+ {
+ // Arrange Act
+ var migration = new TestDatabaseMigration001();
+
+ // Assert
+ Assert.That(migration, Is.TypeOf());
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_down.cs b/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_down.cs
new file mode 100644
index 0000000..ce7ed76
--- /dev/null
+++ b/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_down.cs
@@ -0,0 +1,55 @@
+using Microsoft.Extensions.DependencyInjection;
+using Mongo.Migration.Migrations.Document;
+using Mongo.Migration.Tests.TestDoubles;
+using MongoDB.Bson;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Migrations.Document;
+
+[TestFixture]
+internal class DocumentMigrationRunnerWhenMigratingDown : IntegrationTest
+{
+ [Test]
+ public void When_migrating_down_Then_all_migrations_are_used()
+ {
+ // Arrange
+ IDocumentMigrationRunner runner = TestcontainersContext.Provider.GetRequiredService();
+ BsonDocument document = new()
+ {
+ { "Version", "0.0.2" },
+ { "Door", 3 }
+ };
+
+ // Act
+ runner.Run(typeof(TestDocumentWithTwoMigration), document);
+
+ // Assert
+ 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]
+ public void When_document_has_Then_all_migrations_are_used_to_that_version()
+ {
+ // Arrange
+ IDocumentMigrationRunner runner = TestcontainersContext.Provider.GetRequiredService();
+ BsonDocument document = new()
+ {
+ { "Version", "0.0.2" },
+ { "Doors2", 3 }
+ };
+
+ // Act
+ runner.Run(typeof(TestDocumentWithTwoMigrationMiddleVersion), document);
+
+ // Assert
+ using (Assert.EnterMultipleScope())
+ {
+ Assert.That(document.Names.ToList()[1], Is.EqualTo("Doors1"));
+ Assert.That(document.Values.ToList()[0].AsString, Is.EqualTo("0.0.1"));
+ }
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_up.cs b/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_up.cs
new file mode 100644
index 0000000..1d775b0
--- /dev/null
+++ b/Mongo.Migration.Tests/Migrations/Document/DocumentMigrationRunner_when_migrating_up.cs
@@ -0,0 +1,76 @@
+using Microsoft.Extensions.DependencyInjection;
+using Mongo.Migration.Migrations.Document;
+using Mongo.Migration.Tests.TestDoubles;
+using MongoDB.Bson;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Migrations.Document;
+
+[TestFixture]
+internal class DocumentMigrationRunnerWhenMigratingUp : IntegrationTest
+{
+ [Test]
+ public void When_migrate_up_the_lowest_version_Then_all_migrations_are_used()
+ {
+ // Arrange
+ IDocumentMigrationRunner runner = TestcontainersContext.Provider.GetRequiredService();
+ BsonDocument document = new()
+ {
+ { "Version", "0.0.0" },
+ { "Dors", 3 }
+ };
+
+ // Act
+ runner.Run(typeof(TestDocumentWithTwoMigrationHighestVersion), document);
+
+ // Assert
+ 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]
+ public void When_document_has_no_version_Then_all_migrations_are_used()
+ {
+ // Arrange
+ IDocumentMigrationRunner runner = TestcontainersContext.Provider.GetRequiredService();
+ BsonDocument document = new()
+ {
+ { "Dors", 3 }
+ };
+
+ // Act
+ runner.Run(typeof(TestDocumentWithTwoMigrationHighestVersion), document);
+
+ // Assert
+ using (Assert.EnterMultipleScope())
+ {
+ Assert.That(document["Door"].AsInt32, Is.EqualTo(3));
+ Assert.That(document["Version"].AsString, Is.EqualTo("0.0.2"));
+ }
+ }
+
+ [Test]
+ public void When_document_has_current_version_Then_nothing_happens()
+ {
+ // Arrange
+ IDocumentMigrationRunner runner = TestcontainersContext.Provider.GetRequiredService();
+ BsonDocument document = new()
+ {
+ { "Version", "0.0.2" },
+ { "Door", 3 }
+ };
+
+ // Act
+ runner.Run(typeof(TestDocumentWithTwoMigrationHighestVersion), document);
+
+ // Assert
+ using (Assert.EnterMultipleScope())
+ {
+ Assert.That(document.Names.ToList()[1], Is.EqualTo("Door"));
+ Assert.That(document.Values.ToList()[0].AsString, Is.EqualTo("0.0.2"));
+ }
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Migrations/Document/DocumentMigration_when_creating.cs b/Mongo.Migration.Tests/Migrations/Document/DocumentMigration_when_creating.cs
new file mode 100644
index 0000000..d32c488
--- /dev/null
+++ b/Mongo.Migration.Tests/Migrations/Document/DocumentMigration_when_creating.cs
@@ -0,0 +1,38 @@
+using Mongo.Migration.Tests.TestDoubles;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Migrations.Document;
+
+[TestFixture]
+public class DocumentMigrationWhenCreating
+{
+ [Test]
+ public void Then_migration_has_type_testClass()
+ {
+ // Arrange Act
+ var migration = new TestDocumentWithOneMigration001();
+
+ // Assert
+ Assert.That(migration.Type, Is.EqualTo(typeof(TestDocumentWithOneMigration)));
+ }
+
+ [Test]
+ public void Then_migration_have_version()
+ {
+ // Arrange Act
+ var migration = new TestDocumentWithOneMigration001();
+
+ // Assert
+ Assert.That(migration.Version.ToString(), Is.EqualTo("0.0.1"));
+ }
+
+ [Test]
+ public void Then_migration_should_be_created()
+ {
+ // Arrange Act
+ var migration = new TestDocumentWithOneMigration001();
+
+ // Assert
+ Assert.That(migration, Is.TypeOf());
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Migrations/Document/DocumentMigration_when_migrating.cs b/Mongo.Migration.Tests/Migrations/Document/DocumentMigration_when_migrating.cs
new file mode 100644
index 0000000..f15b66d
--- /dev/null
+++ b/Mongo.Migration.Tests/Migrations/Document/DocumentMigration_when_migrating.cs
@@ -0,0 +1,65 @@
+using Mongo.Migration.Tests.TestDoubles;
+using MongoDB.Bson;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Migrations.Document;
+
+[TestFixture]
+public class DocumentMigrationWhenMigrating
+{
+ [Test]
+ public void When_migrating_down_Then_document_changes()
+ {
+ // Arrange
+ var migration = new TestDocumentWithOneMigration001();
+ var document = new BsonDocument { { "Doors", 3 } };
+
+ // Act
+ migration.Down(document);
+
+ // Assert
+ Assert.That(document, Is.EquivalentTo(new BsonDocument { { "Dors", 3 } }));
+ }
+
+ [Test]
+ public void When_migrating_up_Then_document_changes()
+ {
+ // Arrange
+ var migration = new TestDocumentWithOneMigration001();
+ var document = new BsonDocument { { "Dors", 3 } };
+
+ // Act
+ migration.Up(document);
+
+ // Assert
+ Assert.That(document, Is.EquivalentTo(new BsonDocument { { "Doors", 3 } }));
+ }
+
+ [Test]
+ public void When_version_as_string_migrating_down_Then_document_changes()
+ {
+ // Arrange
+ var migration = new TestClassWithTwoMigrationMiddleVersion001();
+ var document = new BsonDocument { { "Doors1", 3 } };
+
+ // Act
+ migration.Down(document);
+
+ // Assert
+ Assert.That(document, Is.EquivalentTo(new BsonDocument { { "Doors0", 3 } }));
+ }
+
+ [Test]
+ public void When_version_as_string_migrating_up_Then_document_changes()
+ {
+ // Arrange
+ var migration = new TestClassWithTwoMigrationMiddleVersion001();
+ var document = new BsonDocument { { "Doors0", 3 } };
+
+ // Act
+ migration.Up(document);
+
+ // Assert
+ Assert.That(document, Is.EquivalentTo(new BsonDocument { { "Doors1", 3 } }));
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Migrations/Interceptor/InterceptorTests.cs b/Mongo.Migration.Tests/Migrations/Interceptor/InterceptorTests.cs
new file mode 100644
index 0000000..36442e1
--- /dev/null
+++ b/Mongo.Migration.Tests/Migrations/Interceptor/InterceptorTests.cs
@@ -0,0 +1,162 @@
+using Microsoft.Extensions.DependencyInjection;
+using Mongo.Migration.Tests.TestDoubles;
+using MongoDB.Bson;
+using MongoDB.Driver;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Migrations.Interceptor;
+
+public class InterceptorMigrationWhenCreating : IntegrationTest
+{
+ private const string DatabaseName = "TestDatabase";
+ private const string CollectionName = "TestCollection";
+
+ [Test]
+ public async Task TestSerializationIntercepted()
+ {
+ IMongoCollection untypedCollection = GetCollection();
+ IMongoCollection testDocumentCollection =
+ GetCollection();
+
+ await testDocumentCollection.InsertOneAsync(new TestDocumentWithTwoMigrationMiddleVersion
+ {
+ Doors1 = 42
+ });
+
+ BsonDocument? documentInserted = await untypedCollection
+ .Find(Builders.Filter.Eq("Doors1", 42))
+ .FirstOrDefaultAsync();
+
+ Assert.That(documentInserted, Is.Not.Null);
+ Assert.That(documentInserted["Version"].AsString, Is.EqualTo("0.0.1"));
+ }
+
+ [Test]
+ public async Task TestDeserializationIntercepted()
+ {
+ IMongoCollection untypedCollection = GetCollection();
+ IMongoCollection testDocumentCollection =
+ GetCollection();
+
+ await untypedCollection.InsertManyAsync(
+ [
+ [
+ new("Doors0", new BsonInt32(0))
+ ],
+ [
+ new("Doors0", new BsonInt32(1)),
+ new("Version", new BsonString("0.0.0"))
+ ],
+ [
+ new("Doors1", new BsonInt32(2)),
+ new("Version", new BsonString("0.0.1"))
+ ],
+ [
+ new("Doors2", new BsonInt32(3)),
+ new("Version", new BsonString("0.0.2"))
+ ]
+ ]);
+
+ var asyncCursor = await testDocumentCollection
+ .FindAsync(FilterDefinition.Empty);
+ List documents = await asyncCursor.ToListAsync();
+
+ 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.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]
+ public async Task TestSerializationVersionAsStringIntercepted()
+ {
+ IMongoCollection untypedCollection = GetCollection();
+ IMongoCollection testDocumentCollection =
+ GetCollection();
+
+ await testDocumentCollection.InsertOneAsync(new TestClassWithTwoMigrationMiddleVersion
+ {
+ Doors1 = 42
+ });
+
+ BsonDocument? documentInserted = await untypedCollection
+ .Find(Builders.Filter.Eq("Doors1", 42))
+ .FirstOrDefaultAsync();
+
+ Assert.That(documentInserted, Is.Not.Null);
+ Assert.That(documentInserted["Version"].AsString, Is.EqualTo("0.0.1"));
+ }
+
+ [Test]
+ public async Task TestDeserializationVersionAsStringIntercepted()
+ {
+ IMongoCollection untypedCollection = GetCollection();
+ IMongoCollection testDocumentCollection =
+ GetCollection();
+
+ await untypedCollection.InsertManyAsync(
+ [
+ [
+ new("Doors0", new BsonInt32(0))
+ ],
+ [
+ new("Doors0", new BsonInt32(1)),
+ new("Version", new BsonString("0.0.0"))
+ ],
+ [
+ new("Doors1", new BsonInt32(2)),
+ new("Version", new BsonString("0.0.1"))
+ ],
+ [
+ new("Doors2", new BsonInt32(3)),
+ new("Version", new BsonString("0.0.2"))
+ ]
+ ]);
+
+ var asyncCursor = await testDocumentCollection
+ .FindAsync(FilterDefinition.Empty);
+ List documents = await asyncCursor.ToListAsync();
+
+ 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.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));
+ }
+ }
+
+
+ [SetUp]
+ public void SetUpLocal()
+ {
+ IMongoCollection _ = GetCollection();
+ }
+
+ [TearDown]
+ public async Task TearDownLocalAsync()
+ {
+ await GetCollection()
+ .DeleteManyAsync(d => true);
+ }
+
+ private static IMongoCollection GetCollection()
+ {
+ return TestcontainersContext.Provider.GetRequiredService()
+ .GetDatabase(DatabaseName)
+ .GetCollection(CollectionName);
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Migrations/Locators/TypeMigrationLocator_when_locate.cs b/Mongo.Migration.Tests/Migrations/Locators/TypeMigrationLocator_when_locate.cs
new file mode 100644
index 0000000..3c5669f
--- /dev/null
+++ b/Mongo.Migration.Tests/Migrations/Locators/TypeMigrationLocator_when_locate.cs
@@ -0,0 +1,81 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging.Abstractions;
+using Mongo.Migration.Documents;
+using Mongo.Migration.Migrations.Locators;
+using Mongo.Migration.Tests.TestDoubles;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Migrations.Locators;
+
+[TestFixture]
+public class TypeMigrationLocatorWhenLocate : IDisposable
+{
+ private readonly TypeMigrationLocator _locator;
+ private readonly ServiceProvider _serviceProvider;
+
+ public TypeMigrationLocatorWhenLocate()
+ {
+ _serviceProvider = new ServiceCollection().BuildServiceProvider();
+ _locator = new TypeMigrationLocator(NullLogger.Instance, _serviceProvider);
+ }
+
+ [Test]
+ public void When_document_has_one_migration_Then_migrations_count_should_be_one()
+ {
+ // Act
+ var result = _locator.GetMigrations(typeof(TestDocumentWithOneMigration));
+
+ // Assert
+ Assert.That(result, Has.Count.EqualTo(1));
+ }
+
+ [Test]
+ public void When_document_has_two_migration_Then_migrations_count_should_be_two()
+ {
+ // Act
+ var result = _locator.GetMigrations(typeof(TestDocumentWithTwoMigration));
+
+ // Assert
+ Assert.That(result, Has.Count.EqualTo(2));
+ }
+
+ [Test]
+ public void When_get_latest_version_of_migrations()
+ {
+ // Act
+ var version = _locator.GetLatestVersion(typeof(TestDocumentWithTwoMigration));
+
+ // Assert
+ Assert.That(version.ToString(), Is.EqualTo("0.0.2"));
+ }
+
+ [Test]
+ public void When_get_migrations_from_to()
+ {
+ // Act
+ var result = _locator
+ .GetMigrationsFromTo(typeof(TestDocumentWithTwoMigration), DocumentVersion.Default, DocumentVersion.Parse("0.0.1"))
+ .ToList();
+ // Assert
+ Assert.That(result, Has.Count.EqualTo(1));
+ Assert.That(result[0], Is.TypeOf());
+ }
+
+ [Test]
+ public void When_get_migrations_from_to_down()
+ {
+ // Act
+ var result = _locator
+ .GetMigrationsFromToDown(typeof(TestDocumentWithTwoMigration), DocumentVersion.Parse("0.0.2"), DocumentVersion.Parse("0.0.1"))
+ .ToList();
+ // Assert
+ Assert.That(result, Has.Count.EqualTo(1));
+ Assert.That(result[0], Is.TypeOf());
+ }
+
+ public void Dispose()
+ {
+ _serviceProvider.Dispose();
+ GC.SuppressFinalize(this);
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/Mongo.Migration.Tests.csproj b/Mongo.Migration.Tests/Mongo.Migration.Tests.csproj
new file mode 100644
index 0000000..69bc721
--- /dev/null
+++ b/Mongo.Migration.Tests/Mongo.Migration.Tests.csproj
@@ -0,0 +1,35 @@
+
+
+
+ net10.0;net8.0
+ 14.0
+ enable
+ enable
+ false
+ true
+ true
+ Exe
+ true
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/MongoDB/MongoRegistryTests.cs b/Mongo.Migration.Tests/MongoDB/MongoRegistryTests.cs
new file mode 100644
index 0000000..d93ca03
--- /dev/null
+++ b/Mongo.Migration.Tests/MongoDB/MongoRegistryTests.cs
@@ -0,0 +1,41 @@
+using Microsoft.Extensions.DependencyInjection;
+using Mongo.Migration.Bson;
+using Mongo.Migration.Documents;
+using Mongo.Migration.Documents.Serializers;
+using Mongo.Migration.Services;
+using Mongo.Migration.Tests.TestDoubles;
+using MongoDB.Bson;
+using MongoDB.Bson.Serialization;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.MongoDB;
+
+///
+/// Test that static serializers are registered (called from )
+///
+[TestFixture]
+internal class MongoRegistryTests : IntegrationTest
+{
+ [Test]
+ public void DocumentVersionSerializerIsRegistered()
+ {
+ Assert.That(
+ BsonSerializer.SerializerRegistry.GetSerializer(),
+ Is.TypeOf());
+ }
+
+ [Test]
+ public void MongoSerializerProviderIsRegistered()
+ {
+ Assert.That(
+ BsonSerializer.SerializerRegistry.GetSerializer(),
+ Is.TypeOf>());
+ }
+
+ [Test]
+ public void WhenInitializeTwiceThrows()
+ {
+ var migrationService = TestcontainersContext.Provider.GetRequiredService();
+ Assert.Throws(migrationService.RegisterBsonStatics);
+ }
+}
\ No newline at end of file
diff --git a/Mongo.Migration.Tests/MongoDB/VariousCrudOperations.cs b/Mongo.Migration.Tests/MongoDB/VariousCrudOperations.cs
new file mode 100644
index 0000000..9e1a044
--- /dev/null
+++ b/Mongo.Migration.Tests/MongoDB/VariousCrudOperations.cs
@@ -0,0 +1,136 @@
+using MongoDB.Bson;
+using MongoDB.Driver;
+using NUnit.Framework;
+using Mongo.Migration.Tests.TestDoubles;
+using MongoDB.Driver.Linq;
+
+namespace Mongo.Migration.Tests.MongoDB;
+
+[TestFixture]
+public class VariousCrudOperations
+{
+ private const string DatabaseName = "CrudTest";
+ private const string CollectionName = "TestDocumentWithOneMigration";
+ private IMongoCollection? _collection;
+
+ private IMongoCollection Collection => _collection ?? throw new InvalidOperationException();
+
+ [SetUp]
+ public void SetUp()
+ {
+ IMongoClient client = TestcontainersContext.MongoClient;
+ _collection = client.GetDatabase(DatabaseName)
+ .GetCollection(CollectionName);
+ }
+
+ [Test]
+ public async Task TestCreate()
+ {
+ var id = ObjectId.GenerateNewId();
+ var document = new TestDocumentWithOneMigration
+ {
+ Id = id,
+ Doors = 1
+ };
+
+ await Collection.InsertOneAsync(document);
+
+ var documentCreated = Collection.AsQueryable()
+ .Where(d => d.Id == id)
+ .Single();
+
+ Assert.That(documentCreated.Id, Is.EqualTo(id));
+ }
+
+ [Test]
+ public async Task TestRead()
+ {
+ var id = ObjectId.GenerateNewId();
+ var document = new TestDocumentWithOneMigration
+ {
+ Id = id,
+ Doors = 99
+ };
+
+ await Collection.InsertOneAsync(document);
+
+ var documentById = Collection.AsQueryable()
+ .Where(d => d.Id == id)
+ .Single();
+
+ var documentByExpression = Collection.AsQueryable()
+ .Where(d => d.Doors >= 98)
+ .Single();
+
+ using (Assert.EnterMultipleScope())
+ {
+ Assert.That(documentById.Id, Is.EqualTo(id));
+ Assert.That(documentByExpression.Id, Is.EqualTo(id));
+ }
+ }
+
+ [Test]
+ public async Task TestUpdate()
+ {
+ var id = ObjectId.GenerateNewId();
+ var document = new TestDocumentWithOneMigration
+ {
+ Id = id,
+ Doors = 7
+ };
+
+ await Collection.InsertOneAsync(document);
+
+ var documentCreated = Collection.AsQueryable()
+ .Where(d => d.Id == id)
+ .Single();
+
+ Assert.That(documentCreated.Id, Is.EqualTo(id));
+
+ var updateResult = await Collection.UpdateOneAsync(
+ Builders.Filter.Where(d => d.Id == id && d.Doors == 7),
+ Builders.Update
+ .Set(d => d.Doors, 8));
+
+ Assert.That(updateResult.MatchedCount, Is.EqualTo(1));
+
+ var documentUpdated = Collection.AsQueryable()
+ .Where(d => d.Id == id)
+ .Single();
+
+ using (Assert.EnterMultipleScope())
+ {
+ Assert.That(documentUpdated.Id, Is.EqualTo(id));
+ Assert.That(documentUpdated.Doors, Is.EqualTo(8));
+ }
+ }
+
+ [Test]
+ public async Task TestDelete()
+ {
+ var id = ObjectId.GenerateNewId();
+ var document = new TestDocumentWithOneMigration
+ {
+ Id = id,
+ Doors = 9
+ };
+
+ await Collection.InsertOneAsync(document);
+
+ var documentCreated = Collection.AsQueryable()
+ .Where(d => d.Id == id)
+ .Single();
+
+ Assert.That(documentCreated.Id, Is.EqualTo(id));
+
+ var deleteResult = await Collection.DeleteOneAsync(d => d.Id == id);
+
+ Assert.That(deleteResult.DeletedCount, Is.EqualTo(1));
+
+ var searchResult = await Collection.AsQueryable()
+ .Where(d => d.Id == id)
+ .ToListAsync();
+
+ Assert.That(searchResult, Is.Empty);
+ }
+}
diff --git a/Mongo.Migration.Tests/Performance/PerformanceOnStartup.cs b/Mongo.Migration.Tests/Performance/PerformanceOnStartup.cs
new file mode 100644
index 0000000..7581fbc
--- /dev/null
+++ b/Mongo.Migration.Tests/Performance/PerformanceOnStartup.cs
@@ -0,0 +1,109 @@
+using System.Diagnostics;
+using Microsoft.Extensions.DependencyInjection;
+using Mongo.Migration.Migrations.Document;
+using Mongo.Migration.Tests.TestDoubles;
+using MongoDB.Bson;
+using MongoDB.Driver;
+using NUnit.Framework;
+
+namespace Mongo.Migration.Tests.Performance;
+
+[TestFixture]
+public class PerformanceTestOnStartup
+{
+ private const int DocumentCount = 5000;
+
+ private const string DatabaseName = "PerformanceTest";
+
+ private const string CollectionName = "Test";
+
+ private const int ToleranceMs = 2800;
+
+ [Test]
+ public async Task When_migrating_number_of_documents()
+ {
+ // Arrange
+ // Worm up MongoCache
+ ClearCollection();
+ await AddDocumentsToCacheAsync();
+ ClearCollection();
+
+ // Act
+ // Measure time of MongoDb processing without Mongo.Migration
+ await InsertDocumentsAsync(DocumentCount);
+ var sw = new Stopwatch();
+ sw.Start();
+ var _ = await QueryAllAsync(false);
+ sw.Stop();
+
+ ClearCollection();
+
+ // Measure time of MongoDb processing with Mongo.Migration
+ IMongoClient client = TestcontainersContext.MongoClient;
+ await InsertDocumentsAsync(DocumentCount);
+ var swWithMigration = new Stopwatch();
+ swWithMigration.Start();
+
+ IStartUpDocumentMigrationRunner documentMigrationRunner =
+ TestcontainersContext.Provider.GetRequiredService();
+ await documentMigrationRunner.RunAllAsync(client.GetDatabase(DatabaseName), CancellationToken.None);
+ swWithMigration.Stop();
+
+ ClearCollection();
+
+ var result = swWithMigration.ElapsedMilliseconds - sw.ElapsedMilliseconds;
+
+ await TestContext.Out.WriteLineAsync($"MongoDB: {sw.ElapsedMilliseconds}ms, Mongo.Migration: {swWithMigration.ElapsedMilliseconds}ms, Diff: {result}ms (Tolerance: {ToleranceMs}ms), Documents: {DocumentCount}, Migrations per Document: 2");
+
+ // Assert
+ Assert.That(result, Is.LessThan(ToleranceMs));
+ }
+
+ private static Task InsertDocumentsAsync(int documentCount)
+ {
+ var documents = Enumerable
+ .Range(0, documentCount)
+ .Select(i => new BsonDocument
+ {
+ { "_id", new BsonObjectId(ObjectId.GenerateNewId())},
+ { "Dors", new BsonInt32(i) },
+ { "Version", BsonString.Create("0.0.0") }
+ });
+
+ return TestcontainersContext.MongoClient
+ .GetDatabase(DatabaseName)
+ .GetCollection(CollectionName)
+ .InsertManyAsync(documents);
+ }
+
+ private static async Task> QueryAllAsync(bool withVersion)
+ {
+ IMongoClient client = TestcontainersContext.MongoClient;
+
+ if (withVersion)
+ {
+ var versionedCollection = client.GetDatabase(DatabaseName)
+ .GetCollection(CollectionName);
+ var versionedResult = await (await versionedCollection.FindAsync(_ => true)).ToListAsync();
+ return [.. versionedResult.Cast