Add test cases
All checks were successful
Build, Push and Run Container / build (push) Successful in 27s

This commit is contained in:
2025-08-21 17:23:52 +02:00
parent 00e79097d6
commit b00cebbd0a
4 changed files with 51 additions and 13 deletions

View File

@@ -12,6 +12,7 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using ProofOfConcept.Models; using ProofOfConcept.Models;
using ProofOfConcept.Services; using ProofOfConcept.Services;
using ProofOfConcept.Utilities; using ProofOfConcept.Utilities;
using SzakatsA.Result;
Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true; Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;
@@ -137,7 +138,7 @@ builder.Services
}); });
// Add own services // Add own services
builder.Services.AddSingleton<IMessageProcessor, MessageProcessor>(); builder.Services.AddSingleton<MessageProcessor>();
builder.Services.AddTransient<ITeslaAuthenticatorService, TeslaAuthenticatorService>(); builder.Services.AddTransient<ITeslaAuthenticatorService, TeslaAuthenticatorService>();
builder.Services.AddTransient<ZoneDeterminatorService>(); builder.Services.AddTransient<ZoneDeterminatorService>();
@@ -418,6 +419,40 @@ app.MapGet("/Status", async ([FromServices] ILogger<Configurator> logger, [FromS
return Results.Ok(sb.ToString()); return Results.Ok(sb.ToString());
}); });
app.MapGet("/TestStartParking", async ([FromServices] ILogger<Configurator> logger, [FromServices] MessageProcessor messageProcessor) =>
{
logger.LogTrace("Test Start Parking...");
await messageProcessor.ProcessMessage("5YJ3E7EB7KF291652", "location", "{\"latitude\":47.410323,\"longitude\":19.067579}");
await messageProcessor.ProcessMessage("5YJ3E7EB7KF291652", "gear", "P");
await messageProcessor.ProcessMessage("5YJ3E7EB7KF291652", "locked", "true");
await messageProcessor.ProcessMessage("5YJ3E7EB7KF291652", "driverseatoccupied", "false");
logger.LogInformation("All messages sent");
});
app.MapGet("/TestStopParking", async ([FromServices] ILogger<Configurator> logger, [FromServices] MessageProcessor messageProcessor) =>
{
logger.LogTrace("Test Stop Parking...");
await messageProcessor.ProcessMessage("5YJ3E7EB7KF291652", "locked", "false");
await messageProcessor.ProcessMessage("5YJ3E7EB7KF291652", "gear", "D");
logger.LogInformation("All messages sent");
});
app.MapGet("/Zone", async ([FromQuery] double latitude, [FromQuery] double longitude, [FromServices] ILogger<Configurator> logger, [FromServices] ZoneDeterminatorService zoneDeterminator) =>
{
logger.LogTrace("Getting zone for: {latitude}, {longitude}...", latitude, longitude);
Result<string> result = await zoneDeterminator.DetermineZoneCodeAsync(latitude, longitude);
if (result.IsSuccessful)
return Results.Ok(result.Value);
else
return Results.Ok(result.Exception);
});
//Map static assets //Map static assets
app.MapStaticAssets(); app.MapStaticAssets();

View File

@@ -12,7 +12,7 @@ public class MQTTClient : IHostedService
private readonly IMqttClient client; private readonly IMqttClient client;
public MQTTClient(ILogger<MQTTClient> logger, IOptions<MQTTClientConfiguration> options, IOptions<MQTTServerConfiguration> serverOptions, IMessageProcessor messageProcessor) public MQTTClient(ILogger<MQTTClient> logger, IOptions<MQTTClientConfiguration> options, IOptions<MQTTServerConfiguration> serverOptions, MessageProcessor messageProcessor)
{ {
this.logger = logger; this.logger = logger;
this.configuration = options.Value; this.configuration = options.Value;

View File

@@ -7,12 +7,7 @@ using SzakatsA.Result;
namespace ProofOfConcept.Services; namespace ProofOfConcept.Services;
public interface IMessageProcessor public class MessageProcessor
{
Task ProcessMessage(string vin, string field, string value);
}
public class MessageProcessor : IMessageProcessor
{ {
private readonly ILogger<MessageProcessor> logger; private readonly ILogger<MessageProcessor> logger;
private MessageProcessorConfiguration configuration; private MessageProcessorConfiguration configuration;
@@ -89,7 +84,7 @@ public class MessageProcessor : IMessageProcessor
await StopParkingAsync(vin); await StopParkingAsync(vin);
} }
private async Task StartParkingAsync(string vin) public async Task StartParkingAsync(string vin)
{ {
this.logger.LogTrace("Start parking for {vin}...", vin); this.logger.LogTrace("Start parking for {vin}...", vin);
@@ -130,7 +125,7 @@ public class MessageProcessor : IMessageProcessor
this.logger.LogError(zoneLookupResult.Exception, "Can't start parking: error while determining parking zone"); this.logger.LogError(zoneLookupResult.Exception, "Can't start parking: error while determining parking zone");
} }
private async Task StopParkingAsync(string vin) public async Task StopParkingAsync(string vin)
{ {
this.logger.LogTrace("Stopping parking for {vin}...", vin); this.logger.LogTrace("Stopping parking for {vin}...", vin);

View File

@@ -1,3 +1,4 @@
using System.Diagnostics;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using NetTopologySuite.Features; using NetTopologySuite.Features;
using NetTopologySuite.Geometries; using NetTopologySuite.Geometries;
@@ -45,14 +46,21 @@ public class ZoneDeterminatorService
return Result.Success(zone.Attributes["zoneid"].ToString()!); return Result.Success(zone.Attributes["zoneid"].ToString()!);
} }
private async Task InitializeAsync(CancellationToken cancellationToken = default(CancellationToken)) public async Task InitializeAsync(CancellationToken cancellationToken = default(CancellationToken))
{ {
this.logger.LogTrace("Initializing..."); this.logger.LogTrace("Initializing...");
Stopwatch sw = Stopwatch.StartNew();
this.logger.LogTrace("Reading file...");
string geojson = await File.ReadAllTextAsync(this.configuration.ZoneFilePath, cancellationToken); string geojson = await File.ReadAllTextAsync(this.configuration.ZoneFilePath, cancellationToken);
this.logger.LogTrace("File read in {Elapsed} ms", sw.ElapsedMilliseconds);
this.logger.LogTrace("Parsing geojson...");
GeoJsonReader reader = new GeoJsonReader(); GeoJsonReader reader = new GeoJsonReader();
this.parkingZones = reader.Read<FeatureCollection>(geojson); this.parkingZones = reader.Read<FeatureCollection>(geojson);
this.logger.LogTrace("Geojson parsed in {Elapsed} ms: {FeatureCount} features", sw.ElapsedMilliseconds, this.parkingZones.Count);
this.initialized = true;
this.logger.LogInformation("Initialized"); this.logger.LogInformation("Initialized");
} }
} }