Skip to content

Commit

Permalink
add Razor example projects (fix formating)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertk committed Oct 28, 2023
1 parent d49dc04 commit dd2a82f
Show file tree
Hide file tree
Showing 61 changed files with 1,855 additions and 17 deletions.
23 changes: 14 additions & 9 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<GlobalPackageReference Include="SonarAnalyzer.CSharp" Version="9.11.0.78383" />
<GlobalPackageReference Include="SonarAnalyzer.CSharp" Version="9.12.0.78982" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="Google.Protobuf" Version="3.24.3" />
<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="Google.Protobuf" Version="3.24.4" />
<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.1" />
<PackageVersion Include="xunit.runner.console" Version="2.5.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.1" />
<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 All @@ -54,4 +59,4 @@
<PackageVersion Include="CoreWCF.WebHttp" Version="1.4.1" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
</ItemGroup>
</Project>
</Project>
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
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
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
7 changes: 5 additions & 2 deletions src/NewTypes/NewTypesTests/NewTypes.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../NewTypes/NewTypes.csproj"/>
<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>
27 changes: 27 additions & 0 deletions src/RazorPages/RazorPagesIntro/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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);

private readonly ILogger<ErrorModel> _logger;

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>
19 changes: 19 additions & 0 deletions src/RazorPages/RazorPagesIntro/Pages/Privacy.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace RazorPagesIntro.Pages
{
public class PrivacyModel : PageModel
{
private readonly ILogger<PrivacyModel> _logger;

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

public void OnGet()
{
}
}
}
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>
48 changes: 48 additions & 0 deletions src/RazorPages/RazorPagesIntro/Pages/Shared/_Layout.cshtml.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
for details on configuring this project to bundle and minify static web assets. */

a.navbar-brand {
white-space: normal;
text-align: center;
word-break: break-all;
}

a {
color: #0077cc;
}

.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.border-top {
border-top: 1px solid #e5e5e5;
}
.border-bottom {
border-bottom: 1px solid #e5e5e5;
}

.box-shadow {
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}

button.accept-policy {
font-size: 1rem;
line-height: inherit;
}

.footer {
position: absolute;
bottom: 0;
width: 100%;
white-space: nowrap;
line-height: 60px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
3 changes: 3 additions & 0 deletions src/RazorPages/RazorPagesIntro/Pages/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@using RazorPagesIntro
@namespace RazorPagesIntro.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
3 changes: 3 additions & 0 deletions src/RazorPages/RazorPagesIntro/Pages/_ViewStart.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}
Loading

0 comments on commit dd2a82f

Please sign in to comment.