elsa-core/test/unit/Elsa.Persistence.EFCore.UnitTests/DbExceptionClassifierTests.cs
Sipke Schoorstra 54209e24c2
fix(alterations): atomic EF tenant ownership on Save/SaveMany (#8128)
Closes #8125.

Alterations-local CAS via ExecuteUpdate+INSERT with ambient ownership gate,
same-tenant race retry, multi-TFM setters, persistence compatibility ctors.
2026-09-13 23:38:40 +00:00

38 lines
1.3 KiB
C#

namespace Elsa.Persistence.EFCore.UnitTests;
public sealed class DbExceptionClassifierTests
{
[Theory]
[InlineData(19, 1555, true)]
[InlineData(19, 2067, true)]
[InlineData(19, 19, false)]
[InlineData(19, 0, false)]
public void IsDuplicateKey_WhenSqliteExtendedCodeExists_UsesOnlyExtendedDuplicateCodes(int baseCode, int extendedCode, bool expected)
{
var exception = new SqliteExceptionWithExtendedCode(baseCode, extendedCode);
Assert.Equal(expected, DbExceptionClassifier.IsDuplicateKey(exception));
}
[Theory]
[InlineData(19, true)]
[InlineData(1, false)]
public void IsDuplicateKey_WhenSqliteExtendedCodeIsUnavailable_FallsBackToBaseCode(int baseCode, bool expected)
{
var exception = new SqliteExceptionWithoutExtendedCode(baseCode);
Assert.Equal(expected, DbExceptionClassifier.IsDuplicateKey(exception));
}
private sealed class SqliteExceptionWithExtendedCode(int sqliteErrorCode, int sqliteExtendedErrorCode) : Exception
{
public int SqliteErrorCode { get; } = sqliteErrorCode;
public int SqliteExtendedErrorCode { get; } = sqliteExtendedErrorCode;
}
private sealed class SqliteExceptionWithoutExtendedCode(int sqliteErrorCode) : Exception
{
public int SqliteErrorCode { get; } = sqliteErrorCode;
}
}