From 534b74dda5bcc3bfa7073221303b6536edb3a618 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 23 Dec 2020 13:57:41 +1100 Subject: [PATCH] Changes CustomTestSetup to just be a normal method, not sure why it was an action, fixes ContentEventsTests which requires NuCache --- .../Testing/UmbracoTestAttribute.cs | 3 +-- .../Testing/UmbracoIntegrationTest.cs | 5 ++-- .../Scoping/ScopedRepositoryTests.cs | 7 ++--- .../Services/ContentEventsTests.cs | 26 ++++++------------- ...kOfficeServiceCollectionExtensionsTests.cs | 7 +++-- 5 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/Umbraco.Tests.Common/Testing/UmbracoTestAttribute.cs b/src/Umbraco.Tests.Common/Testing/UmbracoTestAttribute.cs index f5983ddca6..4c1101d6f1 100644 --- a/src/Umbraco.Tests.Common/Testing/UmbracoTestAttribute.cs +++ b/src/Umbraco.Tests.Common/Testing/UmbracoTestAttribute.cs @@ -24,9 +24,8 @@ namespace Umbraco.Tests.Testing public bool Mapper { get => _mapper.ValueOrDefault(WithApplication); set => _mapper.Set(value); } private readonly Settable _mapper = new Settable(); - // FIXME: to be completed /// - /// Gets or sets a value indicating ... + /// Gets or sets a value indicating whether the LEGACY XML Cache used in tests should bind to repository events /// public bool PublishedRepositoryEvents { get => _publishedRepositoryEvents.ValueOrDefault(false); set => _publishedRepositoryEvents.Set(value); } private readonly Settable _publishedRepositoryEvents = new Settable(); diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 3d50e72b9a..d8f27d27a7 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -25,6 +25,7 @@ using Umbraco.Core.Runtime; using Umbraco.Core.Scoping; using Umbraco.Core.Strings; using Umbraco.Extensions; +using Umbraco.Infrastructure.PublishedCache.DependencyInjection; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Extensions; using Umbraco.Tests.Integration.Implementations; @@ -232,7 +233,7 @@ namespace Umbraco.Tests.Integration.Testing builder.Build(); - CustomTestSetup(services); + CustomTestSetup(builder); } protected virtual AppCaches GetAppCaches() @@ -402,7 +403,7 @@ namespace Umbraco.Tests.Integration.Testing public TestHelper TestHelper { get; } = new TestHelper(); - protected virtual Action CustomTestSetup => services => { }; + protected virtual void CustomTestSetup(IUmbracoBuilder builder) { } /// /// Returns the DI container diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs index 5542f926e1..f5301fb7f6 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.DependencyInjection; @@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using NUnit.Framework; using Umbraco.Core.Cache; +using Umbraco.Core.DependencyInjection; using Umbraco.Core.Events; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; @@ -31,8 +32,8 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Scoping private IServerMessenger ServerMessenger => GetRequiredService(); private CacheRefresherCollection CacheRefresherCollection => GetRequiredService(); - protected override Action CustomTestSetup => (services) - => services.Replace(ServiceDescriptor.Singleton(typeof(IServerMessenger), typeof(LocalServerMessenger))); + protected override void CustomTestSetup(IUmbracoBuilder builder) + => builder.Services.Replace(ServiceDescriptor.Singleton(typeof(IServerMessenger), typeof(LocalServerMessenger))); protected override AppCaches GetAppCaches() { diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEventsTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEventsTests.cs index d5f9f41cbb..80bf464c31 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEventsTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEventsTests.cs @@ -1,17 +1,20 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Logging; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; -using Microsoft.Extensions.Logging; +using Umbraco.Core.DependencyInjection; using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Sync; +using Umbraco.Infrastructure.PublishedCache.DependencyInjection; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.Testing; using Umbraco.Web; +using Umbraco.Web.BackOffice.DependencyInjection; using Umbraco.Web.Cache; namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Services @@ -21,14 +24,13 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Services public class ContentEventsTests : UmbracoIntegrationTestWithContent { private CacheRefresherCollection CacheRefresherCollection => GetRequiredService(); + private IUmbracoContextFactory UmbracoContextFactory => GetRequiredService(); + private ILogger Logger => GetRequiredService>(); #region Setup - // trace ContentRepository unit-of-work events (refresh, remove), and ContentCacheRefresher CacheUpdated event - // - [SetUp] public void SetUp() { @@ -52,19 +54,7 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Services ContentTypeService.Save(_contentType); } - // protected override void Compose() - // { - // base.Compose(); - // - // Composition.Register(_ => new TestServerRegistrar()); // localhost-only - // composition.Services.AddUnique(); - // - // Composition.WithCollectionBuilder() - // .Add() - // .Add() - // .Add(); - // } - + protected override void CustomTestSetup(IUmbracoBuilder builder) => builder.AddNuCache(); [TearDown] public void TearDownTest() diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UmbracoBackOfficeServiceCollectionExtensionsTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UmbracoBackOfficeServiceCollectionExtensionsTests.cs index b942e57e46..37863da472 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UmbracoBackOfficeServiceCollectionExtensionsTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UmbracoBackOfficeServiceCollectionExtensionsTests.cs @@ -1,17 +1,18 @@ -using System; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Umbraco.Core.DependencyInjection; using Umbraco.Core.Security; using Umbraco.Tests.Integration.Testing; using Umbraco.Web.BackOffice.DependencyInjection; -using Umbraco.Web.Common.Security; namespace Umbraco.Tests.Integration.Umbraco.Web.BackOffice { [TestFixture] public class UmbracoBackOfficeServiceCollectionExtensionsTests : UmbracoIntegrationTest { + protected override void CustomTestSetup(IUmbracoBuilder builder) => builder.Services.AddUmbracoBackOfficeIdentity(); + [Test] public void AddUmbracoBackOfficeIdentity_ExpectBackOfficeUserStoreResolvable() { @@ -37,7 +38,5 @@ namespace Umbraco.Tests.Integration.Umbraco.Web.BackOffice Assert.NotNull(userManager); } - - protected override Action CustomTestSetup => (services) => services.AddUmbracoBackOfficeIdentity(); } }