+ John Doe's favorite number is + + +(double) 6.02214085774747E+23 +
++ John Smith's favorite number is + + +(long) 100000000000 +
++ Someone Nice's favorite number is + + +(decimal) 1.6180339887498948482045868344 +
diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/DefaultRoslynCompilationServiceTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/DefaultRoslynCompilationServiceTest.cs index 1e72b1b92c..ae218dafef 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/DefaultRoslynCompilationServiceTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/DefaultRoslynCompilationServiceTest.cs @@ -2,9 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.IO; using System.Reflection; -using System.Text; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Razor.Compilation; using Microsoft.AspNetCore.Razor.Language; @@ -19,6 +17,38 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal { public class DefaultRoslynCompilationServiceTest { + [Fact] + public void Compile_SucceedsForCSharp7() + { + // Arrange + var content = @" +public class MyTestType +{ + private string _name; + + public string Name + { + get => _name; + set => _name = value ?? throw new System.ArgumentNullException(nameof(value)); + } +}"; + var compilationService = GetRoslynCompilationService(); + + var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("Hello world", "test.cshtml")); + + var csharpDocument = new RazorCSharpDocument() + { + GeneratedCode = content + }; + + // Act + var result = compilationService.Compile(codeDocument, csharpDocument); + + // Assert + Assert.Equal("MyTestType", result.CompiledType.Name); + Assert.Null(result.CompilationFailures); + } + [Fact] public void Compile_ReturnsCompilationResult() { @@ -219,7 +249,7 @@ public void Compile_RunsCallback() RoslynCompilationContext usedCompilation = null; var options = GetOptions(c => usedCompilation = c); var compilationService = GetRoslynCompilationService(options: options); - + var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("Hello world", "some-relative-path")); var csharpDocument = new RazorCSharpDocument() diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/DependencyContextRazorViewEngineOptionsSetupTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/DependencyContextRazorViewEngineOptionsSetupTest.cs index d2a4d3ca1f..de3d7956c1 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/DependencyContextRazorViewEngineOptionsSetupTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Test/Internal/DependencyContextRazorViewEngineOptionsSetupTest.cs @@ -99,7 +99,7 @@ public void Configure_UsesDefaultCompilationOptions() }); Assert.Empty(parseOptions.PreprocessorSymbolNames); - Assert.Equal(LanguageVersion.CSharp6, parseOptions.LanguageVersion); + Assert.Equal(LanguageVersion.CSharp7, parseOptions.LanguageVersion); } [Fact] diff --git a/test/WebSites/BasicWebSite/Controllers/HomeController.cs b/test/WebSites/BasicWebSite/Controllers/HomeController.cs index 48e1aa850c..c6554d7c76 100644 --- a/test/WebSites/BasicWebSite/Controllers/HomeController.cs +++ b/test/WebSites/BasicWebSite/Controllers/HomeController.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Collections.Generic; using System.Threading.Tasks; using BasicWebSite.Models; using Microsoft.AspNetCore.Http; @@ -16,6 +17,18 @@ public IActionResult Index() return View(); } + public IActionResult CSharp7View() + { + var people = new List<(string FirstName, string LastName, object FavoriteNumber)>() + { + ("John", "Doe", 6.022_140_857_747_474e23), + ("John", "Smith", 100_000_000_000), + ("Someone", "Nice", (decimal)1.618_033_988_749_894_848_204_586_834_365_638_117_720_309_179M), + }; + + return View(people); + } + // Keep the return type as object to ensure that we don't // wrap IActionResult instances into ObjectResults. public object PlainView() diff --git a/test/WebSites/BasicWebSite/Views/Home/CSharp7View.cshtml b/test/WebSites/BasicWebSite/Views/Home/CSharp7View.cshtml new file mode 100644 index 0000000000..e2518ae708 --- /dev/null +++ b/test/WebSites/BasicWebSite/Views/Home/CSharp7View.cshtml @@ -0,0 +1,24 @@ +@model IEnumerable<(string FirstName, string LastName, object FavoriteNumber)> + + @foreach (var person in Model) + { +
+ @person.FirstName @person.LastName's favorite number is
+
+
+ @switch (person.FavoriteNumber)
+ {
+ case double doubleVal:
+