Browse Source

Add FastEndpoints to CSharp (#7001)

* Add FastEndpoints framework to CSharp

* update FastEndpoints library to latest version

* fix FastEndpoints listening address issue when running in docker
Dĵ ΝιΓΞΗΛψΚ 3 years ago
parent
commit
a781f7562f

+ 37 - 0
frameworks/CSharp/fastendpoints/.gitignore

@@ -0,0 +1,37 @@
+[Oo]bj/
+[Bb]in/
+TestResults/
+.nuget/
+*.sln.ide/
+_ReSharper.*/
+.idea/
+packages/
+artifacts/
+PublishProfiles/
+.vs/
+*.user
+*.suo
+*.cache
+*.docstates
+_ReSharper.*
+nuget.exe
+*net45.csproj
+*net451.csproj
+*k10.csproj
+*.psess
+*.vsp
+*.pidb
+*.userprefs
+*DS_Store
+*.ncrunchsolution
+*.*sdf
+*.ipch
+*.swp
+*~
+.build/
+.testPublish/
+launchSettings.json
+BenchmarkDotNet.Artifacts/
+BDN.Generated/
+binaries/
+global.json

+ 14 - 0
frameworks/CSharp/fastendpoints/Benchmarks/Benchmarks.csproj

@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk.Web">
+
+    <PropertyGroup>
+        <TargetFramework>net6.0</TargetFramework>
+        <Nullable>enable</Nullable>
+        <ImplicitUsings>enable</ImplicitUsings>
+        <NoWarn>CA2016;IDE1006</NoWarn>
+    </PropertyGroup>
+
+    <ItemGroup>
+        <PackageReference Include="FastEndpoints" Version="2.17.0" />
+    </ItemGroup>
+
+</Project>

+ 25 - 0
frameworks/CSharp/fastendpoints/Benchmarks/Benchmarks.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.0.32002.185
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "Benchmarks.csproj", "{95F15ACC-FFB8-4C45-BF4E-6E2B602C1EBA}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{95F15ACC-FFB8-4C45-BF4E-6E2B602C1EBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{95F15ACC-FFB8-4C45-BF4E-6E2B602C1EBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{95F15ACC-FFB8-4C45-BF4E-6E2B602C1EBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{95F15ACC-FFB8-4C45-BF4E-6E2B602C1EBA}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {975848F3-00CE-49FC-A82F-86DDC0A3CC6F}
+	EndGlobalSection
+EndGlobal

+ 21 - 0
frameworks/CSharp/fastendpoints/Benchmarks/Endpoints/JsonEndpoint.cs

@@ -0,0 +1,21 @@
+namespace Benchmarks.Endpoints;
+
+public class Response
+{
+    public string message => "Hello, World!";
+}
+
+public class JsonEndpoint : Endpoint<EmptyRequest, Response>
+{
+    public override void Configure()
+    {
+        Get("/json");
+        AllowAnonymous();
+    }
+
+    public override Task HandleAsync(EmptyRequest r, CancellationToken ct)
+    {
+        HttpContext.Response.ContentLength = 27;
+        return SendAsync(Response);
+    }
+}

+ 17 - 0
frameworks/CSharp/fastendpoints/Benchmarks/Endpoints/PlainTextEndpoint.cs

@@ -0,0 +1,17 @@
+namespace Benchmarks.Endpoints;
+
+public class PlainTextEndpoint : Endpoint<EmptyRequest, object>
+{
+    private static readonly byte[] payload = System.Text.Encoding.UTF8.GetBytes("Hello, World!");
+
+    public override void Configure()
+    {
+        Get("/plaintext");
+        AllowAnonymous();
+    }
+
+    public override Task HandleAsync(EmptyRequest r, CancellationToken ct)
+    {
+        return SendBytesAsync(payload, contentType: "text/plain");
+    }
+}

+ 9 - 0
frameworks/CSharp/fastendpoints/Benchmarks/Program.cs

@@ -0,0 +1,9 @@
+global using FastEndpoints;
+
+var builder = WebApplication.CreateBuilder();
+builder.Services.AddFastEndpoints();
+
+var app = builder.Build();
+app.UseAuthorization();
+app.UseFastEndpoints();
+app.Run();

+ 8 - 0
frameworks/CSharp/fastendpoints/Benchmarks/appsettings.Development.json

@@ -0,0 +1,8 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Information",
+      "Microsoft.AspNetCore": "Warning"
+    }
+  }
+}

+ 15 - 0
frameworks/CSharp/fastendpoints/Benchmarks/appsettings.json

@@ -0,0 +1,15 @@
+{
+  "Logging": {
+    "LogLevel": {
+      "Default": "Warning"
+    }
+  },
+  "AllowedHosts": "*",
+  "Kestrel": {
+    "Endpoints": {
+      "Http": {
+        "Url": "http://*:8080"
+      }
+    }
+  }
+}

+ 26 - 0
frameworks/CSharp/fastendpoints/README.md

@@ -0,0 +1,26 @@
+# FastEndpoints Tests on Windows and Linux
+This includes tests for plaintext and json serialization.
+
+## Infrastructure Software Versions
+
+**Language**
+
+* C# 10.0
+
+**Platforms**
+
+* .NET Core (Windows and Linux)
+
+**Web Servers**
+
+* [Kestrel](https://github.com/dotnet/aspnetcore/tree/main/src/Servers/Kestrel)
+
+**Web Stack**
+
+* [FastEndpoints](https://fast-endpoints.com/)
+* ASP.Net 6
+
+## Paths & Source for Tests
+
+* [Plaintext](Benchmarks/Endpoints/PlainTextEndpoint.cs): "http://localhost:8080/plaintext"
+* [JSON Serialization](Benchmarks/Endpoints/JsonEndpoint.cs): "http://localhost:8080/json"

+ 26 - 0
frameworks/CSharp/fastendpoints/benchmark_config.json

@@ -0,0 +1,26 @@
+{
+  "framework": "fastendpoints",
+  "tests": [
+    {
+      "default": {
+        "plaintext_url": "/plaintext",
+        "json_url": "/json",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Micro",
+        "database": "None",
+        "framework": "FastEndpoints",
+        "language": "C#",
+        "orm": "Raw",
+        "platform": ".NET",
+        "flavor": "CoreCLR",
+        "webserver": "Kestrel",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "FastEndpoints",
+        "notes": "",
+        "versus": "aspcore"
+      }
+    }
+  ]
+}

+ 15 - 0
frameworks/CSharp/fastendpoints/config.toml

@@ -0,0 +1,15 @@
+[framework]
+name = "fastendpoints"
+
+[main]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+approach = "Realistic"
+classification = "Micro"
+database = "None"
+database_os = "Linux"
+os = "Linux"
+orm = "Raw"
+platform = ".NET"
+webserver = "Kestrel"
+versus = "aspcore"

+ 12 - 0
frameworks/CSharp/fastendpoints/fastendpoints.dockerfile

@@ -0,0 +1,12 @@
+FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
+WORKDIR /app
+COPY Benchmarks .
+RUN dotnet publish -c Release -o out
+
+FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
+WORKDIR /app
+COPY --from=build /app/out ./
+
+EXPOSE 8080
+
+ENTRYPOINT ["dotnet", "Benchmarks.dll"]