Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PendingPackageMigrationsTests.cs
Paul Johnson 00133e880d Move test projects from src/ to tests/ (#11357)
* Update gitignore

* Move csproj

* Update project references

* Update solutions

* Update build scripts

* Tests used to share editorconfig with projects in src

* Fix broken tests.

* Stop copying around .editorconfig

merged root one with linting

* csharp_style_expression_bodied -> suggestion

* Move StyleCop rulesets to matching directories and update shared build properties

* Remove legacy build files, update NuGet.cofig and solution files

* Restore myget source

* Clean up .gitignore

* Update .gitignore

* Move new test classes to tests after merge

* Gitignore + nuget config

* Move new test

Co-authored-by: Ronald Barendse <ronald@barend.se>
2021-10-18 08:14:04 +01:00

85 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Packaging;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Packaging
{
[TestFixture]
public class PendingPackageMigrationsTests
{
private static readonly Guid s_step1 = Guid.NewGuid();
private static readonly Guid s_step2 = Guid.NewGuid();
private const string TestPackageName = "Test1";
private class TestPackageMigrationPlan : PackageMigrationPlan
{
public TestPackageMigrationPlan() : base(TestPackageName)
{
}
protected override void DefinePlan()
{
To(s_step1);
To(s_step2);
}
}
private PendingPackageMigrations GetPendingPackageMigrations()
=> new PendingPackageMigrations(
Mock.Of<ILogger<PendingPackageMigrations>>(),
new PackageMigrationPlanCollection(() => new[]
{
new TestPackageMigrationPlan()
}));
[Test]
public void GivenNoRegisteredMigrations_ThenPlanIsReturned()
{
PendingPackageMigrations pendingPackageMigrations = GetPendingPackageMigrations();
var registeredMigrations = new Dictionary<string, string>();
IReadOnlyList<string> pending = pendingPackageMigrations.GetPendingPackageMigrations(registeredMigrations);
Assert.AreEqual(1, pending.Count);
}
[Test]
public void GivenRegisteredMigration_WhenFinalStepMatched_ThenNoneAreReturned()
{
PendingPackageMigrations pendingPackageMigrations = GetPendingPackageMigrations();
var registeredMigrations = new Dictionary<string, string>
{
[Constants.Conventions.Migrations.KeyValuePrefix + TestPackageName] = s_step2.ToString()
};
IReadOnlyList<string> pending = pendingPackageMigrations.GetPendingPackageMigrations(registeredMigrations);
Assert.AreEqual(0, pending.Count);
}
[Test]
public void GivenRegisteredMigration_WhenNonFinalStepMatched_ThenPlanIsReturned()
{
PendingPackageMigrations pendingPackageMigrations = GetPendingPackageMigrations();
var registeredMigrations = new Dictionary<string, string>
{
[Constants.Conventions.Migrations.KeyValuePrefix + TestPackageName] = s_step1.ToString()
};
IReadOnlyList<string> pending = pendingPackageMigrations.GetPendingPackageMigrations(registeredMigrations);
Assert.AreEqual(1, pending.Count);
}
[Test]
public void GivenRegisteredMigration_WhenStepIsDifferentCase_ThenPlanIsReturned()
{
PendingPackageMigrations pendingPackageMigrations = GetPendingPackageMigrations();
var registeredMigrations = new Dictionary<string, string>
{
[Constants.Conventions.Migrations.KeyValuePrefix + TestPackageName] = s_step1.ToString().ToUpper()
};
IReadOnlyList<string> pending = pendingPackageMigrations.GetPendingPackageMigrations(registeredMigrations);
Assert.AreEqual(1, pending.Count);
}
}
}