Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/ComponentRuntimeTests.cs
Sven Geusens c8e054baa2 V10/feature/pipeline test filters (#14766)
* Add configuration/code to not run certain tests based on variables/release builds

* Applied longrunning testAttribute to the worst offenders (>200ms on my machine)

* Fix yaml notation

* split up windows/non windows test runs

* Added supression for moved tests

* Fix yaml validation issues

* Change yaml string parameter null value to empty string

* Convert empty strings to whitespace strings

* Rename and cleanup some paramater to better reflect why we use them

* Nightly build test

* Change nightly build authentication type

* template paramater fix

* Update nightly pipeline name

---------

Co-authored-by: Sven Geusens <sge@umbraco.dk>
2023-09-12 14:16:27 +02:00

66 lines
2.2 KiB
C#

using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Runtime;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Tests.Common.Attributes;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
namespace Umbraco.Cms.Tests.Integration;
[TestFixture]
[UmbracoTest(Boot = true)]
public class ComponentRuntimeTests : UmbracoIntegrationTest
{
// ensure composers are added
protected override void CustomTestSetup(IUmbracoBuilder builder) => builder.AddComposers();
/// <summary>
/// This will boot up umbraco with components enabled to show they initialize and shutdown
/// </summary>
[Test]
[LongRunning]
public async Task Start_And_Stop_Umbraco_With_Components_Enabled()
{
var runtime = Services.GetRequiredService<IRuntime>();
var runtimeState = Services.GetRequiredService<IRuntimeState>();
var mainDom = Services.GetRequiredService<IMainDom>();
var components = Services.GetRequiredService<ComponentCollection>();
var myComponent = components.OfType<MyComponent>().First();
Assert.IsTrue(mainDom.IsMainDom);
Assert.IsNull(runtimeState.BootFailedException);
Assert.IsTrue(myComponent.IsInit, "The component was not initialized");
// force stop now
await runtime.StopAsync(CancellationToken.None);
Assert.IsTrue(myComponent.IsTerminated, "The component was not terminated");
}
public class MyComposer : IComposer
{
public void Compose(IUmbracoBuilder builder) => builder.Components().Append<MyComponent>();
}
public class MyComponent : IComponent
{
private readonly ILogger<MyComponent> _logger;
public MyComponent(ILogger<MyComponent> logger) => _logger = logger;
public bool IsInit { get; private set; }
public bool IsTerminated { get; private set; }
public void Initialize() => IsInit = true;
public void Terminate() => IsTerminated = true;
}
}