* Run code cleanup * Dotnet format benchmarks project * Fix up Test.Common * Run dotnet format + manual cleanup * Run code cleanup for unit tests * Run dotnet format * Fix up errors * Manual cleanup of Unit test project * Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix according to review * Fix after merge * Fix errors Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
82 lines
2.8 KiB
C#
82 lines
2.8 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(
|
|
Mock.Of<ILogger<PendingPackageMigrations>>(),
|
|
new PackageMigrationPlanCollection(() => new[] { new TestPackageMigrationPlan() }));
|
|
|
|
[Test]
|
|
public void GivenNoRegisteredMigrations_ThenPlanIsReturned()
|
|
{
|
|
var pendingPackageMigrations = GetPendingPackageMigrations();
|
|
var registeredMigrations = new Dictionary<string, string>();
|
|
var pending = pendingPackageMigrations.GetPendingPackageMigrations(registeredMigrations);
|
|
Assert.AreEqual(1, pending.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void GivenRegisteredMigration_WhenFinalStepMatched_ThenNoneAreReturned()
|
|
{
|
|
var pendingPackageMigrations = GetPendingPackageMigrations();
|
|
var registeredMigrations = new Dictionary<string, string>
|
|
{
|
|
[Constants.Conventions.Migrations.KeyValuePrefix + TestPackageName] = s_step2.ToString(),
|
|
};
|
|
var pending = pendingPackageMigrations.GetPendingPackageMigrations(registeredMigrations);
|
|
Assert.AreEqual(0, pending.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void GivenRegisteredMigration_WhenNonFinalStepMatched_ThenPlanIsReturned()
|
|
{
|
|
var pendingPackageMigrations = GetPendingPackageMigrations();
|
|
var registeredMigrations = new Dictionary<string, string>
|
|
{
|
|
[Constants.Conventions.Migrations.KeyValuePrefix + TestPackageName] = s_step1.ToString(),
|
|
};
|
|
var pending = pendingPackageMigrations.GetPendingPackageMigrations(registeredMigrations);
|
|
Assert.AreEqual(1, pending.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void GivenRegisteredMigration_WhenStepIsDifferentCase_ThenPlanIsReturned()
|
|
{
|
|
var pendingPackageMigrations = GetPendingPackageMigrations();
|
|
var registeredMigrations = new Dictionary<string, string>
|
|
{
|
|
[Constants.Conventions.Migrations.KeyValuePrefix + TestPackageName] = s_step1.ToString().ToUpper(),
|
|
};
|
|
var pending = pendingPackageMigrations.GetPendingPackageMigrations(registeredMigrations);
|
|
Assert.AreEqual(1, pending.Count);
|
|
}
|
|
}
|