|
|
@@ -1,11 +1,58 @@
|
|
|
+using System.Text.Json;
|
|
|
using Admin.NET.Plugin.AiDOP.DataPlatform.Core.Edge;
|
|
|
using Admin.NET.Plugin.AiDOP.DataPlatform.Core.Connectors;
|
|
|
+using Admin.NET.Plugin.AiDOP.DataPlatform.UnifiedIngress;
|
|
|
+using Microsoft.AspNetCore.Builder;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.AspNetCore.Mvc.Abstractions;
|
|
|
+using Microsoft.AspNetCore.Routing;
|
|
|
+using Microsoft.Extensions.DependencyInjection;
|
|
|
using Xunit;
|
|
|
|
|
|
namespace Admin.NET.Plugin.AiDOP.Tests.DataPlatform;
|
|
|
|
|
|
public sealed class MdpEdgeReceiptTests
|
|
|
{
|
|
|
+ [Fact]
|
|
|
+ public async Task HeartbeatTaskCanBeDeserializedByTheEdgeClient()
|
|
|
+ {
|
|
|
+ var lease = new DateTimeOffset(2026, 12, 2, 7, 25, 54, TimeSpan.Zero);
|
|
|
+ var task = new EdgeTask("run-A", EdgeProtocol.ApiPull, 123456789012345678L, 2, 3, 4,
|
|
|
+ "S", "test", "schema", "config", "page-2", "READY", LeaseUntil: lease);
|
|
|
+
|
|
|
+ var result = await RenderHeartbeatAsync(task);
|
|
|
+
|
|
|
+ Assert.Equal(StatusCodes.Status200OK, result.StatusCode);
|
|
|
+ Assert.StartsWith("application/json", result.ContentType);
|
|
|
+ var received = JsonSerializer.Deserialize<EdgeTask>(result.Body, EdgeProtocol.Json);
|
|
|
+ Assert.Equal(task, received);
|
|
|
+ Assert.Equal(lease.Offset, received.LeaseUntil.Value.Offset);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public async Task HeartbeatWithoutATaskRemainsNoContent()
|
|
|
+ {
|
|
|
+ var result = await RenderHeartbeatAsync(null);
|
|
|
+
|
|
|
+ Assert.Equal(StatusCodes.Status204NoContent, result.StatusCode);
|
|
|
+ Assert.Empty(result.Body);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static async Task<(int StatusCode, string ContentType, byte[] Body)> RenderHeartbeatAsync(EdgeTask task)
|
|
|
+ {
|
|
|
+ var builder = WebApplication.CreateBuilder();
|
|
|
+ builder.Services.AddControllers().AddNewtonsoftJson(options =>
|
|
|
+ options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss");
|
|
|
+ await using var app = builder.Build();
|
|
|
+ await using var body = new MemoryStream();
|
|
|
+ var http = new DefaultHttpContext { RequestServices = app.Services };
|
|
|
+ http.Response.Body = body;
|
|
|
+ var action = new ActionContext(http, new RouteData(), new ActionDescriptor());
|
|
|
+ await MdpEdgeDeviceController.HeartbeatResult(task).ExecuteResultAsync(action);
|
|
|
+ return (http.Response.StatusCode, http.Response.ContentType, body.ToArray());
|
|
|
+ }
|
|
|
+
|
|
|
[Fact]
|
|
|
public void OnlyMatchingCloudReceiptCanCommitPosition()
|
|
|
{
|