Files
Umbraco-CMS/src/Umbraco.Tests.Integration/Umbraco.Core/RuntimeStateTests.cs

103 lines
3.6 KiB
C#
Raw Normal View History

using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Packaging;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.Migrations;
using Umbraco.Cms.Infrastructure.Packaging;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core
{
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public class RuntimeStateTests : UmbracoIntegrationTest
{
private protected IRuntimeState RuntimeState { get; private set; }
public override void Configure(IApplicationBuilder app)
{
base.Configure(app);
RuntimeState = Services.GetRequiredService<IRuntimeState>();
}
protected override void CustomTestSetup(IUmbracoBuilder builder)
{
PackageMigrationPlanCollectionBuilder migrations = builder.PackageMigrationPlans();
migrations.Clear();
migrations.Add<TestMigrationPlan>();
}
[Test]
public void GivenPackageMigrationsExist_WhenLatestStateIsRegistered_ThenLevelIsRun()
{
// Add the final state to the keyvalue storage
IKeyValueService keyValueService = Services.GetRequiredService<IKeyValueService>();
keyValueService.SetValue(
Constants.Conventions.Migrations.KeyValuePrefix + TestMigrationPlan.TestMigrationPlanName,
TestMigrationPlan.TestMigrationFinalState.ToString());
RuntimeState.DetermineRuntimeLevel();
Assert.AreEqual(RuntimeLevel.Run, RuntimeState.Level);
Assert.AreEqual(RuntimeLevelReason.Run, RuntimeState.Reason);
}
[Test]
public void GivenPackageMigrationsExist_WhenUnattendedMigrations_ThenLevelIsRun()
{
RuntimeState.DetermineRuntimeLevel();
Assert.AreEqual(RuntimeLevel.Run, RuntimeState.Level);
Assert.AreEqual(RuntimeLevelReason.UpgradePackageMigrations, RuntimeState.Reason);
}
[Test]
Adjust the runtime state and keep disabling unattended package migrations simple (#10486) * Clean up and changes to backoffice for the nuget only packages * temp commit of package logic removal * Lots of package code cleanup and removal * Removes old package data from the test package xml * Updates packaging code to take in XDocument instead of a file since we'll not be dealing with files, starts creating expressions for the package migrations scripting. * fixing tests * Fixes runtime state and boot failed middleware so that it actually runs. Separates out unattended install/upgrade into notification handlers. * Gets unattended package migrations working and running * Gets embedded package.xml resources able to install from package migration. * Implements automatic package migrations for package that just declare an xml data manifest. * fix build * small cleanups * fix build * adds some tests * Fix export test * Fix newlines in test for linux * Typo * removes old todos and updates AutomaticPackgeMigrationPlan to use getter with backing field. * Update dictionary package data to use GUID * Ensures macros are packaged and used with their GUID * Ensures the GUID for doc types and media types remains consistent for package installation based on what is in the xml. * fix automatic migrations to not validate initial state, fixes packaging GUIDs for multiple entities. * Added guids to embedded test packages (Some tests are still failing) * Fix one more test * Fixes up Key vs Id, moves tests to correct namespace, fix tests * Fixes Dictionary packaging to ensure an xml hierarchy * Fixes tests * fixes package xml * Removes the runtime PackageMigrations state, the state is just run if unattended migrations are disabled. * change log level * Small clean up and reuse of attribute Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-06-17 18:00:49 +10:00
public void GivenPackageMigrationsExist_WhenNotUnattendedMigrations_ThenLevelIsRun()
{
var unattendedOptions = Services.GetRequiredService<IOptions<UnattendedSettings>>();
unattendedOptions.Value.PackageMigrationsUnattended = false;
RuntimeState.DetermineRuntimeLevel();
Adjust the runtime state and keep disabling unattended package migrations simple (#10486) * Clean up and changes to backoffice for the nuget only packages * temp commit of package logic removal * Lots of package code cleanup and removal * Removes old package data from the test package xml * Updates packaging code to take in XDocument instead of a file since we'll not be dealing with files, starts creating expressions for the package migrations scripting. * fixing tests * Fixes runtime state and boot failed middleware so that it actually runs. Separates out unattended install/upgrade into notification handlers. * Gets unattended package migrations working and running * Gets embedded package.xml resources able to install from package migration. * Implements automatic package migrations for package that just declare an xml data manifest. * fix build * small cleanups * fix build * adds some tests * Fix export test * Fix newlines in test for linux * Typo * removes old todos and updates AutomaticPackgeMigrationPlan to use getter with backing field. * Update dictionary package data to use GUID * Ensures macros are packaged and used with their GUID * Ensures the GUID for doc types and media types remains consistent for package installation based on what is in the xml. * fix automatic migrations to not validate initial state, fixes packaging GUIDs for multiple entities. * Added guids to embedded test packages (Some tests are still failing) * Fix one more test * Fixes up Key vs Id, moves tests to correct namespace, fix tests * Fixes Dictionary packaging to ensure an xml hierarchy * Fixes tests * fixes package xml * Removes the runtime PackageMigrations state, the state is just run if unattended migrations are disabled. * change log level * Small clean up and reuse of attribute Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-06-17 18:00:49 +10:00
Assert.AreEqual(RuntimeLevel.Run, RuntimeState.Level);
Assert.AreEqual(RuntimeLevelReason.Run, RuntimeState.Reason);
}
private class TestMigrationPlan : PackageMigrationPlan
{
public const string TestMigrationPlanName = "Test";
public static Guid TestMigrationFinalState => new Guid("BB02C392-4007-4A6C-A550-28BA2FF7E43D");
public TestMigrationPlan() : base(TestMigrationPlanName)
{
}
protected override void DefinePlan()
{
To<TestMigration>(TestMigrationFinalState);
}
}
private class TestMigration : PackageMigrationBase
{
public TestMigration(IPackagingService packagingService, IMigrationContext context)
: base(packagingService, context)
{
}
public override void Migrate()
{
ImportPackage.FromEmbeddedResource<TestMigration>().Do();
}
}
}
}