Add project files.
This commit is contained in:
+29
@@ -0,0 +1,29 @@
|
||||
using Elsa.Testing.Shared;
|
||||
using Elsa.Workflows.Activities;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Core;
|
||||
|
||||
public class ScheduleActivityExecutionContextTests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider = new TestApplicationBuilder(testOutputHelper).Build();
|
||||
|
||||
[Fact(DisplayName = "Scheduling an activity that is not part of the workflow should throw an exception")]
|
||||
public async Task ScheduleActivityAsync_WithActivityNotPartOfWorkflow_ShouldThrowException()
|
||||
{
|
||||
await _serviceProvider.PopulateRegistriesAsync();
|
||||
var writeLineA = new WriteLine("Test");
|
||||
var writeLineB = new WriteLine("Test");
|
||||
var workflow = new Workflow
|
||||
{
|
||||
Root = writeLineA
|
||||
};
|
||||
var workflowGraphBuilder = _serviceProvider.GetRequiredService<IWorkflowGraphBuilder>();
|
||||
var workflowGraph = await workflowGraphBuilder.BuildAsync(workflow);
|
||||
var workflowExecutionContext = await WorkflowExecutionContext.CreateAsync(_serviceProvider, workflowGraph, "test");
|
||||
var activityExecutionContext = await workflowExecutionContext.CreateActivityExecutionContextAsync(writeLineA);
|
||||
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => activityExecutionContext.ScheduleActivityAsync(writeLineB).AsTask());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System.Text.Json;
|
||||
using Elsa.Testing.Shared;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Elsa.Workflows.IntegrationTests.Core;
|
||||
|
||||
public class SerializerUnicodeEncodingTests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider = new TestApplicationBuilder(testOutputHelper).Build();
|
||||
|
||||
[Fact]
|
||||
public void TestPayloadSerializer()
|
||||
{
|
||||
var serializer = _serviceProvider.GetRequiredService<IPayloadSerializer>();
|
||||
TestSerializer(input => serializer.Serialize(input));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestApiSerializer()
|
||||
{
|
||||
var serializer = _serviceProvider.GetRequiredService<IApiSerializer>();
|
||||
TestSerializer(input => serializer.Serialize(input));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestBookmarkPayloadSerializer()
|
||||
{
|
||||
var serializer = _serviceProvider.GetRequiredService<IBookmarkPayloadSerializer>();
|
||||
TestSerializer(input => serializer.Serialize(input));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSafeSerializer()
|
||||
{
|
||||
var serializer = _serviceProvider.GetRequiredService<ISafeSerializer>();
|
||||
TestSerializer(input => serializer.Serialize(input));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWorkflowStateSerializer()
|
||||
{
|
||||
var serializer = _serviceProvider.GetRequiredService<IWorkflowStateSerializer>();
|
||||
TestSerializer(input => serializer.Serialize(input));
|
||||
}
|
||||
|
||||
private void TestSerializer(Func<object, string> serialize)
|
||||
{
|
||||
var unicodeString = UnicodeRangeGenerator.GenerateUnicodeString();
|
||||
var anonymousObject = new
|
||||
{
|
||||
Text = unicodeString
|
||||
};
|
||||
var serializedJson = serialize(anonymousObject);
|
||||
var serializedStringValue = GetSerializedTextValue(serializedJson);
|
||||
Assert.Equal(unicodeString, serializedStringValue);
|
||||
}
|
||||
|
||||
private string GetSerializedTextValue(string serializedJson)
|
||||
{
|
||||
var rootElement = JsonDocument.Parse(serializedJson).RootElement;
|
||||
return GetCaseInsensitiveSerializedTextValue(rootElement, "text", "Text");
|
||||
}
|
||||
|
||||
private string GetCaseInsensitiveSerializedTextValue(JsonElement jsonElement, params string[] propertyNames)
|
||||
{
|
||||
foreach (string propertyName in propertyNames)
|
||||
if (jsonElement.TryGetProperty(propertyName, out var property))
|
||||
return property.GetString()!;
|
||||
throw new KeyNotFoundException($"None of the following properties were found: {string.Join(", ", propertyNames)}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user