Adding test configuration
This commit is contained in:
24
MainProject/MainProject.csproj
Normal file
24
MainProject/MainProject.csproj
Normal file
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<PackageReference Include="NLog" Version="5.2.8" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Filters.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
11
MainProject/Models/Settings/AppSettings.cs
Normal file
11
MainProject/Models/Settings/AppSettings.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
|
||||
public class AppSettings
|
||||
{
|
||||
#nullable enable
|
||||
public Settings? Settings { get; set; }
|
||||
public PrivateSettings? PrivateSettings { get; set; }
|
||||
public OpenApiSettings? OpenApiSettings { get; set; }
|
||||
|
||||
#nullable disable
|
||||
}
|
||||
10
MainProject/Models/Settings/DatabaseConnection.cs
Normal file
10
MainProject/Models/Settings/DatabaseConnection.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
|
||||
public class DatabaseConnection
|
||||
{
|
||||
#nullable enable
|
||||
public string? SqlServer { get; set; }
|
||||
public string? Postgres { get; set; }
|
||||
public string? Mongodb { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
10
MainProject/Models/Settings/OpenApiSettings.cs
Normal file
10
MainProject/Models/Settings/OpenApiSettings.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
|
||||
public class OpenApiSettings
|
||||
{
|
||||
#nullable enable
|
||||
public string? TermsOfServiceUrl { get; set; }
|
||||
public OpenApiSettingsDetails? OpenApiContact { get; set; }
|
||||
public OpenApiSettingsDetails? OpenApiLicense { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
9
MainProject/Models/Settings/OpenApiSettingsDetails.cs
Normal file
9
MainProject/Models/Settings/OpenApiSettingsDetails.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
|
||||
public class OpenApiSettingsDetails
|
||||
{
|
||||
#nullable enable
|
||||
public string? Name { get; set; }
|
||||
public string? Url { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
8
MainProject/Models/Settings/PrivateSettings.cs
Normal file
8
MainProject/Models/Settings/PrivateSettings.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
|
||||
public class PrivateSettings
|
||||
{
|
||||
#nullable enable
|
||||
public DatabaseConnection? DatabaseConnection { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
10
MainProject/Models/Settings/Settings.cs
Normal file
10
MainProject/Models/Settings/Settings.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
|
||||
public class Settings
|
||||
{
|
||||
#nullable enable
|
||||
public string? Name { get; set; }
|
||||
public string? Version { get; set; }
|
||||
public string? Description { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
14
MainProject/NLog.config
Normal file
14
MainProject/NLog.config
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
|
||||
<targets>
|
||||
<target name="logfile" xsi:type="File" fileName="file.txt" />
|
||||
<target name="logconsole" xsi:type="Console" />
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Info" writeTo="logconsole" />
|
||||
<logger name="*" minlevel="Debug" writeTo="logfile" />
|
||||
</rules>
|
||||
</nlog>
|
||||
91
MainProject/Program.cs
Normal file
91
MainProject/Program.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
using BasicDotnetTemplate.MainProject.Utils;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject;
|
||||
internal static class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var _configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(System.AppDomain.CurrentDomain.BaseDirectory)
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
// REGISTER SERVICES HERE
|
||||
builder.Services.AddSingleton<IConfiguration>(_configuration);
|
||||
|
||||
PrivateSettings privateSettings = new PrivateSettings();
|
||||
_configuration.GetSection("PrivateSettings").Bind(privateSettings);
|
||||
|
||||
builder.Services.Configure<AppSettings>(_configuration.GetSection("AppSettings"));
|
||||
builder.Services.Configure<PrivateSettings>(_configuration.GetSection("PrivateSettings"));
|
||||
|
||||
builder.Services.AddAuthentication();
|
||||
builder.Services.AddAuthorization();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
|
||||
AppSettings appSettings = new AppSettings();
|
||||
appSettings.PrivateSettings = privateSettings;
|
||||
_configuration.GetSection("AppSettings").Bind(appSettings);
|
||||
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
{
|
||||
options.SwaggerDoc("v1", new OpenApiInfo
|
||||
{
|
||||
Version = appSettings?.Settings?.Version,
|
||||
Title = appSettings?.Settings?.Name,
|
||||
Description = appSettings?.Settings?.Description,
|
||||
TermsOfService = new Uri("https://example.com/terms"),
|
||||
Contact = new OpenApiContact
|
||||
{
|
||||
Name = "Example Contact",
|
||||
Url = new Uri("https://example.com/contact")
|
||||
},
|
||||
License = new OpenApiLicense
|
||||
{
|
||||
Name = "Example License",
|
||||
Url = new Uri("https://example.com/license")
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// REGISTER MIDDLEWARE HERE
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}"
|
||||
);
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseStaticFiles();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(options =>
|
||||
{
|
||||
options.InjectStylesheet("/swagger-ui/custom.css");
|
||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
|
||||
});
|
||||
}
|
||||
|
||||
app.Run();
|
||||
}
|
||||
|
||||
}
|
||||
12
MainProject/Utils/AppSettingsUtils.cs
Normal file
12
MainProject/Utils/AppSettingsUtils.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Utils;
|
||||
|
||||
public static class AppSettingsUtils
|
||||
{
|
||||
static AppSettingsUtils() { }
|
||||
public static bool CheckAppSettings(AppSettings appSetting)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
22
MainProject/appsettings.json
Normal file
22
MainProject/appsettings.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"AppSettings" :
|
||||
{
|
||||
"Settings": {
|
||||
"Name": "MainProject",
|
||||
"Version": "v1.0",
|
||||
"Description": "This template contains basic configuration for a .Net 8 backend"
|
||||
},
|
||||
"OpenApiSettings": {
|
||||
"TermsOfServiceUrl": "",
|
||||
"OpenApiContact": {
|
||||
"Name": "",
|
||||
"Url": ""
|
||||
},
|
||||
"OpenApiLicense": {
|
||||
"Name": "",
|
||||
"Url": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
20
MainProject/wwwroot/swagger-ui/custom.css
Normal file
20
MainProject/wwwroot/swagger-ui/custom.css
Normal file
@@ -0,0 +1,20 @@
|
||||
.topbar-wrapper img[alt="Swagger UI"], .topbar-wrapper span {
|
||||
src
|
||||
}
|
||||
|
||||
.topbar-wrapper .link:after {
|
||||
/* content: 'Unoffical McLaren F1 API'; */
|
||||
/* color: #fff; */
|
||||
visibility: visible;
|
||||
display: block;
|
||||
position: absolute;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.swagger-ui .topbar .download-url-wrapper .select-label select {
|
||||
border-color: #1cd6ef;
|
||||
}
|
||||
|
||||
.swagger-ui .info .title small:last-child {
|
||||
background-color: #1cd6ef !important;
|
||||
}
|
||||
BIN
MainProject/wwwroot/swagger/favicon-16x16.png
Normal file
BIN
MainProject/wwwroot/swagger/favicon-16x16.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
MainProject/wwwroot/swagger/favicon-32x32.png
Normal file
BIN
MainProject/wwwroot/swagger/favicon-32x32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
BIN
MainProject/wwwroot/swagger/favicon.ico
Normal file
BIN
MainProject/wwwroot/swagger/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
Reference in New Issue
Block a user