diff --git a/src/Umbraco.Infrastructure/BackOffice/IdentityAuditEventArgs.cs b/src/Umbraco.Infrastructure/BackOffice/IdentityAuditEventArgs.cs index cb0b04ef56..1991f248f1 100644 --- a/src/Umbraco.Infrastructure/BackOffice/IdentityAuditEventArgs.cs +++ b/src/Umbraco.Infrastructure/BackOffice/IdentityAuditEventArgs.cs @@ -3,7 +3,7 @@ using System.Threading; using Umbraco.Extensions; -namespace Umbraco.Web.BackOffice.Identity +namespace Umbraco.Core.BackOffice { /// /// This class is used by events raised from the BackofficeUserManager @@ -108,9 +108,9 @@ namespace Umbraco.Web.BackOffice.Identity protected int GetCurrentRequestBackofficeUserId() { var userId = -1; - var backOfficeIdentity = Thread.CurrentPrincipal.GetUmbracoIdentity(); + /*var backOfficeIdentity = Thread.CurrentPrincipal.GetUmbracoIdentity(); if (backOfficeIdentity != null) - int.TryParse(backOfficeIdentity.Id.ToString(), out userId); + int.TryParse(backOfficeIdentity.Id.ToString(), out userId);*/ return userId; } } diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index a38e002810..8f9ec4d833 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -109,6 +109,8 @@ namespace Umbraco.Tests.Integration.Testing // Add it! services.AddUmbracoConfiguration(hostContext.Configuration); services.AddUmbracoCore(webHostEnvironment, umbracoContainer, GetType().Assembly, NoAppCache.Instance, testHelper.GetLoggingConfiguration(), out _); + + CustomTestSetup(services); }); var host = await hostBuilder.StartAsync(); @@ -123,6 +125,8 @@ namespace Umbraco.Tests.Integration.Testing #region Common services + protected virtual Action CustomTestSetup => services => { }; + /// /// Returns the DI container /// diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UmbracoBackOfficeServiceCollectionExtensionsTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UmbracoBackOfficeServiceCollectionExtensionsTests.cs new file mode 100644 index 0000000000..3b61f31b66 --- /dev/null +++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/UmbracoBackOfficeServiceCollectionExtensionsTests.cs @@ -0,0 +1,40 @@ +using System; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Moq; +using NUnit.Framework; +using Umbraco.Extensions; +using Umbraco.Core.BackOffice; +using Umbraco.Core.Cache; +using Umbraco.Core.Composing; +using Umbraco.Tests.Integration.Extensions; +using Umbraco.Tests.Integration.Implementations; +using Umbraco.Tests.Integration.Testing; + +namespace Umbraco.Tests.UnitTests.Umbraco.Web.BackOffice.Extensions +{ + [TestFixture] + public class UmbracoBackOfficeServiceCollectionExtensionsTests : UmbracoIntegrationTest + { + [Test] + public void AddUmbracoBackOfficeIdentity_ExpectBackOfficeUserStoreResolvable() + { + var userStore = Services.GetService>(); + + Assert.IsNotNull(userStore); + Assert.AreEqual(typeof(BackOfficeUserStore), userStore.GetType()); + } + + [Test] + public void AddUmbracoBackOfficeIdentity_ExpectBackOfficeUserManagerResolvable() + { + var userManager = Services.GetService(); + + Assert.NotNull(userManager); + } + + protected override Action CustomTestSetup => (services) => services.AddUmbracoBackOfficeIdentity(); + } +} diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensionsTests.cs deleted file mode 100644 index b5b7cf9a02..0000000000 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensionsTests.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.DependencyInjection; -using Moq; -using NUnit.Framework; -using Umbraco.Extensions; -using Umbraco.Core.BackOffice; - -namespace Umbraco.Tests.UnitTests.Umbraco.Web.BackOffice.Extensions -{ - [TestFixture] - public class UmbracoBackOfficeServiceCollectionExtensionsTests - { - /*[Test] - public void AddUmbracoBackOfficeIdentity_ExpectBackOfficeUserStoreResolvable() - { - var services = new ServiceCollection(); - - var mockEnvironment = new Mock(); - - services.AddUmbracoCore(mockEnvironment.Object); - services.AddUmbracoBackOfficeIdentity(); - - var serviceProvider = services.BuildServiceProvider(); - - var userStore = serviceProvider.GetService>(); - Assert.AreEqual(typeof(BackOfficeUserStore), userStore.GetType()); - }*/ - } -} diff --git a/src/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensions.cs index 379381e6e9..9d3e2a9e3f 100644 --- a/src/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.BackOffice/Extensions/UmbracoBackOfficeServiceCollectionExtensions.cs @@ -4,7 +4,6 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using Umbraco.Core; using Umbraco.Core.BackOffice; -using Umbraco.Core.Composing; using Umbraco.Core.Mapping; using Umbraco.Net; using Umbraco.Web.Common.AspNetCore; @@ -13,7 +12,7 @@ namespace Umbraco.Extensions { public static class UmbracoBackOfficeServiceCollectionExtensions { - public static void AddUmbracoBackOfficeIdentity(this IServiceCollection services, IFactory factory) + public static void AddUmbracoBackOfficeIdentity(this IServiceCollection services) { // UmbracoMapper - hack? services.AddSingleton(); diff --git a/src/Umbraco.Web.UI.NetCore/Startup.cs b/src/Umbraco.Web.UI.NetCore/Startup.cs index 613095437b..27e276138e 100644 --- a/src/Umbraco.Web.UI.NetCore/Startup.cs +++ b/src/Umbraco.Web.UI.NetCore/Startup.cs @@ -36,7 +36,7 @@ namespace Umbraco.Web.UI.BackOffice services.AddUmbracoCore(_env, out var factory); services.AddUmbracoWebComponents(); services.AddUmbracoRuntimeMinifier(_config); - services.AddUmbracoBackOfficeIdentity(factory); + services.AddUmbracoBackOfficeIdentity(); services.AddMvc();