Browse Source

[Static web assets] Removes private reflection from Identity.DefaultUI.WebSite by giving it IVT access in Hosting

These tests need to disable polling within the underlying file provider, given that the provider is internal, they were using reflection to access them and modify the polling setting.

This change gives the test assembly internals visible to access so that it can do so without resorting to use private reflection.
Javier Calvarro Nelson 4 years ago
parent
commit
02f537463d

+ 20 - 3
AspNetCore.sln

@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.31320.298
+# Visual Studio Version 17
+VisualStudioVersion = 17.0.31613.370
 MinimumVisualStudioVersion = 15.0.26124.0
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "eng", "eng", "{C28A32F6-8314-412E-9F3B-CBD31C23E878}"
 EndProject
@@ -1638,6 +1638,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Razor.
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpClientApp", "src\Servers\Kestrel\samples\HttpClientApp\HttpClientApp.csproj", "{514726D2-3D2E-44C1-B056-163E37DE3E8B}"
 EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "testassets", "testassets", "{48526D13-69E2-4409-A57B-C3FA3C64B4F7}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Identity.DefaultUI.WebSite", "src\Identity\testassets\Identity.DefaultUI.WebSite\Identity.DefaultUI.WebSite.csproj", "{835A4E0F-A697-4B69-9736-3E99D163C4B9}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -7817,6 +7821,18 @@ Global
 		{514726D2-3D2E-44C1-B056-163E37DE3E8B}.Release|x64.Build.0 = Release|Any CPU
 		{514726D2-3D2E-44C1-B056-163E37DE3E8B}.Release|x86.ActiveCfg = Release|Any CPU
 		{514726D2-3D2E-44C1-B056-163E37DE3E8B}.Release|x86.Build.0 = Release|Any CPU
+		{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Debug|x64.Build.0 = Debug|Any CPU
+		{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Debug|x86.Build.0 = Debug|Any CPU
+		{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Release|Any CPU.Build.0 = Release|Any CPU
+		{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Release|x64.ActiveCfg = Release|Any CPU
+		{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Release|x64.Build.0 = Release|Any CPU
+		{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Release|x86.ActiveCfg = Release|Any CPU
+		{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Release|x86.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -8628,7 +8644,8 @@ Global
 		{17459B97-1AA3-4154-83D3-C6BDC9FA3F85} = {022B4B80-E813-4256-8034-11A68146F4EF}
 		{247E7B6F-FBA2-41A9-BA03-C7C4DF28091C} = {B27FBAC2-ADA3-4A05-B232-64011B6B2DA3}
 		{514726D2-3D2E-44C1-B056-163E37DE3E8B} = {7B976D8F-EA31-4C0B-97BD-DFD9B3CC86FB}
-		{B2ACFA01-3046-4A32-B90A-F9537F51BF85} = {6126DCE4-9692-4EE2-B240-C65743572995}
+		{48526D13-69E2-4409-A57B-C3FA3C64B4F7} = {9F21A235-436E-4020-A076-1DF4F89D0CA0}
+		{835A4E0F-A697-4B69-9736-3E99D163C4B9} = {48526D13-69E2-4409-A57B-C3FA3C64B4F7}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}

+ 4 - 0
src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj

@@ -34,4 +34,8 @@
     <Compile Include="$(SharedSourceRoot)TypeNameHelper\*.cs" />
   </ItemGroup>
 
+  <ItemGroup>
+    <InternalsVisibleTo Include="Identity.DefaultUI.WebSite" />
+  </ItemGroup>
+
 </Project>

+ 3 - 18
src/Identity/testassets/Identity.DefaultUI.WebSite/StartupBase.cs

@@ -15,6 +15,7 @@ using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.FileProviders;
 using Microsoft.Extensions.Hosting;
+using Microsoft.AspNetCore.StaticWebAssets;
 
 namespace Identity.DefaultUI.WebSite
 {
@@ -102,11 +103,8 @@ namespace Identity.DefaultUI.WebSite
                     case PhysicalFileProvider physical:
                         physical.UseActivePolling = false;
                         break;
-                    case IFileProvider staticWebAssets when staticWebAssets.GetType().Name == "StaticWebAssetsFileProvider":
-                        GetUnderlyingProvider(staticWebAssets).UseActivePolling = false;
-                        break;
-                    case IFileProvider manifestStaticWebAssets when manifestStaticWebAssets.GetType().Name == "ManifestStaticWebAssetFileProvider":
-                        foreach (var provider in GetUnderlyingProviders(manifestStaticWebAssets))
+                    case ManifestStaticWebAssetFileProvider manifestStaticWebAssets:
+                        foreach (var provider in manifestStaticWebAssets.FileProviders)
                         {
                             pendingProviders.Push(provider);
                         }
@@ -124,18 +122,5 @@ namespace Identity.DefaultUI.WebSite
                 }
             }
         }
-
-        private static IFileProvider[] GetUnderlyingProviders(IFileProvider manifestStaticWebAssets)
-        {
-            return (IFileProvider[])manifestStaticWebAssets
-                .GetType()
-                .GetField("_fileProviders", BindingFlags.NonPublic | BindingFlags.Instance)
-                .GetValue(manifestStaticWebAssets);
-        }
-
-        private static PhysicalFileProvider GetUnderlyingProvider(IFileProvider staticWebAssets)
-        {
-            return (PhysicalFileProvider) staticWebAssets.GetType().GetProperty("InnerProvider").GetValue(staticWebAssets);
-        }
     }
 }

+ 3 - 0
src/Shared/StaticWebAssets/StaticWebAssetsFileProvider.cs

@@ -35,6 +35,9 @@ namespace Microsoft.AspNetCore.StaticWebAssets
             _root = manifest.Root;
         }
 
+        // For testing purposes only
+        internal IFileProvider[] FileProviders => _fileProviders;
+
         public IDirectoryContents GetDirectoryContents(string subpath)
         {
             if (subpath == null)