diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/Assert.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/Assert.cs index d94289e180..f2ee9393f6 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/Assert.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/Assert.cs @@ -397,25 +397,24 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests throw new ArgumentNullException(nameof(result)); } + assemblyPath = Path.Combine(result.Project.DirectoryPath, Path.Combine(assemblyPath)); + var typeNames = GetDeclaredTypeNames(assemblyPath); Assert.DoesNotContain(fullTypeName, typeNames); } private static IEnumerable GetDeclaredTypeNames(string assemblyPath) { - IEnumerable typeNames; using (var file = File.OpenRead(assemblyPath)) { var peReader = new PEReader(file); var metadataReader = peReader.GetMetadataReader(); - typeNames = metadataReader.TypeDefinitions.Where(t => !t.IsNil).Select(t => + return metadataReader.TypeDefinitions.Where(t => !t.IsNil).Select(t => { var type = metadataReader.GetTypeDefinition(t); return metadataReader.GetString(type.Namespace) + "." + metadataReader.GetString(type.Name); - }); + }).ToArray(); } - - return typeNames; } private abstract class MSBuildXunitException : Xunit.Sdk.XunitException diff --git a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildWithComponentsIntegrationTest.cs b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildWithComponentsIntegrationTest.cs index 4ce8344550..847fccafc3 100644 --- a/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildWithComponentsIntegrationTest.cs +++ b/src/Razor/Microsoft.NET.Sdk.Razor/test/IntegrationTests/BuildWithComponentsIntegrationTest.cs @@ -36,8 +36,16 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests Assert.AssemblyContainsType(result, Path.Combine(OutputPath, "MvcWithComponents.dll"), "MvcWithComponents.TestComponent"); Assert.AssemblyContainsType(result, Path.Combine(OutputPath, "MvcWithComponents.dll"), "MvcWithComponents.Views.Shared.NavMenu"); + + // This is a component file with a .cshtml extension. It should appear in the main assembly, but not in the views dll. Assert.AssemblyContainsType(result, Path.Combine(OutputPath, "MvcWithComponents.dll"), "MvcWithComponents.Components.Counter"); - Assert.AssemblyDoesNotContainType(result, Path.Combine(OutputPath, "MvcWithComponents.dll"), "MvcWithComponents.Views.Home.Index"); + Assert.AssemblyDoesNotContainType(result, Path.Combine(OutputPath, "MvcWithComponents.Views.dll"), "MvcWithComponents.Components.Counter"); + Assert.AssemblyDoesNotContainType(result, Path.Combine(OutputPath, "MvcWithComponents.Views.dll"), "AspNetCore.Components_Counter"); + + // Verify a regular View appears in the views dll, but not in the main assembly. + Assert.AssemblyDoesNotContainType(result, Path.Combine(OutputPath, "MvcWithComponents.dll"), "AspNetCore.Views.Home.Index"); + Assert.AssemblyDoesNotContainType(result, Path.Combine(OutputPath, "MvcWithComponents.dll"), "AspNetCore.Views_Home_Index"); + Assert.AssemblyContainsType(result, Path.Combine(OutputPath, "MvcWithComponents.Views.dll"), "AspNetCore.Views_Home_Index"); } } } diff --git a/src/Razor/test/testassets/ComponentLibrary/ComponentLibrary.csproj b/src/Razor/test/testassets/ComponentLibrary/ComponentLibrary.csproj index f4cf248c2b..077e7ae96b 100644 --- a/src/Razor/test/testassets/ComponentLibrary/ComponentLibrary.csproj +++ b/src/Razor/test/testassets/ComponentLibrary/ComponentLibrary.csproj @@ -28,7 +28,7 @@ - +