Skip to content

Commit 7f8d97d

Browse files
committed
Add test for PostgreSQL SqlState 22001 max length violation (fixes #92)
Add a PostgreSQL-specific test that verifies MaxLengthExceededException is thrown when executing raw SQL that inserts a value exceeding the character varying column limit. This exercises the IDbCommandInterceptor CommandFailed path for PostgreSQL error 22001 (StringDataRightTruncation). The PostgreSQL classifier already handles SqlState 22001 via PostgresErrorCodes.StringDataRightTruncation. This test ensures the full interceptor pipeline works for raw SQL operations in addition to the existing SaveChanges and ExecuteUpdate test coverage. https://claude.ai/code/session_0147Z5VzzZpX1pUfaAapNZie
1 parent 8a0db27 commit 7f8d97d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

EntityFramework.Exceptions/Tests/PostgreSQLTests.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using EntityFramework.Exceptions.PostgreSQL;
1+
using EntityFramework.Exceptions.Common;
2+
using EntityFramework.Exceptions.PostgreSQL;
23
using Microsoft.EntityFrameworkCore;
4+
using System.Threading.Tasks;
35
using Testcontainers.PostgreSql;
46
using Xunit;
57

@@ -10,6 +12,19 @@ public class PostgreSQLTests : DatabaseTests, IClassFixture<PostgreSQLDemoContex
1012
public PostgreSQLTests(PostgreSQLDemoContextFixture fixture) : base(fixture.DemoContext, fixture.SameNameIndexesContext)
1113
{
1214
}
15+
16+
[Fact]
17+
public async Task MaxLengthViolationThrowsMaxLengthExceededExceptionThroughRawSql()
18+
{
19+
var longName = new string('G', DemoContext.ProductNameMaxLength + 5);
20+
21+
Assert.Throws<MaxLengthExceededException>(() =>
22+
DemoContext.Database.ExecuteSqlInterpolated(
23+
$"INSERT INTO \"Products\" (\"Name\") VALUES ({longName})"));
24+
await Assert.ThrowsAsync<MaxLengthExceededException>(() =>
25+
DemoContext.Database.ExecuteSqlInterpolatedAsync(
26+
$"INSERT INTO \"Products\" (\"Name\") VALUES ({longName})"));
27+
}
1328
}
1429

1530
public class PostgreSQLDemoContextFixture : DemoContextFixture<PostgreSqlContainer>

0 commit comments

Comments
 (0)