-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathPostgreSQLTests.cs
More file actions
43 lines (37 loc) · 1.78 KB
/
PostgreSQLTests.cs
File metadata and controls
43 lines (37 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using EntityFramework.Exceptions.Common;
using EntityFramework.Exceptions.PostgreSQL;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
using Testcontainers.PostgreSql;
using Xunit;
namespace EntityFramework.Exceptions.Tests
{
public class PostgreSQLTests : DatabaseTests, IClassFixture<PostgreSQLDemoContextFixture>
{
public PostgreSQLTests(PostgreSQLDemoContextFixture fixture) : base(fixture.DemoContext, fixture.SameNameIndexesContext)
{
}
[Fact]
public async Task MaxLengthViolationThrowsMaxLengthExceededExceptionThroughRawSql()
{
var longName = new string('G', DemoContext.ProductNameMaxLength + 5);
Assert.Throws<MaxLengthExceededException>(() =>
DemoContext.Database.ExecuteSqlInterpolated(
$"INSERT INTO \"Products\" (\"Name\") VALUES ({longName})"));
await Assert.ThrowsAsync<MaxLengthExceededException>(() =>
DemoContext.Database.ExecuteSqlInterpolatedAsync(
$"INSERT INTO \"Products\" (\"Name\") VALUES ({longName})"));
}
}
public class PostgreSQLDemoContextFixture : DemoContextFixture<PostgreSqlContainer>
{
static PostgreSQLDemoContextFixture()
{
Container = new PostgreSqlBuilder().Build();
}
protected override DbContextOptionsBuilder<DemoContext> BuildDemoContextOptions(DbContextOptionsBuilder<DemoContext> builder, string connectionString)
=> builder.UseNpgsql(connectionString).UseExceptionProcessor();
protected override DbContextOptionsBuilder BuildSameNameIndexesContextOptions(DbContextOptionsBuilder builder, string connectionString)
=> builder.UseNpgsql(connectionString).UseExceptionProcessor();
}
}