Skip to content

Commit

Permalink
add Razor example projects (fix formating) (#116)
Browse files Browse the repository at this point in the history
* add Razor example projects (fix formating)

* use coverlet.collector from coverlet-nightly feed

* small fixes

* add coverlet.runsettings file
  • Loading branch information
Bertk authored Oct 28, 2023
1 parent a9b226a commit e592861
Show file tree
Hide file tree
Showing 67 changed files with 1,904 additions and 21 deletions.
8 changes: 7 additions & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"commands": [
"nbgv"
]
},
"coverlet.console": {
"version": "6.0.0",
"commands": [
"coverlet"
]
}
}
}
}
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 2
end_of_line = crlf
dotnet_diagnostic.CA2007.severity = suggestion
###############################
# C# Coding Conventions #
###############################
Expand Down Expand Up @@ -960,6 +961,7 @@ csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_prefer_primary_constructors = true:suggestion


[*.vb]
Expand Down
17 changes: 11 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.1-preview.21.g91acb45884" />
<PackageVersion Include="Google.Protobuf" Version="3.24.4" />
<PackageVersion Include="Grpc.AspNetCore" Version="2.57.0" />
<PackageVersion Include="Grpc.Net.Client" Version="2.57.0" />
<PackageVersion Include="Grpc.Tools" Version="2.58.0" />
<PackageVersion Include="Grpc.AspNetCore" Version="2.58.0" />
<PackageVersion Include="Grpc.Net.Client" Version="2.58.0" />
<PackageVersion Include="Grpc.Tools" Version="2.59.0" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="6.0.24" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageVersion Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="6.0.24" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.24" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
Expand All @@ -23,17 +26,19 @@
<PackageVersion Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Microsoft.SourceLink.AzureRepos.Git" Version="1.1.1" />
<PackageVersion Include="Moq" Version="4.20.69" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NuGet.Frameworks" Version="6.7.0" />
<PackageVersion Include="xunit" Version="2.5.2" />
<PackageVersion Include="xunit.runner.console" Version="2.5.2" />
<PackageVersion Include="xunit" Version="2.5.3" />
<PackageVersion Include="xunit.runner.console" Version="2.5.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Collections.Immutable" Version="7.0.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
<PackageVersion Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="7.0.2" />
<PackageVersion Include="System.Diagnostics.TraceSource" Version="4.3.0" />
<PackageVersion Include="System.Reflection.Metadata" Version="7.0.2" />
<PackageVersion Include="System.Reflection" Version="4.3.0" />
<PackageVersion Include="System.Text.Json" Version="7.0.3" />
Expand Down
23 changes: 23 additions & 0 deletions SampleSolution.sln
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Calculator.ServiceHost", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Calculator.ServiceLib", "src\Calculator\Calculator.ServiceLib\Calculator.ServiceLib.csproj", "{F7572347-CFF3-49FE-8074-394F95FE8CD6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorPagesIntro", "src\RazorPages\RazorPagesIntro\RazorPagesIntro.csproj", "{F49D0EF1-4ADD-4C0E-B36B-EFD9EBB37E07}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RazorPages", "RazorPages", "{7EA84684-E8A2-4335-8B51-21D03C338971}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorPagesTestSample", "src\RazorPages\RazorPagesTestSample\RazorPagesTestSample.csproj", "{3160C37B-EEE3-48B4-B4C3-635C6EFA554B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorPagesTestSample.Tests", "src\RazorPages\RazorPagesTestSample.Tests\RazorPagesTestSample.Tests.csproj", "{6AFF10EC-E3F1-4E8D-B6ED-4F110AA346D5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -78,6 +86,18 @@ Global
{F7572347-CFF3-49FE-8074-394F95FE8CD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7572347-CFF3-49FE-8074-394F95FE8CD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7572347-CFF3-49FE-8074-394F95FE8CD6}.Release|Any CPU.Build.0 = Release|Any CPU
{F49D0EF1-4ADD-4C0E-B36B-EFD9EBB37E07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F49D0EF1-4ADD-4C0E-B36B-EFD9EBB37E07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F49D0EF1-4ADD-4C0E-B36B-EFD9EBB37E07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F49D0EF1-4ADD-4C0E-B36B-EFD9EBB37E07}.Release|Any CPU.Build.0 = Release|Any CPU
{3160C37B-EEE3-48B4-B4C3-635C6EFA554B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3160C37B-EEE3-48B4-B4C3-635C6EFA554B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3160C37B-EEE3-48B4-B4C3-635C6EFA554B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3160C37B-EEE3-48B4-B4C3-635C6EFA554B}.Release|Any CPU.Build.0 = Release|Any CPU
{6AFF10EC-E3F1-4E8D-B6ED-4F110AA346D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6AFF10EC-E3F1-4E8D-B6ED-4F110AA346D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6AFF10EC-E3F1-4E8D-B6ED-4F110AA346D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6AFF10EC-E3F1-4E8D-B6ED-4F110AA346D5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -91,6 +111,9 @@ Global
{2FD5EB8E-5708-45FD-A736-A1FF70F7BBF0} = {05EA6E82-061C-410A-84EA-A88B1F6503FF}
{8533142F-A138-4089-804A-7FD20A6218CF} = {05EA6E82-061C-410A-84EA-A88B1F6503FF}
{F7572347-CFF3-49FE-8074-394F95FE8CD6} = {05EA6E82-061C-410A-84EA-A88B1F6503FF}
{F49D0EF1-4ADD-4C0E-B36B-EFD9EBB37E07} = {7EA84684-E8A2-4335-8B51-21D03C338971}
{3160C37B-EEE3-48B4-B4C3-635C6EFA554B} = {7EA84684-E8A2-4335-8B51-21D03C338971}
{6AFF10EC-E3F1-4E8D-B6ED-4F110AA346D5} = {7EA84684-E8A2-4335-8B51-21D03C338971}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8785AA60-E1A0-4C1E-B5AD-2E18515B66ED}
Expand Down
7 changes: 3 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ stages:
matrix:
Build_Release:
_BuildConfig: Release
${{ if eq(variables._RunAsPublic, True) }}:
Build_Debug:
_BuildConfig: Debug
Build_Debug:
_BuildConfig: Debug
preSteps:
- checkout: self
fetchDepth: 0
Expand Down Expand Up @@ -143,7 +142,7 @@ stages:

- template: ../steps/CoverageResults.yml
parameters:
reports: $(Build.SourcesDirectory)/artifacts/TestResults/**/coverage.cobertura.xml
reports: $(Build.SourcesDirectory)/**/coverage.cobertura.xml
configuration: $(_BuildConfig)
condition: and(succeeded(), eq(variables['_BuildConfig'], 'Debug'))
assemblyfilters: '-xunit'
Expand Down
5 changes: 5 additions & 0 deletions eng/azuredevops/pipelines/steps/CoverageResults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ steps:
verbosity: 'Verbose'
assemblyfilters: ${{parameters.assemblyfilters}}

- publish: '$(Build.SourcesDirectory)/artifacts/TestResults'
displayName: 'Publish TestResults Artifacts'
artifact: TestResults_$(Agent.Os)_$(_BuildConfig)
condition: ${{parameters.condition}}

- publish: '$(Build.SourcesDirectory)/artifacts/CoverageReport'
displayName: 'Publish CoverageReport Artifact'
artifact: CoverageResults_$(Agent.Os)_${{parameters.configuration}}
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"sdk": {
"version": "7.0.401",
"version": "7.0.403",
"rollForward": "latestFeature"
},
"tools": {
"dotnet": "7.0.401"
"dotnet": "7.0.403"
},
"msbuild-sdks": {
"DotNetDev.ArcadeLight.Sdk": "1.6.5"
Expand Down
1 change: 1 addition & 0 deletions nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="coverlet-nightly" value="https://pkgs.dev.azure.com/tonerdo/coverlet/_packaging/coverlet-nightly/nuget/v3/index.json" />
</packageSources>
</configuration>
2 changes: 1 addition & 1 deletion src/NewTypes/NewTypes/Pets/Cat.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace Pets
{
Expand Down
2 changes: 1 addition & 1 deletion src/NewTypes/NewTypes/Pets/Dog.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace Pets
{
Expand Down
2 changes: 1 addition & 1 deletion src/NewTypes/NewTypes/Pets/IPet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace Pets
{
Expand Down
19 changes: 15 additions & 4 deletions src/NewTypes/NewTypesTests/NewTypes.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.console">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../NewTypes/NewTypes.csproj"/>
<ItemGroup>
<ProjectReference Include="../NewTypes/NewTypes.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/NewTypes/NewTypesTests/PetTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Xunit;
using Pets;
using Xunit;

namespace PetsUnitTest
{
Expand Down
26 changes: 26 additions & 0 deletions src/RazorPages/RazorPagesIntro/Pages/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@page
@model ErrorModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
29 changes: 29 additions & 0 deletions src/RazorPages/RazorPagesIntro/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace RazorPagesIntro.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

#pragma warning disable S4487 // Unread "private" fields should be removed
private readonly ILogger<ErrorModel> _logger;
#pragma warning restore S4487 // Unread "private" fields should be removed

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
4 changes: 4 additions & 0 deletions src/RazorPages/RazorPagesIntro/Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@page

<h1>Hello, world!</h1>
<h2>The time on the server is @DateTime.Now</h2>
8 changes: 8 additions & 0 deletions src/RazorPages/RazorPagesIntro/Pages/Index2.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@page
@using RazorPagesIntro.Pages
@model Index2Model

<h2>Separate page model</h2>
<p>
@Model.Message
</p>
16 changes: 16 additions & 0 deletions src/RazorPages/RazorPagesIntro/Pages/Index2.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;

namespace RazorPagesIntro.Pages
{
public class Index2Model : PageModel
{
public string Message { get; private set; } = "PageModel in C#";

public void OnGet()
{
Message += $" Server time is { DateTime.Now }";
}
}
}
8 changes: 8 additions & 0 deletions src/RazorPages/RazorPagesIntro/Pages/Privacy.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@page
@model PrivacyModel
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>
22 changes: 22 additions & 0 deletions src/RazorPages/RazorPagesIntro/Pages/Privacy.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace RazorPagesIntro.Pages
{
public class PrivacyModel : PageModel
{
#pragma warning disable S4487 // Unread "private" fields should be removed
private readonly ILogger<PrivacyModel> _logger;
#pragma warning restore S4487 // Unread "private" fields should be removed

public PrivacyModel(ILogger<PrivacyModel> logger)
{
_logger = logger;
}

public void OnGet()
{
// to be populated
}
}
}
51 changes: 51 additions & 0 deletions src/RazorPages/RazorPagesIntro/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - RazorPagesIntro</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/RazorPagesIntro.styles.css" asp-append-version="true" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-page="/Index">RazorPagesIntro</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2021 - RazorPagesIntro - <a asp-area="" asp-page="/Privacy">Privacy</a>
</div>
</footer>

<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>

@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
Loading

0 comments on commit e592861

Please sign in to comment.