Remove IHostingEnvironment dependency (#230)
This commit is contained in:
parent
d91d627c04
commit
129edaec7c
|
|
@ -4,7 +4,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using Microsoft.AspNetCore.DataProtection.Infrastructure;
|
using Microsoft.AspNetCore.DataProtection.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.DataProtection
|
namespace Microsoft.AspNetCore.DataProtection
|
||||||
|
|
@ -37,10 +36,6 @@ namespace Microsoft.AspNetCore.DataProtection
|
||||||
if (services != null)
|
if (services != null)
|
||||||
{
|
{
|
||||||
discriminator = services.GetService<IApplicationDiscriminator>()?.Discriminator;
|
discriminator = services.GetService<IApplicationDiscriminator>()?.Discriminator;
|
||||||
if (discriminator == null)
|
|
||||||
{
|
|
||||||
discriminator = services.GetService<IHostingEnvironment>()?.ContentRootPath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove whitespace and homogenize empty -> null
|
// Remove whitespace and homogenize empty -> null
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Microsoft.AspNetCore.Cryptography.Internal\Microsoft.AspNetCore.Cryptography.Internal.csproj" />
|
<ProjectReference Include="..\Microsoft.AspNetCore.Cryptography.Internal\Microsoft.AspNetCore.Cryptography.Internal.csproj" />
|
||||||
<ProjectReference Include="..\Microsoft.AspNetCore.DataProtection.Abstractions\Microsoft.AspNetCore.DataProtection.Abstractions.csproj" />
|
<ProjectReference Include="..\Microsoft.AspNetCore.DataProtection.Abstractions\Microsoft.AspNetCore.DataProtection.Abstractions.csproj" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="$(AspNetCoreVersion)" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
|
||||||
|
|
@ -33,6 +32,7 @@
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
|
||||||
<PackageReference Include="Microsoft.Win32.Registry" Version="$(CoreFxVersion)" />
|
<PackageReference Include="Microsoft.Win32.Registry" Version="$(CoreFxVersion)" />
|
||||||
|
<PackageReference Include="System.Reflection.TypeExtensions" Version="$(CoreFxVersion)" />
|
||||||
<PackageReference Include="System.Security.Claims" Version="$(CoreFxVersion)" />
|
<PackageReference Include="System.Security.Claims" Version="$(CoreFxVersion)" />
|
||||||
<PackageReference Include="System.Security.Principal.Windows" Version="$(CoreFxVersion)" />
|
<PackageReference Include="System.Security.Principal.Windows" Version="$(CoreFxVersion)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNetCore.DataProtection.Infrastructure;
|
using Microsoft.AspNetCore.DataProtection.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -12,21 +11,16 @@ namespace Microsoft.AspNetCore.DataProtection
|
||||||
public class DataProtectionUtilityExtensionsTests
|
public class DataProtectionUtilityExtensionsTests
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(" discriminator", "app-path ", "discriminator")] // normalized trim
|
[InlineData(" discriminator", "discriminator")] // normalized trim
|
||||||
[InlineData("", "app-path", null)] // app discriminator not null -> overrides app base path
|
[InlineData("", null)] // app discriminator not null -> overrides app base path
|
||||||
[InlineData(null, "app-path ", "app-path")] // normalized trim
|
[InlineData(null, null)] // nothing provided at all
|
||||||
[InlineData(null, " ", null)] // normalized whitespace -> null
|
public void GetApplicationUniqueIdentifier(string appDiscriminator, string expected)
|
||||||
[InlineData(null, null, null)] // nothing provided at all
|
|
||||||
public void GetApplicationUniqueIdentifier(string appDiscriminator, string appBasePath, string expected)
|
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var mockAppDiscriminator = new Mock<IApplicationDiscriminator>();
|
var mockAppDiscriminator = new Mock<IApplicationDiscriminator>();
|
||||||
mockAppDiscriminator.Setup(o => o.Discriminator).Returns(appDiscriminator);
|
mockAppDiscriminator.Setup(o => o.Discriminator).Returns(appDiscriminator);
|
||||||
var mockEnvironment = new Mock<IHostingEnvironment>();
|
|
||||||
mockEnvironment.Setup(o => o.ContentRootPath).Returns(appBasePath);
|
|
||||||
var mockServiceProvider = new Mock<IServiceProvider>();
|
var mockServiceProvider = new Mock<IServiceProvider>();
|
||||||
mockServiceProvider.Setup(o => o.GetService(typeof(IApplicationDiscriminator))).Returns(mockAppDiscriminator.Object);
|
mockServiceProvider.Setup(o => o.GetService(typeof(IApplicationDiscriminator))).Returns(mockAppDiscriminator.Object);
|
||||||
mockServiceProvider.Setup(o => o.GetService(typeof(IHostingEnvironment))).Returns(mockEnvironment.Object);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
string actual = mockServiceProvider.Object.GetApplicationUniqueIdentifier();
|
string actual = mockServiceProvider.Object.GetApplicationUniqueIdentifier();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue