elsa-core/test/unit/Elsa.Common.UnitTests/Codecs/ZstdTests.cs
Sipke Schoorstra ca88051573
Improves workflow materializer handling (#7195)
* Add tenant headers support to BackgroundWorkflowCancellationDispatcher (#7040)

* Add tenant headers support to BackgroundWorkflowCancellationDispatcher

* Fix 'CreateHeaders' call

* Fix memory leak: Dispose IronCompressResult in Zstd codec (#7193)

* Initial plan

* Fix memory leak: Dispose IronCompressResult in Zstd codec and add tests

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Refactor tests to be more DRY using Theory and InlineData

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Introduce `IMaterializerRegistry` to manage workflow materializers and ensure availability checks.

* Extend `IWorkflowDefinitionService` and `CachingWorkflowDefinitionService` with workflow graph lookup methods (`TryFindWorkflowGraphAsync`). Refactor caching and materialization logic for consistency.

* Refactor caching interface and implementation: add `FindOrCreateAsync`, update `GetOrCreateAsync` to ensure non-null results, and improve exception handling.

* Refactor `GetWorkflowGraphAsync` to use `TryFindWorkflowGraphAsync` and improve exception handling for missing workflow definitions and materializers.

* Refactor caching logic to replace `GetOrCreateAsync` with `FindOrCreateAsync` for improved clarity and consistency.

* Update workflow model, add event, and mark exception obsolete

Updated `TimestampFilter.Column` to use a `null!` default value for clarity. Added `Event1` in the `hello-world.elsa` workflow and removed an unused folder entry from the project. Marked `WorkflowGraphNotFoundException` as obsolete with guidance to use `WorkflowDefinitionNotFoundException` instead.

* Add new workflow files and exception classes for Elsa

Introduced a workflow definition file "eventing.json" and new exception classes (`WorkflowDefinitionNotFoundException` and `WorkflowMaterializerNotFoundException`) to enhance handling of workflow-related errors. Also added a `WorkflowGraphFindResult` model for better workflow graph management. These changes improve the structure and functionality of the workflow system.

* Add unit tests for `CachingWorkflowDefinitionService` and related helpers

Introduce comprehensive unit tests to validate caching logic, workflow graph/materialization behavior, and cache key generation in `CachingWorkflowDefinitionService`. Add `WorkflowDefinitionServiceTests` and helper methods for streamlined test setup.

* Enable `UseElsaScriptBlobStorage` in workflow server configuration

* Refactor `BackgroundWorkflowCancellationDispatcher` to simplify object initialization and clean up XML documentation comments

* Address PR #7195 review feedback: optimize caching, improve exceptions, add test coverage (#7196)

* Initial plan

* Apply PR review feedback: Fix exceptions, optimize caching, improve error handling

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Add unit tests for MaterializerRegistry and LocalWorkflowClient exception handling

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Add unit tests for BackgroundWorkflowCancellationDispatcher tenant headers

Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>

* Refactor `WorkflowMaterializerNotFoundException` to improve structure and usability, update related references, and simplify object initialization in test cases.

* Update `WorkflowDefinitionServiceTests` to use `WorkflowMaterializerNotFoundException` in place of `InvalidOperationException` for materializer not found scenario

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>

* Potential fix for pull request finding 'Inefficient use of ContainsKey'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>

* Refactor tests and services: simplify object initialization, use target-typed `new()` syntax, and replace `CancellationToken` with `CancellationToken.None` where applicable.

* Refactor tests in `BackgroundWorkflowCancellationDispatcherTests`: improve tenant initialization and optimize header checks by replacing `TryGetValue` with `ContainsKey`.

---------

Co-authored-by: Sverre Winkelmans <69142682+Sverre-W@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
2026-01-19 08:59:12 +01:00

68 lines
1.9 KiB
C#

using Elsa.Common.Codecs;
namespace Elsa.Common.UnitTests.Codecs;
public class ZstdTests
{
private readonly Zstd _codec = new();
[Fact]
public async Task CompressAsync_WithSimpleString_ReturnsCompressedString()
{
// Arrange
var input = "Hello, World!";
// Act
var result = await _codec.CompressAsync(input);
// Assert
Assert.NotNull(result);
Assert.NotEmpty(result);
Assert.NotEqual(input, result);
}
[Theory]
[InlineData("Hello, World!")]
[InlineData("")]
[InlineData("Hello! 你好! مرحبا! Здравствуйте! 🎉🎊")]
[InlineData("{\"name\":\"John Doe\",\"age\":30,\"city\":\"New York\",\"items\":[1,2,3,4,5]}")]
public async Task CompressDecompress_RoundTrip_PreservesOriginalData(string original)
{
// Act
var compressed = await _codec.CompressAsync(original);
var decompressed = await _codec.DecompressAsync(compressed);
// Assert
Assert.Equal(original, decompressed);
}
[Fact]
public async Task CompressDecompress_WithLargeString_WorksCorrectly()
{
// Arrange
var original = string.Join("", Enumerable.Repeat("This is a test string that will be compressed. ", 1000));
// Act
var compressed = await _codec.CompressAsync(original);
var decompressed = await _codec.DecompressAsync(compressed);
// Assert
Assert.Equal(original, decompressed);
Assert.True(compressed.Length < original.Length, "Compressed string should be smaller than original");
}
[Fact]
public async Task CompressAsync_MultipleCallsWithSameInput_ProducesConsistentResults()
{
// Arrange
var input = "Test string for consistency";
// Act
var result1 = await _codec.CompressAsync(input);
var result2 = await _codec.CompressAsync(input);
// Assert
Assert.Equal(result1, result2);
}
}