From 3a7022fdcdcc19f5fd782d331266aab2c66f152a Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Fri, 5 May 2017 15:41:16 -0700 Subject: [PATCH] Remove IHostingEnvironment dependency --- .../DataProtectionUtilityExtensions.cs | 5 ----- .../Microsoft.AspNetCore.DataProtection.csproj | 2 +- .../DataProtectionUtilityExtensionsTests.cs | 14 ++++---------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNetCore.DataProtection/DataProtectionUtilityExtensions.cs b/src/Microsoft.AspNetCore.DataProtection/DataProtectionUtilityExtensions.cs index 0b72c11864..04152f3ed6 100644 --- a/src/Microsoft.AspNetCore.DataProtection/DataProtectionUtilityExtensions.cs +++ b/src/Microsoft.AspNetCore.DataProtection/DataProtectionUtilityExtensions.cs @@ -4,7 +4,6 @@ using System; using System.ComponentModel; using Microsoft.AspNetCore.DataProtection.Infrastructure; -using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.DataProtection @@ -37,10 +36,6 @@ namespace Microsoft.AspNetCore.DataProtection if (services != null) { discriminator = services.GetService()?.Discriminator; - if (discriminator == null) - { - discriminator = services.GetService()?.ContentRootPath; - } } // Remove whitespace and homogenize empty -> null diff --git a/src/Microsoft.AspNetCore.DataProtection/Microsoft.AspNetCore.DataProtection.csproj b/src/Microsoft.AspNetCore.DataProtection/Microsoft.AspNetCore.DataProtection.csproj index ccf9d95f42..79a93e283b 100644 --- a/src/Microsoft.AspNetCore.DataProtection/Microsoft.AspNetCore.DataProtection.csproj +++ b/src/Microsoft.AspNetCore.DataProtection/Microsoft.AspNetCore.DataProtection.csproj @@ -19,7 +19,6 @@ - @@ -33,6 +32,7 @@ + diff --git a/test/Microsoft.AspNetCore.DataProtection.Test/DataProtectionUtilityExtensionsTests.cs b/test/Microsoft.AspNetCore.DataProtection.Test/DataProtectionUtilityExtensionsTests.cs index 8e2cbd71d9..f1b2f508da 100644 --- a/test/Microsoft.AspNetCore.DataProtection.Test/DataProtectionUtilityExtensionsTests.cs +++ b/test/Microsoft.AspNetCore.DataProtection.Test/DataProtectionUtilityExtensionsTests.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNetCore.DataProtection.Infrastructure; -using Microsoft.AspNetCore.Hosting; using Moq; using Xunit; @@ -12,21 +11,16 @@ namespace Microsoft.AspNetCore.DataProtection public class DataProtectionUtilityExtensionsTests { [Theory] - [InlineData(" discriminator", "app-path ", "discriminator")] // normalized trim - [InlineData("", "app-path", null)] // app discriminator not null -> overrides app base path - [InlineData(null, "app-path ", "app-path")] // normalized trim - [InlineData(null, " ", null)] // normalized whitespace -> null - [InlineData(null, null, null)] // nothing provided at all - public void GetApplicationUniqueIdentifier(string appDiscriminator, string appBasePath, string expected) + [InlineData(" discriminator", "discriminator")] // normalized trim + [InlineData("", null)] // app discriminator not null -> overrides app base path + [InlineData(null, null)] // nothing provided at all + public void GetApplicationUniqueIdentifier(string appDiscriminator, string expected) { // Arrange var mockAppDiscriminator = new Mock(); mockAppDiscriminator.Setup(o => o.Discriminator).Returns(appDiscriminator); - var mockEnvironment = new Mock(); - mockEnvironment.Setup(o => o.ContentRootPath).Returns(appBasePath); var mockServiceProvider = new Mock(); mockServiceProvider.Setup(o => o.GetService(typeof(IApplicationDiscriminator))).Returns(mockAppDiscriminator.Object); - mockServiceProvider.Setup(o => o.GetService(typeof(IHostingEnvironment))).Returns(mockEnvironment.Object); // Act string actual = mockServiceProvider.Object.GetApplicationUniqueIdentifier();