Remove IHostingEnvironment dependency (#230)

This commit is contained in:
Chris R 2017-05-05 17:03:33 -07:00 коммит произвёл David Fowler
Родитель d91d627c04
Коммит 129edaec7c
3 изменённых файлов: 5 добавлений и 16 удалений

Просмотреть файл

@ -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<IApplicationDiscriminator>()?.Discriminator;
if (discriminator == null)
{
discriminator = services.GetService<IHostingEnvironment>()?.ContentRootPath;
}
}
// Remove whitespace and homogenize empty -> null

Просмотреть файл

@ -19,7 +19,6 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.AspNetCore.Cryptography.Internal\Microsoft.AspNetCore.Cryptography.Internal.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.Logging.Abstractions" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
@ -33,6 +32,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<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.Principal.Windows" Version="$(CoreFxVersion)" />
</ItemGroup>

Просмотреть файл

@ -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<IApplicationDiscriminator>();
mockAppDiscriminator.Setup(o => o.Discriminator).Returns(appDiscriminator);
var mockEnvironment = new Mock<IHostingEnvironment>();
mockEnvironment.Setup(o => o.ContentRootPath).Returns(appBasePath);
var mockServiceProvider = new Mock<IServiceProvider>();
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();