From cfa4689d47a61f1123eae0007be8a589148475fc Mon Sep 17 00:00:00 2001 From: Pranav K Date: Thu, 16 Feb 2017 12:49:57 -0800 Subject: [PATCH] Re-enable netcoreapp1.1 tests Fixes #1003 --- .../DefaultRazorDiagnosticTest.cs | 4 +-- .../TestTagHelperDescriptors.cs | 1 + ...oft.AspNetCore.Razor.Evolution.Test.csproj | 4 +-- .../DefaultTagHelperDescriptorFactoryTest.cs | 6 ++--- .../Microsoft.CodeAnalysis.Razor.Test.csproj | 8 +++--- .../TestCompilation.cs | 27 ++++++++++++++++--- ...ComponentTagHelperDescriptorFactoryTest.cs | 7 ++--- 7 files changed, 40 insertions(+), 17 deletions(-) diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/DefaultRazorDiagnosticTest.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/DefaultRazorDiagnosticTest.cs index 9ba1460122..f78b65eb20 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/DefaultRazorDiagnosticTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/DefaultRazorDiagnosticTest.cs @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution var diagnostic = new DefaultRazorDiagnostic(descriptor, span, new object[] { 1.3m }); // Act - var result = diagnostic.GetMessage(CultureInfo.GetCultureInfo("fr-FR")); + var result = diagnostic.GetMessage(new CultureInfo("fr-FR")); // Assert Assert.Equal("this is an 1,3", result); @@ -102,7 +102,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution var diagnostic = new DefaultRazorDiagnostic(descriptor, span, new object[] { 1.3m }); // Act - var result = ((IFormattable)diagnostic).ToString("ignored", CultureInfo.GetCultureInfo("fr-FR")); + var result = ((IFormattable)diagnostic).ToString("ignored", new CultureInfo("fr-FR")); // Assert Assert.Equal("test.cs(2,9): Error RZ0000: this is an 1,3", result); diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/TestTagHelperDescriptors.cs b/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/TestTagHelperDescriptors.cs index bb3daf3cb2..d4b8d017c9 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/TestTagHelperDescriptors.cs +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/IntegrationTests/TestTagHelperDescriptors.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Reflection; namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests { diff --git a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Microsoft.AspNetCore.Razor.Evolution.Test.csproj b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Microsoft.AspNetCore.Razor.Evolution.Test.csproj index d726f14f28..ff460eea45 100644 --- a/test/Microsoft.AspNetCore.Razor.Evolution.Test/Microsoft.AspNetCore.Razor.Evolution.Test.csproj +++ b/test/Microsoft.AspNetCore.Razor.Evolution.Test/Microsoft.AspNetCore.Razor.Evolution.Test.csproj @@ -1,8 +1,8 @@  - - net46 + netcoreapp1.1;net46 + netcoreapp1.1 $(DefineConstants);__RemoveThisBitTo__GENERATE_BASELINES $(DefaultItemExcludes);TestFiles\**\* diff --git a/test/Microsoft.CodeAnalysis.Razor.Test/DefaultTagHelperDescriptorFactoryTest.cs b/test/Microsoft.CodeAnalysis.Razor.Test/DefaultTagHelperDescriptorFactoryTest.cs index d91399bee4..9d12fe88d2 100644 --- a/test/Microsoft.CodeAnalysis.Razor.Test/DefaultTagHelperDescriptorFactoryTest.cs +++ b/test/Microsoft.CodeAnalysis.Razor.Test/DefaultTagHelperDescriptorFactoryTest.cs @@ -2098,11 +2098,11 @@ public class DynamicTestTagHelper : {typeof(AspNetCore.Razor.TagHelpers.TagHelpe { // Arrange var errorSink = new ErrorSink(); - var objectAssemblyName = typeof(object).GetTypeInfo().Assembly.GetName().Name; + var objectAssemblyName = typeof(Enumerable).GetTypeInfo().Assembly.GetName().Name; var expectedDescriptor = - CreateTagHelperDescriptor("object", "System.Object", objectAssemblyName); + CreateTagHelperDescriptor("enumerable", "System.Linq.Enumerable", objectAssemblyName); var factory = new DefaultTagHelperDescriptorFactory(Compilation, designTime: false); - var typeSymbol = Compilation.GetTypeByMetadataName(typeof(object).FullName); + var typeSymbol = Compilation.GetTypeByMetadataName(typeof(Enumerable).FullName); // Act var descriptors = factory.CreateDescriptors(typeSymbol, errorSink); diff --git a/test/Microsoft.CodeAnalysis.Razor.Test/Microsoft.CodeAnalysis.Razor.Test.csproj b/test/Microsoft.CodeAnalysis.Razor.Test/Microsoft.CodeAnalysis.Razor.Test.csproj index 98e221c72b..5e14c2b5b8 100644 --- a/test/Microsoft.CodeAnalysis.Razor.Test/Microsoft.CodeAnalysis.Razor.Test.csproj +++ b/test/Microsoft.CodeAnalysis.Razor.Test/Microsoft.CodeAnalysis.Razor.Test.csproj @@ -1,11 +1,10 @@  - true - $(NoWarn);CS1591 - - net452 + netcoreapp1.1;net46 + netcoreapp1.1 $(DefaultItemExcludes);TestFiles\**\* + true $(PackageTargetFallback);portable-net45+win8+wp8+wpa81; @@ -19,6 +18,7 @@ + diff --git a/test/Microsoft.CodeAnalysis.Razor.Test/TestCompilation.cs b/test/Microsoft.CodeAnalysis.Razor.Test/TestCompilation.cs index afb2131825..f822f95492 100644 --- a/test/Microsoft.CodeAnalysis.Razor.Test/TestCompilation.cs +++ b/test/Microsoft.CodeAnalysis.Razor.Test/TestCompilation.cs @@ -3,8 +3,12 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Reflection; using Microsoft.CodeAnalysis.CSharp; +using Microsoft.Extensions.DependencyModel; +using Xunit; namespace Microsoft.CodeAnalysis.Razor { @@ -19,13 +23,30 @@ namespace Microsoft.CodeAnalysis.Razor syntaxTrees = new[] { syntaxTree }; } - var references = AppDomain.CurrentDomain - .GetAssemblies() - .Select(assembly => MetadataReference.CreateFromFile(assembly.Location)); + var assemblyName = new AssemblyName(typeof(TestCompilation).GetTypeInfo().Assembly.GetName().Name); + var dependencyContext = DependencyContext.Load(Assembly.Load(assemblyName)); + + var references = dependencyContext.CompileLibraries.SelectMany(l => l.ResolveReferencePaths()) + .Select(assemblyPath => MetadataReference.CreateFromFile(assemblyPath)); var compilation = CSharpCompilation.Create("TestAssembly", syntaxTrees, references); + EnsureValidCompilation(compilation); return compilation; } + + private static void EnsureValidCompilation(CSharpCompilation compilation) + { + using (var stream = new MemoryStream()) + { + var emitResult = compilation + .WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)) + .Emit(stream); + var diagnostics = string.Join( + Environment.NewLine, + emitResult.Diagnostics.Select(d => CSharpDiagnosticFormatter.Instance.Format(d))); + Assert.True(emitResult.Success, $"Compilation is invalid : {Environment.NewLine}{diagnostics}"); + } + } } } diff --git a/test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTagHelperDescriptorFactoryTest.cs b/test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTagHelperDescriptorFactoryTest.cs index 7a72acef90..079653468a 100644 --- a/test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTagHelperDescriptorFactoryTest.cs +++ b/test/Microsoft.CodeAnalysis.Razor.Test/ViewComponentTagHelperDescriptorFactoryTest.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; +using System.Reflection; using Microsoft.AspNetCore.Razor.Evolution; using Microsoft.CodeAnalysis.Razor.Workspaces.Test; using Microsoft.CodeAnalysis.Razor.Workspaces.Test.Comparers; @@ -22,7 +23,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces { TagName = "vc:string-parameter", TypeName = "__Generated__StringParameterViewComponentTagHelper", - AssemblyName = typeof(StringParameterViewComponent).Assembly.GetName().Name, + AssemblyName = typeof(StringParameterViewComponent).GetTypeInfo().Assembly.GetName().Name, Attributes = new List { new TagHelperAttributeDescriptor @@ -70,7 +71,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces { TagName = "vc:various-parameter", TypeName = "__Generated__VariousParameterViewComponentTagHelper", - AssemblyName = typeof(VariousParameterViewComponent).Assembly.GetName().Name, + AssemblyName = typeof(VariousParameterViewComponent).GetTypeInfo().Assembly.GetName().Name, Attributes = new List { new TagHelperAttributeDescriptor @@ -133,7 +134,7 @@ namespace Microsoft.CodeAnalysis.Razor.Workspaces { TagName = "vc:generic-parameter", TypeName = "__Generated__GenericParameterViewComponentTagHelper", - AssemblyName = typeof(GenericParameterViewComponent).Assembly.GetName().Name, + AssemblyName = typeof(GenericParameterViewComponent).GetTypeInfo().Assembly.GetName().Name, Attributes = new List { new TagHelperAttributeDescriptor