elsa-core/test/unit/Elsa.Workflows.Management.UnitTests/Services/DefaultFileNameSanitizerTests.cs
Sipke Schoorstra a0f0a3c2f5
Add workflow export functionality and update changelog (#7357)
* Add `IWorkflowDefinitionExporter` for workflow export functionality

Introduced `IWorkflowDefinitionExporter` interface and its implementation to export workflow definitions as JSON or ZIP archives. Simplified `Export` endpoint logic by utilizing the new exporter service. Updated package version to 3.6.1.

* Remove duplicate `ExportAsync` method from `IWorkflowDefinitionExporter` and its implementation in `WorkflowDefinitionExporter`.

* Remove deprecated test from `WorkflowDefinitionExporterTests`, regression tests are covered in `WorkflowReferenceGraphBuilderTests`.

* Update GitHub Actions workflow to support version 3.6.1 deployment

* Update src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionExporter.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Move `WorkflowDefinitionExporterRegressionTests` to separate test file for clarity

* Add `DefaultFileNameSanitizer` for sanitizing file names and update `WorkflowDefinitionExporter` to use it. Implement unit tests for the sanitizer.

* Update test assertion for exported workflow file name in `WorkflowDefinitionExporterRegressionTests`.

* Simplify file naming in `WorkflowDefinitionExporter` by removing duplicate ID from JSON file names.

* Update test/unit/Elsa.Workflows.Management.UnitTests/Services/DefaultFileNameSanitizerTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-03-11 17:20:07 +01:00

36 lines
1.1 KiB
C#

using Elsa.Workflows.Management.Services;
namespace Elsa.Workflows.Management.UnitTests.Services;
public class DefaultFileNameSanitizerTests
{
private readonly DefaultFileNameSanitizer _sut = new();
[Theory]
[InlineData("folder/child", "folder-child")]
[InlineData("folder\\child", "folder-child")]
[InlineData("already-safe", "already-safe")]
public void Sanitize_Replaces_Path_Separators_And_Preserves_Safe_Names(string input, string expected)
{
var result = _sut.Sanitize(input);
Assert.Equal(expected, result);
}
[Fact]
public void Sanitize_Replaces_Runtime_Invalid_File_Name_Characters()
{
var invalidChars = Path.GetInvalidFileNameChars();
var hasNonSeparatorInvalidChar = invalidChars.Any(c => c is not '/' and not '\\');
if (!hasNonSeparatorInvalidChar)
return;
var invalidCharacter = invalidChars.First(c => c is not '/' and not '\\');
var result = _sut.Sanitize($"before{invalidCharacter}after");
Assert.Equal("before-after", result);
}
}