Add test cases
All checks were successful
Build, Push and Run Container / build (push) Successful in 27s
All checks were successful
Build, Push and Run Container / build (push) Successful in 27s
This commit is contained in:
@@ -12,6 +12,7 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||
using ProofOfConcept.Models;
|
||||
using ProofOfConcept.Services;
|
||||
using ProofOfConcept.Utilities;
|
||||
using SzakatsA.Result;
|
||||
|
||||
Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true;
|
||||
|
||||
@@ -137,7 +138,7 @@ builder.Services
|
||||
});
|
||||
|
||||
// Add own services
|
||||
builder.Services.AddSingleton<IMessageProcessor, MessageProcessor>();
|
||||
builder.Services.AddSingleton<MessageProcessor>();
|
||||
builder.Services.AddTransient<ITeslaAuthenticatorService, TeslaAuthenticatorService>();
|
||||
builder.Services.AddTransient<ZoneDeterminatorService>();
|
||||
|
||||
@@ -418,6 +419,40 @@ app.MapGet("/Status", async ([FromServices] ILogger<Configurator> logger, [FromS
|
||||
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
|
||||
app.MapStaticAssets();
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ public class MQTTClient : IHostedService
|
||||
|
||||
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.configuration = options.Value;
|
||||
|
||||
@@ -7,12 +7,7 @@ using SzakatsA.Result;
|
||||
|
||||
namespace ProofOfConcept.Services;
|
||||
|
||||
public interface IMessageProcessor
|
||||
{
|
||||
Task ProcessMessage(string vin, string field, string value);
|
||||
}
|
||||
|
||||
public class MessageProcessor : IMessageProcessor
|
||||
public class MessageProcessor
|
||||
{
|
||||
private readonly ILogger<MessageProcessor> logger;
|
||||
private MessageProcessorConfiguration configuration;
|
||||
@@ -89,7 +84,7 @@ public class MessageProcessor : IMessageProcessor
|
||||
await StopParkingAsync(vin);
|
||||
}
|
||||
|
||||
private async Task StartParkingAsync(string vin)
|
||||
public async Task StartParkingAsync(string 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");
|
||||
}
|
||||
|
||||
private async Task StopParkingAsync(string vin)
|
||||
public async Task StopParkingAsync(string vin)
|
||||
{
|
||||
this.logger.LogTrace("Stopping parking for {vin}...", vin);
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NetTopologySuite.Features;
|
||||
using NetTopologySuite.Geometries;
|
||||
@@ -45,14 +46,21 @@ public class ZoneDeterminatorService
|
||||
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...");
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
|
||||
this.logger.LogTrace("Reading file...");
|
||||
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();
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user