Merge pull request #7752 from elsa-workflows/sfmskywalker-fix-flaky-payload-test
Fix flaky PublishEvent payload assertion
This commit is contained in:
commit
883a184c2e
|
|
@ -11,8 +11,6 @@
|
|||
<packageSourceMapping>
|
||||
<packageSource key="NuGet official package source">
|
||||
<package pattern="*" />
|
||||
</packageSource>
|
||||
<packageSource key="cshells-feedz">
|
||||
<package pattern="CShells" />
|
||||
<package pattern="CShells.*" />
|
||||
</packageSource>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using Elsa.Common.Models;
|
||||
using Elsa.Testing.Shared;
|
||||
|
|
@ -74,10 +75,25 @@ public class PublishEventTests : AppComponentTest
|
|||
|
||||
// Verify the payload structure and content
|
||||
using var payloadDocument = JsonDocument.Parse(JsonSerializer.Serialize(receivedPayload));
|
||||
Assert.True(payloadDocument.RootElement.TryGetProperty("Status", out var status), "Received payload should contain a Status property");
|
||||
Assert.True(TryGetProperty(payloadDocument.RootElement, "Status", out var status), "Received payload should contain a Status property");
|
||||
Assert.Equal("Shipped", status.GetString());
|
||||
}
|
||||
|
||||
private static bool TryGetProperty(JsonElement element, string propertyName, out JsonElement property)
|
||||
{
|
||||
var candidate = element.EnumerateObject()
|
||||
.Where(candidate => candidate.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase))
|
||||
.FirstOrDefault();
|
||||
if (candidate.Value.ValueKind == JsonValueKind.Undefined)
|
||||
{
|
||||
property = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
property = candidate.Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<WorkflowInstance> GetSingleWorkflowInstanceAsync(string definitionId, string correlationId, int timeoutMs = 5000)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<WorkflowInstance>();
|
||||
|
|
|
|||
Loading…
Reference in a new issue