Skip to content

Commit

Permalink
Merge Update to .NET 8 #190
Browse files Browse the repository at this point in the history
  • Loading branch information
domi-b authored Jan 23, 2024
2 parents ba13951 + 734a72d commit ba2b714
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x

# Run the npm ci command before building
# the dotnet project, because the project
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<AnalysisLevel>latest-all</AnalysisLevel>
<AnalysisLevel>8.0-recommended</AnalysisLevel>
<NoWarn>CS1591,CS8618,CS8620</NoWarn>
<VersionPrefix>1.0</VersionPrefix>
<Product>interlis-model-browser</Product>
Expand Down
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
ARG VERSION
ARG REVISION
Expand Down Expand Up @@ -26,7 +26,7 @@ RUN dotnet publish "ModelRepoBrowser.csproj" \
-p:SourceRevisionId=${REVISION} \
-o ${PUBLISH_DIR}

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS final
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
ENV HOME=/app
ENV TZ=Europe/Zurich
ENV ASPNETCORE_ENVIRONMENT=Production
Expand All @@ -40,14 +40,16 @@ RUN \
apt-get install -y curl && \
rm -rf /var/lib/apt/lists/*

EXPOSE 80
EXPOSE 8080

# Set default locale
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8

COPY --from=build /app/publish $HOME

HEALTHCHECK CMD curl --fail http://localhost/ || exit 1
USER $APP_UID

HEALTHCHECK CMD curl --fail http://localhost:8080/ || exit 1

ENTRYPOINT ["dotnet", "ModelRepoBrowser.dll"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Folgende Komponenten müssen auf dem Entwicklungsrechner installiert sein:
* Git
* Docker
* Visual Studio 2022 oder Visual Studio Code
* .NET 6
* .NET 8
* Node.js 16 LTS

## Neue Version erstellen
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/ModelController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ModelController(ILogger<ModelController> logger, RepoBrowserContext conte
/// <param name="name" example="SZ_Schutzbauten_Wasser_V1">The name of the model.</param>
/// <returns>The <see cref="Model"/> with the specified <paramref name="md5"/> and <paramref name="name"/> or <c>null</c> if it does not exist.</returns>
[HttpGet("{md5}/{name}")]
[SwaggerResponse(StatusCodes.Status200OK, "The INTERLIS model.", typeof(Model), new[] { "application/json" })]
[SwaggerResponse(StatusCodes.Status200OK, "The INTERLIS model.", typeof(Model), ContentTypes = new[] { "application/json" })]
[SwaggerResponse(StatusCodes.Status204NoContent, "The INTERLIS model for the requested md5 and name combination does not exist. No content returned.", ContentTypes = new[] { "application/json" })]
public Model? ModelDetails(string md5, string name)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public SearchController(ILogger<SearchController> logger, RepoBrowserContext con
/// that matched the <paramref name="query"/>.
/// </returns>
[HttpGet]
[SwaggerResponse(StatusCodes.Status200OK, "The INTERLIS repository tree containinig all models matching the search.", typeof(Repository), new[] { "application/json" })]
[SwaggerResponse(StatusCodes.Status200OK, "The INTERLIS repository tree containinig all models matching the search.", typeof(Repository), ContentTypes = new[] { "application/json" })]
[SwaggerResponse(StatusCodes.Status204NoContent, "No INTERLIS model matching the search query exists. No repository tree returned.", ContentTypes = new[] { "application/json" })]
[SwaggerResponse(StatusCodes.Status400BadRequest, "The server cannot process the request due to invalid or malformed request.", typeof(ProblemDetails), new[] { "application/json" })]
[SwaggerResponse(StatusCodes.Status400BadRequest, "The server cannot process the request due to invalid or malformed request.", typeof(ProblemDetails), ContentTypes = new[] { "application/json" })]
public async Task<Repository?> Search([FromQuery] string? query, [FromQuery] string[]? repositoryNames = null, [FromQuery] string[]? issuers = null, [FromQuery] string[]? schemaLanguages = null, [FromQuery] string[]? dependsOnModels = null)
{
logger.LogInformation("Search with query <{SearchQuery}>", query);
Expand Down Expand Up @@ -121,9 +121,9 @@ private Dictionary<string, Repository> FilterRepositories(string[]? repositoryNa
/// <param name="dependsOnModels" example='["CHAdminCodes_V1", "GeometryCHLV95_V1"]'>The dependsOnModels list to filter the found models by.</param>
/// <returns>A sequence of <see cref="Model.Name"/> related to <paramref name="query"/>.</returns>
[HttpGet("suggest")]
[SwaggerResponse(StatusCodes.Status200OK, "The names of all INTERLIS models matching the search.", typeof(IEnumerable<string>), new[] { "application/json" })]
[SwaggerResponse(StatusCodes.Status200OK, "The names of all INTERLIS models matching the search.", typeof(IEnumerable<string>), ContentTypes = new[] { "application/json" })]
[SwaggerResponse(StatusCodes.Status204NoContent, "No INTERLIS model matching the search query exists. Nothing returned.", ContentTypes = new[] { "application/json" })]
[SwaggerResponse(StatusCodes.Status400BadRequest, "The server cannot process the request due to invalid or malformed request.", typeof(ProblemDetails), new[] { "application/json" })]
[SwaggerResponse(StatusCodes.Status400BadRequest, "The server cannot process the request due to invalid or malformed request.", typeof(ProblemDetails), ContentTypes = new[] { "application/json" })]
public async Task<IEnumerable<string>> GetSearchSuggestions([FromQuery] string? query, [FromQuery] string[]? repositoryNames = null, [FromQuery] string[]? issuers = null, [FromQuery] string[]? schemaLanguages = null, [FromQuery] string[]? dependsOnModels = null)
{
logger.LogDebug("Get search options for <{SearchQuery}>", query);
Expand Down
2 changes: 1 addition & 1 deletion src/Crawler/RepositoryCrawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class RepositoryCrawler : IRepositoryCrawler
{
private readonly ILogger<RepositoryCrawler> logger;
private readonly HttpClient httpClient;
private IDictionary<string, Repository> modelRepositories;
private ConcurrentDictionary<string, Repository> modelRepositories;

public RepositoryCrawler(ILogger<RepositoryCrawler> logger, IHttpClientFactory httpClientFactory)
{
Expand Down
15 changes: 6 additions & 9 deletions src/ModelRepoBrowser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
Expand All @@ -16,14 +16,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.4.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 7 additions & 5 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
using Microsoft.OpenApi.Models;
using ModelRepoBrowser;
using ModelRepoBrowser.Crawler;
using Npgsql.Logging;
using Npgsql;
using System.Reflection;
using System.Text.Json.Serialization;

NpgsqlLogManager.Provider = new ConsoleLoggingProvider(NpgsqlLogLevel.Debug, true, false);
NpgsqlLogManager.IsParameterLoggingEnabled = true;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllersWithViews();

var connectionString = builder.Configuration.GetConnectionString("RepoBrowserContext");
builder.Services.AddNpgsql<RepoBrowserContext>(connectionString, options => options.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery));
builder.Services.AddNpgsql<RepoBrowserContext>(connectionString!, options => options.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery));

builder.Services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; });

Expand All @@ -31,7 +28,9 @@
// Custom order in Swagger UI.
options.OrderActionsBy(apiDescription =>
{
#pragma warning disable CA1861 // Avoid constant arrays as arguments
var customOrder = new[] { "Search", "Model", "Version" };
#pragma warning restore CA1861 // Avoid constant arrays as arguments
var controllerName = (apiDescription.ActionDescriptor as ControllerActionDescriptor)?.ControllerName;
return $"{Array.IndexOf(customOrder, controllerName)}";
});
Expand All @@ -52,6 +51,9 @@

var app = builder.Build();

var loggerFactory = app.Services.GetRequiredService<ILoggerFactory>();
NpgsqlLoggingConfiguration.InitializeLogging(loggerFactory);

if (!app.Environment.IsDevelopment())
{
app.UseHsts();
Expand Down
23 changes: 13 additions & 10 deletions tests/ModelRepoBrowser.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<RootNamespace>ModelRepoBrowser</RootNamespace>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<NoWarn>$(NoWarn),CA1001,CA1014,CS8625,CA2000,CA2007</NoWarn>
<NoWarn>$(NoWarn),CA1001,CA1014,CS8625,CA2000,CA2007,CA1861</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Moq" Version="4.18.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="RichardSzalay.MockHttp" Version="6.0.0" />
<PackageReference Include="Bogus" Version="35.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="RichardSzalay.MockHttp" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion tests/RepositoryCrawlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class RepositoryCrawlerTest
{
private Mock<ILogger<RepositoryCrawler>> loggerMock;
private Mock<IHttpClientFactory> httpClientFactory;
private IRepositoryCrawler repositoryCrawler;
private RepositoryCrawler repositoryCrawler;
private MockHttpMessageHandler mockHttp;

[TestInitialize]
Expand All @@ -42,6 +42,8 @@ private void SetupHttpMockFiles()
.Respond(HttpStatusCode.OK);
}
}

mockHttp.Fallback.Respond(HttpStatusCode.NotFound);
}

private void SetupRepositoryCrawlerInstance(HttpClient httpClient)
Expand Down
4 changes: 2 additions & 2 deletions tests/TestHelpers/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ public static IEnumerable<T> AssertSingleItem<T>(this IEnumerable<T> collection,
/// </exception>
public static IEnumerable<T> AssertSingleItem<T>(this IEnumerable<T> collection, Func<T, bool> predicate, Action<T> asserter, string message, params object[] parameters)
{
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
if (asserter == null) throw new ArgumentNullException(nameof(asserter));
ArgumentNullException.ThrowIfNull(predicate);
ArgumentNullException.ThrowIfNull(asserter);

return AssertItems(collection, predicate, asserter, 1, message, parameters);
}
Expand Down
14 changes: 7 additions & 7 deletions tests/TestHelpers/MessageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static class MessageHelper
/// <exception cref="ArgumentNullException"><paramref name="action"/> or <paramref name="message"/> is <c>null</c>.</exception>
public static void Assert(Action action, string message, params object[] parameters)
{
if (action == null) throw new ArgumentNullException(nameof(action));
if (message == null) throw new ArgumentNullException(nameof(message));
ArgumentNullException.ThrowIfNull(action);
ArgumentNullException.ThrowIfNull(message);

// Wrap the action delegate in a function delegate to reuse
// Assert(Func<TResult>, string, params object[]) method
Expand All @@ -44,8 +44,8 @@ public static void Assert(Action action, string message, params object[] paramet
/// <exception cref="ArgumentNullException"><paramref name="f"/> or <paramref name="message"/> is <c>null</c>.</exception>
public static TResult Assert<TResult>(Func<TResult> f, string message, params object[] parameters)
{
if (f == null) throw new ArgumentNullException(nameof(f));
if (message == null) throw new ArgumentNullException(nameof(message));
ArgumentNullException.ThrowIfNull(f);
ArgumentNullException.ThrowIfNull(message);

try
{
Expand Down Expand Up @@ -86,7 +86,7 @@ public static string BuildMessage(Exception ex, string message, object[] paramet
/// <exception cref="ArgumentNullException"><paramref name="ex"/> or <paramref name="defaultMessage"/> is <c>null</c>.</exception>
public static string BuildMessage(Exception ex, string defaultMessage, object[] defaultParameters, string customMessage, object[] customParameters)
{
if (ex == null) throw new ArgumentNullException(nameof(ex));
ArgumentNullException.ThrowIfNull(ex);

return CombineMessages(ex.Message, CombineDefaultAndCustomMessage(defaultMessage, defaultParameters, customMessage, customParameters));
}
Expand Down Expand Up @@ -115,7 +115,7 @@ public static string CombineDefaultAndCustomMessage(string defaultMessage, strin
/// <exception cref="ArgumentNullException"><paramref name="defaultMessage"/> is <c>null</c>.</exception>
public static string CombineDefaultAndCustomMessage(string defaultMessage, object[] defaultParameters, string customMessage, object[] customParameters)
{
if (defaultMessage == null) throw new ArgumentNullException(nameof(defaultMessage));
ArgumentNullException.ThrowIfNull(defaultMessage);

if (defaultParameters != null && defaultParameters.Length > 0)
{
Expand All @@ -139,7 +139,7 @@ public static string CombineDefaultAndCustomMessage(string defaultMessage, objec
/// <returns>The combined string.</returns>
public static string CombineMessages(params string[] messages)
{
if (messages == null) throw new ArgumentNullException(nameof(messages));
ArgumentNullException.ThrowIfNull(messages);
if (messages.Length == 0) throw new ArgumentOutOfRangeException(nameof(messages));

return string.Join(" ", messages.Select(exp => exp.Trim()));
Expand Down
2 changes: 1 addition & 1 deletion tests/VersionControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public class VersionControllerTest
public void Get()
{
var controller = new VersionController();
Assert.AreEqual("1.0", controller.Get());
StringAssert.StartsWith(controller.Get(), "1.0", StringComparison.Ordinal);
}
}

0 comments on commit ba2b714

Please sign in to comment.