-
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathSqlServerTests.cs
48 lines (37 loc) · 1.76 KB
/
SqlServerTests.cs
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
44
45
46
47
48
using EntityFramework.Exceptions.SqlServer;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
using Testcontainers.MsSql;
using Xunit;
namespace EntityFramework.Exceptions.Tests;
public class SqlServerTests : DatabaseTests, IClassFixture<SqlServerDemoContextFixture>
{
public SqlServerTests(SqlServerDemoContextFixture fixture) : base(fixture.DemoContext, fixture.SameNameIndexesContext)
{
}
[Fact]
public override async Task PrimaryKeyViolationThrowsUniqueConstraintException()
{
DemoContext.Database.OpenConnection();
DemoContext.Database.ExecuteSqlRaw("SET IDENTITY_INSERT Products ON");
await base.PrimaryKeyViolationThrowsUniqueConstraintException();
DemoContext.Database.ExecuteSqlRaw("SET IDENTITY_INSERT Products OFF");
DemoContext.Database.CloseConnection();
}
[Fact(Skip = "Skipping as Microsoft.Data.SqlClient throws ArgumentException when numeric value is not in range.")]
public override Task NumericOverflowViolationThrowsNumericOverflowException()
{
return Task.CompletedTask;
}
}
public class SqlServerDemoContextFixture : DemoContextFixture<MsSqlContainer>
{
static SqlServerDemoContextFixture()
{
Container = new MsSqlBuilder().WithImage("mcr.microsoft.com/mssql/server:2022-latest").Build();
}
protected override DbContextOptionsBuilder<DemoContext> BuildDemoContextOptions(DbContextOptionsBuilder<DemoContext> builder, string connectionString)
=> builder.UseSqlServer(connectionString).UseExceptionProcessor();
protected override DbContextOptionsBuilder BuildSameNameIndexesContextOptions(DbContextOptionsBuilder builder, string connectionString) =>
builder.UseSqlServer(connectionString).UseExceptionProcessor();
}