Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ASP.NET dotnet new Template #1656

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@
<PackageVersion Include="Polly" Version="8.5.1" />
<PackageVersion Include="Polyfill" Version="7.13.0" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="Sourcy.DotNet" Version="0.0.81" />
<PackageVersion Include="Sourcy.Git" Version="0.0.81" />
<PackageVersion Include="Sourcy.DotNet" Version="0.0.82">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Sourcy.Git" Version="0.0.82">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="StreamJsonRpc" Version="2.20.20" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.Text.Json" Version="9.0.1" />
Expand All @@ -65,4 +71,4 @@
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.1" />
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion TUnit.Templates/content/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ItemGroup>
<ItemGroup Condition="$(MSBuildProjectName.Contains('TestProject'))">
<Using Include="TUnit.Core.HookType" Static="True" />
<Using Include="TUnit.Core" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "Tom Longhurst",
"description": "Templates for getting started with TUnit",
"classifications": [
"Test",
"TUnit"
],
"name": "TUnit Test Project",
"identity": "TUnit.Test.Project",
"groupIdentity": "TUnit",
"shortName": "TUnit",
"tags": {
"language": "C#",
"type": "project"
},
"sourceName": "TestProject",
"preferNameDirectory": true
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="TUnit" Version="0.7.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WebApp\WebApp.csproj" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions TUnit.Templates/content/TUnit.AspNet/TestProject/Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace TestProject;

public class Tests
{
[ClassDataSource<WebApplicationFactory>(Shared = SharedType.PerTestSession)]
public required WebApplicationFactory WebApplicationFactory { get; init; }

[Test]
public async Task Test()
{
var client = WebApplicationFactory.CreateClient();

var response = await client.GetAsync("/ping");

var stringContent = await response.Content.ReadAsStringAsync();

await Assert.That(stringContent).IsEqualTo("Hello, World!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.Mvc.Testing;
using TUnit.Core.Interfaces;

namespace TestProject;

public class WebApplicationFactory : WebApplicationFactory<Program>, IAsyncInitializer
{
public Task InitializeAsync()
{
_ = Server;

return Task.CompletedTask;
}
}
13 changes: 13 additions & 0 deletions TUnit.Templates/content/TUnit.AspNet/WebApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();

var app = builder.Build();

app.UseHttpsRedirection();

app.MapGet("/ping", () => "Hello, World!");

app.Run();

public partial class Program;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:24820",
"sslPort": 44340
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5298",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7061;http://localhost:5298",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
14 changes: 14 additions & 0 deletions TUnit.Templates/content/TUnit.AspNet/WebApp/WebApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.12" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.12"/>
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions TUnit.Templates/content/TUnit.AspNet/WebApp/WebApp.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@WebApp_HostAddress = http://localhost:5298

GET {{WebApp_HostAddress}}/weatherforecast/
Accept: application/json

###
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions TUnit.Templates/content/TUnit.AspNet/WebApp/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
24 changes: 23 additions & 1 deletion TUnit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TUnit.Engine.Tests", "TUnit
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject", "TUnit.Templates\content\TUnit\TestProject.csproj", "{4BFDDFDB-96D9-42AA-85CE-9FBD017ACBE1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Templates", "Templates", "{835A7825-FC06-46E2-B3B1-2BF791A22B97}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Basic", "Basic", "{1CE32FD7-4B3B-4639-B88F-67FB339461F2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AspNet", "AspNet", "{23F41068-7C7E-435C-B6AB-4258B6380DC2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject", "TUnit.Templates\content\TUnit.AspNet\TestProject\TestProject.csproj", "{2BCFDB65-AF9F-4CC4-B215-4C0035906F2A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApp", "TUnit.Templates\content\TUnit.AspNet\WebApp\WebApp.csproj", "{D778BF96-702F-4A59-A2D5-E348A3320E58}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -189,6 +199,14 @@ Global
{4BFDDFDB-96D9-42AA-85CE-9FBD017ACBE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4BFDDFDB-96D9-42AA-85CE-9FBD017ACBE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4BFDDFDB-96D9-42AA-85CE-9FBD017ACBE1}.Release|Any CPU.Build.0 = Release|Any CPU
{2BCFDB65-AF9F-4CC4-B215-4C0035906F2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2BCFDB65-AF9F-4CC4-B215-4C0035906F2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BCFDB65-AF9F-4CC4-B215-4C0035906F2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2BCFDB65-AF9F-4CC4-B215-4C0035906F2A}.Release|Any CPU.Build.0 = Release|Any CPU
{D778BF96-702F-4A59-A2D5-E348A3320E58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D778BF96-702F-4A59-A2D5-E348A3320E58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D778BF96-702F-4A59-A2D5-E348A3320E58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D778BF96-702F-4A59-A2D5-E348A3320E58}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -217,7 +235,11 @@ Global
{744CD312-B913-48E0-B917-531ED2A9A541} = {503DA9FA-045D-4910-8AF6-905E6048B1F1}
{54D5F1A7-7979-4C07-8FE1-426233846018} = {503DA9FA-045D-4910-8AF6-905E6048B1F1}
{E0E07E64-BC0A-489E-B562-2982F3836994} = {62AD1EAF-43C4-4AC0-B9FA-CD59739B3850}
{4BFDDFDB-96D9-42AA-85CE-9FBD017ACBE1} = {0BA988BF-ADCE-4343-9098-B4EF65C43709}
{1CE32FD7-4B3B-4639-B88F-67FB339461F2} = {835A7825-FC06-46E2-B3B1-2BF791A22B97}
{4BFDDFDB-96D9-42AA-85CE-9FBD017ACBE1} = {1CE32FD7-4B3B-4639-B88F-67FB339461F2}
{23F41068-7C7E-435C-B6AB-4258B6380DC2} = {835A7825-FC06-46E2-B3B1-2BF791A22B97}
{2BCFDB65-AF9F-4CC4-B215-4C0035906F2A} = {23F41068-7C7E-435C-B6AB-4258B6380DC2}
{D778BF96-702F-4A59-A2D5-E348A3320E58} = {23F41068-7C7E-435C-B6AB-4258B6380DC2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {109D285A-36B3-4503-BCDF-8E26FB0E2C5B}
Expand Down
Loading