Files
Umbraco-CMS/src/Umbraco.Tests.Integration/ComponentRuntimeTests.cs
Mole bf41c2eeaa Netcore: Align namespaces (#9801)
* Rename Umbraco.Core namespace to Umbraco.Cms.Core

* Move extension methods in core project to Umbraco.Extensions

* Move extension methods in core project to Umbraco.Extensions

* Rename Umbraco.Examine namespace to Umbraco.Cms.Examine

* Move examine extensions to Umbraco.Extensions namespace

* Reflect changed namespaces in Builder and fix unit tests

* Adjust namespace in Umbraco.ModelsBuilder.Embedded

* Adjust namespace in Umbraco.Persistence.SqlCe

* Adjust namespace in Umbraco.PublishedCache.NuCache

* Align namespaces in Umbraco.Web.BackOffice

* Align namespaces in Umbraco.Web.Common

* Ensure that SqlCeSupport is still enabled after changing the namespace

* Align namespaces in Umbraco.Web.Website

* Align namespaces in Umbraco.Web.UI.NetCore

* Align namespaces in Umbraco.Tests.Common

* Align namespaces in Umbraco.Tests.UnitTests

* Align namespaces in Umbraco.Tests.Integration

* Fix errors caused by changed namespaces

* Fix integration tests

* Undo the Umbraco.Examine.Lucene namespace change

This breaks integration tests on linux, since the namespace wont exists there because it's only used on windows.

* Fix merge

* Fix Merge
2021-02-18 11:06:02 +01:00

67 lines
2.3 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.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]
public async Task Start_And_Stop_Umbraco_With_Components_Enabled()
{
IRuntime runtime = Services.GetRequiredService<IRuntime>();
IRuntimeState runtimeState = Services.GetRequiredService<IRuntimeState>();
IMainDom mainDom = Services.GetRequiredService<IMainDom>();
ComponentCollection components = Services.GetRequiredService<ComponentCollection>();
MyComponent 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 : IUserComposer
{
public void Compose(IUmbracoBuilder builder) => builder.Components().Append<MyComponent>();
}
public class MyComponent : IComponent
{
public bool IsInit { get; private set; }
public bool IsTerminated { get; private set; }
private readonly ILogger<MyComponent> _logger;
public MyComponent(ILogger<MyComponent> logger) => _logger = logger;
public void Initialize() => IsInit = true;
public void Terminate() => IsTerminated = true;
}
}
}