Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Extensions/UmbracoBuilderExtensionsTests.cs
Nikolaj Geisle 7aeb400fce V10: fix build warnings in test projects (#12509)
* 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>
2022-06-21 08:09:38 +02:00

102 lines
3.1 KiB
C#

using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
using AutoFixture.NUnit3;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Extensions;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Logging;
using Umbraco.Cms.Core.Notifications;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Extensions;
[TestFixture]
public class UmbracoBuilderExtensionsTests
{
[Test]
[Customization]
public void AddNotificationsFromAssembly_Should_AddNotificationHandler_To_ServicesCollection(IUmbracoBuilder sut)
{
sut.AddNotificationsFromAssembly<CustomizationAttribute>();
var expectedHandlerType = typeof(INotificationHandler<ContentPublishedNotification>);
var handler = sut.Services.SingleOrDefault(x => x.ServiceType == expectedHandlerType);
Assert.NotNull(handler);
Assert.That(handler.ImplementationType, Is.EqualTo(typeof(StubNotificationHandler)));
}
[Test]
[Customization]
public void AddNotificationsFromAssembly_Should_AddAsyncNotificationHandler_To_ServicesCollection(
IUmbracoBuilder sut)
{
sut.AddNotificationsFromAssembly<CustomizationAttribute>();
var expectedHandlerType = typeof(INotificationAsyncHandler<ContentPublishedNotification>);
var handler = sut.Services.SingleOrDefault(x => x.ServiceType == expectedHandlerType);
Assert.NotNull(handler);
Assert.That(handler.ImplementationType, Is.EqualTo(typeof(StubNotificationHandler)));
}
private class CustomizationAttribute : AutoDataAttribute
{
public CustomizationAttribute()
: base(() =>
{
var fixture = new Fixture();
var stub = new UmbracoBuildStub();
fixture.Inject((IUmbracoBuilder)stub);
return fixture;
})
{
}
}
private class UmbracoBuildStub : IUmbracoBuilder
{
public UmbracoBuildStub() => Services = new ServiceCollection();
public IServiceCollection Services { get; }
public IConfiguration Config { get; }
public TypeLoader TypeLoader { get; }
public ILoggerFactory BuilderLoggerFactory { get; }
public IHostingEnvironment BuilderHostingEnvironment { get; }
public IProfiler Profiler { get; }
public AppCaches AppCaches { get; }
public TBuilder WithCollectionBuilder<TBuilder>()
where TBuilder : ICollectionBuilder => default;
public void Build()
{
}
}
private class StubNotificationHandler
: INotificationHandler<ContentPublishedNotification>,
INotificationAsyncHandler<ContentPublishedNotification>
{
public Task HandleAsync(ContentPublishedNotification notification, CancellationToken cancellationToken) => Task.CompletedTask;
public void Handle(ContentPublishedNotification notification)
{
}
}
}