Adding test configuration

This commit is contained in:
2024-03-10 20:36:07 +01:00
parent 5ac0d169b6
commit ddb5223572
22 changed files with 112 additions and 21 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,3 @@
**/obj
**/bin
appsettings.*.json
**/appsettings.*.json

4
.vscode/launch.json vendored
View File

@@ -5,12 +5,12 @@
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"name": ".NET Rest Api",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net8.0/BasicDotnetTemplate.dll",
"program": "${workspaceFolder}/MainProject/bin/Debug/net8.0/MainProject.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console

6
.vscode/tasks.json vendored
View File

@@ -7,7 +7,7 @@
"type": "process",
"args": [
"build",
"${workspaceFolder}/BasicDotnetTemplate.csproj",
"${workspaceFolder}/MainProject/MainProject.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
@@ -19,7 +19,7 @@
"type": "process",
"args": [
"publish",
"${workspaceFolder}/BasicDotnetTemplate.csproj",
"${workspaceFolder}/MainProject/MainProject.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
@@ -33,7 +33,7 @@
"watch",
"run",
"--project",
"${workspaceFolder}/BasicDotnetTemplate.csproj"
"${workspaceFolder}/MainProject.csproj"
],
"problemMatcher": "$msCompile"
}

28
BasicDotnetTemplate.sln Normal file
View File

@@ -0,0 +1,28 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MainProject", "MainProject\MainProject.csproj", "{5BC4F94C-35BC-4436-A107-9D85E53A9E84}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MainProject.Tests", "MainProject.Tests\MainProject.Tests.csproj", "{A672CB00-DC99-4847-A384-B857C5E69301}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5BC4F94C-35BC-4436-A107-9D85E53A9E84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5BC4F94C-35BC-4436-A107-9D85E53A9E84}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5BC4F94C-35BC-4436-A107-9D85E53A9E84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5BC4F94C-35BC-4436-A107-9D85E53A9E84}.Release|Any CPU.Build.0 = Release|Any CPU
{A672CB00-DC99-4847-A384-B857C5E69301}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A672CB00-DC99-4847-A384-B857C5E69301}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A672CB00-DC99-4847-A384-B857C5E69301}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A672CB00-DC99-4847-A384-B857C5E69301}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,25 @@
using BasicDotnetTemplate.MainProject.Models.Settings;
using BasicDotnetTemplate.MainProject.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace BasicDotnetTemplate.MainProject.Tests
{
[TestClass]
public class AppSettingsUtils_Tests
{
private readonly AppSettings _appSettings;
public AppSettingsUtils_Tests()
{
_appSettings = new AppSettings();
}
[TestMethod]
public void AppSettingsUtils_Tests_IsValid()
{
bool result = AppSettingsUtils.CheckAppSettings(_appSettings);
Assert.IsTrue(result);
}
}
}

View File

@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MainProject\MainProject.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,4 +1,4 @@
namespace BasicDotnetTemplate.Models.Settings;
namespace BasicDotnetTemplate.MainProject.Models.Settings;
public class AppSettings
{

View File

@@ -1,4 +1,4 @@
namespace BasicDotnetTemplate.Models.Settings;
namespace BasicDotnetTemplate.MainProject.Models.Settings;
public class DatabaseConnection
{

View File

@@ -1,4 +1,4 @@
namespace BasicDotnetTemplate.Models.Settings;
namespace BasicDotnetTemplate.MainProject.Models.Settings;
public class OpenApiSettings
{

View File

@@ -1,4 +1,4 @@
namespace BasicDotnetTemplate.Models.Settings;
namespace BasicDotnetTemplate.MainProject.Models.Settings;
public class OpenApiSettingsDetails
{

View File

@@ -1,4 +1,4 @@
namespace BasicDotnetTemplate.Models.Settings;
namespace BasicDotnetTemplate.MainProject.Models.Settings;
public class PrivateSettings
{

View File

@@ -1,4 +1,4 @@
namespace BasicDotnetTemplate.Models.Settings;
namespace BasicDotnetTemplate.MainProject.Models.Settings;
public class Settings
{

View File

@@ -1,7 +1,9 @@
using Microsoft.OpenApi.Models;
using BasicDotnetTemplate.Models.Settings;
using System;
using Microsoft.OpenApi.Models;
using BasicDotnetTemplate.MainProject.Models.Settings;
using BasicDotnetTemplate.MainProject.Utils;
namespace BasicDotnetTemplate;
namespace BasicDotnetTemplate.MainProject;
internal static class Program
{
public static void Main(string[] args)
@@ -9,7 +11,7 @@ internal static class Program
var builder = WebApplication.CreateBuilder(args);
var _configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.SetBasePath(System.AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables()
@@ -56,7 +58,6 @@ internal static class Program
});
});
var app = builder.Build();
// REGISTER MIDDLEWARE HERE

View 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;
}
}

View File

@@ -2,7 +2,7 @@
"AppSettings" :
{
"Settings": {
"Name": "BasicDotnetTemplate",
"Name": "MainProject",
"Version": "v1.0",
"Description": "This template contains basic configuration for a .Net 8 backend"
},

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -1,3 +1 @@
# BasicDotnetTemplate
# MainProject