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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build and Publish NuGet

on:
release:
types: [published]
workflow_dispatch:
push:

jobs:
build-and-publish:
runs-on: ubuntu-latest

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

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "6.0.x"

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

# - name: Test
# run: dotnet test --configuration Release --no-build --verbosity normal

- name: Pack
run: dotnet pack --configuration Release --no-build --output ./artifacts

- name: Publish to GitHub Packages
run: dotnet nuget push ./artifacts/*.nupkg --source https://nuget.pkg.github.com/cactusoft-ca/index.json --api-key ${{ secrets.GITHUB_TOKEN }}
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65 changes: 23 additions & 42 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
## A streamlined .gitignore for modern .NET projects
## including temporary files, build results, and
## files generated by popular .NET tools. If you are
## developing with Visual Studio, the VS .gitignore
## https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
## has more thorough IDE-specific entries.
##
## Get latest from https://github.com/github/gitignore/blob/main/Dotnet.gitignore
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
nupkg/
.idea/

# Visual Studio Code
.vscode

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
[Dd]ebug/
Expand All @@ -14,41 +22,14 @@
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
build/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/

# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/

# ASP.NET Scaffolding
ScaffoldingReadMe.txt

# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg

# Others
~$*
*~
CodeCoverage/

# MSBuild Binary and Structured Log
*.binlog

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
[Oo]ut/
msbuild.log
msbuild.err
msbuild.wrn

# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Visual Studio 2015
.vs/
25 changes: 25 additions & 0 deletions MIT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The MIT License (MIT)
=====================

Copyright © `2018` `Arthur Osmokiesku`

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, 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.
62 changes: 62 additions & 0 deletions MongoDBMigrations.SmokeTests/ComplexMigrationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MongoDB.Bson;
using MongoDB.Driver;

namespace MongoDBMigrations.SmokeTests
{
[TestClass]
public class ComplexMigrationTests
{
MongoDaemon.ConnectionInfo _daemon;

[TestInitialize]
public void SetUp() {
_daemon = MongoDaemon.Prepare();

var db = new MongoClient(_daemon.ConnectionString).GetDatabase(_daemon.DatabaseName);
//Create test collection with some data
db.CreateCollection("clients");
db.GetCollection<BsonDocument>("clients")
.InsertMany(new[]{
new BsonDocument{ {"name", "Alex"}, {"age", 17}},
new BsonDocument{ {"name", "Max"}, {"age", 25}}
});

//Run up to the latest migration
new MigrationEngine()
.UseDatabase(_daemon.ConnectionString, _daemon.DatabaseName)
.UseAssembly(Assembly.GetExecutingAssembly())
.UseSchemeValidation(false)
.Run();
}

[TestCleanup]
public void TearDown()
{
_daemon.Dispose();
}

[TestMethod]
public void SawLikeMigrationDownAndThenUp()
{
var downTarget = new Version("1.0.0");
var downMigrationResult = new MigrationEngine()
.UseDatabase(_daemon.ConnectionString, _daemon.DatabaseName)
.UseAssembly(Assembly.GetExecutingAssembly())
.UseSchemeValidation(false)
.Run(downTarget);

Assert.AreEqual(downTarget, downMigrationResult.CurrentVersion);
Assert.IsTrue(downMigrationResult.Success);

var upMigrationResult = new MigrationEngine()
.UseDatabase(_daemon.ConnectionString, _daemon.DatabaseName)
.UseAssembly(Assembly.GetExecutingAssembly())
.UseSchemeValidation(false)
.Run();

Assert.IsTrue(upMigrationResult.Success);
}
}
}
62 changes: 62 additions & 0 deletions MongoDBMigrations.SmokeTests/DatabaseCheckerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MongoDB.Bson;
using MongoDB.Driver;

namespace MongoDBMigrations.SmokeTests
{
[TestClass]
public class DatabaseCheckerTests
{
MongoDaemon.ConnectionInfo _daemon;

[TestInitialize]
public void SetUp()
{
_daemon = MongoDaemon.Prepare();

var db = new MongoClient(_daemon.ConnectionString).GetDatabase(_daemon.DatabaseName);
//Create test collection with some data
db.CreateCollection("clients");
db.GetCollection<BsonDocument>("clients")
.InsertMany(new[]{
new BsonDocument{ {"name", "Alex"}, {"age", 17}},
new BsonDocument{ {"name", "Max"}, {"age", 25}}
});
}

[TestCleanup]
public void TearDown()
{
_daemon.Dispose();
}

[TestMethod]
public void IsDatabaseOutdatedShouldReturnTrue()
{
var result = MongoDatabaseStateChecker.IsDatabaseOutdated(_daemon.ConnectionString, _daemon.DatabaseName, typeof(DatabaseCheckerTests).Assembly);
Assert.IsTrue(result);
}

[TestMethod]
public void IsDatabaseOutdatedShoudReturnFalse()
{
var target = new Version("1.1.0");
new MigrationEngine()
.UseDatabase(_daemon.ConnectionString, _daemon.DatabaseName)
.UseAssembly(Assembly.GetExecutingAssembly())
.UseSchemeValidation(false)
.Run(target);

var result = MongoDatabaseStateChecker.IsDatabaseOutdated(_daemon.ConnectionString, _daemon.DatabaseName, typeof(DatabaseCheckerTests).Assembly);
Assert.IsFalse(result);
}

[TestMethod]
[ExpectedException(typeof(DatabaseOutdatedExcetion))]
public void ThrowIfDatabaseOutdatedShouldThrowException()
{
MongoDatabaseStateChecker.ThrowIfDatabaseOutdated(_daemon.ConnectionString, _daemon.DatabaseName, typeof(DatabaseCheckerTests).Assembly);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using MongoDB.Bson;
using MongoDB.Driver;

namespace MongoDBMigrations.SmokeTests.Migrations
{
public class _1_0_0_FirstMigrationTest : IMigration
{
public Version Version => new Version(1, 0, 0);

public string Name => "Changing column name";

public void Down(MigrationContext context)
{
var collection = context.Database.GetCollection<BsonDocument>("clients");
collection.UpdateMany(FilterDefinition<BsonDocument>.Empty,
Builders<BsonDocument>.Update.Rename("firstName", "name"));
}

public void Up(MigrationContext context)
{
var collection = context.Database.GetCollection<BsonDocument>("clients");
collection.UpdateMany(FilterDefinition<BsonDocument>.Empty,
Builders<BsonDocument>.Update.Rename("name", "firstName"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using MongoDB.Bson;
using MongoDB.Driver;

namespace MongoDBMigrations.SmokeTests.Migrations
{
public class _1_1_0_SecondMigrationTest : IMigration
{
public Version Version => new Version(1, 1, 0);

public string Name => "Changing type of age type";

public void Down(MigrationContext context)
{
var collection = context.Database.GetCollection<BsonDocument>("clients");
var list = collection.Find(FilterDefinition<BsonDocument>.Empty).ToList();
FieldDefinition<BsonDocument, int> fieldDefenition = "age";
foreach (var item in list)
{
collection.UpdateOne(new BsonDocument("_id", item["_id"]),
Builders<BsonDocument>.Update.Set(fieldDefenition, item["age"].ToInt32()));
}
}

public void Up(MigrationContext context)
{
var collection = context.Database.GetCollection<BsonDocument>("clients");
var list = collection.Find(FilterDefinition<BsonDocument>.Empty).ToList();
FieldDefinition<BsonDocument, string> fieldDefenition = "age";
foreach (var item in list)
{
collection.UpdateOne(new BsonDocument("_id", item["_id"]),
Builders<BsonDocument>.Update.Set(fieldDefenition, item["age"].ToString()));
}
}
}
}
31 changes: 31 additions & 0 deletions MongoDBMigrations.SmokeTests/MongoDBMigrations.SmokeTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>

<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Mongo2Go" Version="3.1.3" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
</ItemGroup>

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

<ItemGroup>
<None Update="local.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<IncludeInPackage>true</IncludeInPackage>
</None>
</ItemGroup>

</Project>
Loading