修复Mysql
This commit is contained in:
@@ -14,6 +14,31 @@ namespace Jiaowu.Api.Tests;
|
||||
|
||||
public sealed class AuthControllerTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task RetriableTransaction_WorksWithRetryingExecutionStrategy()
|
||||
{
|
||||
await using var connection = new SqliteConnection("Data Source=:memory:");
|
||||
await connection.OpenAsync();
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseSqlite(connection)
|
||||
.ReplaceService<IExecutionStrategyFactory, RetryingExecutionStrategyFactory>()
|
||||
.Options;
|
||||
await using var db = new AppDbContext(options);
|
||||
await db.Database.EnsureCreatedAsync();
|
||||
|
||||
Assert.True(db.Database.CreateExecutionStrategy().RetriesOnFailure);
|
||||
await db.ExecuteInRetriableTransactionAsync(
|
||||
async transaction =>
|
||||
{
|
||||
db.Colleges.Add(new College { Code = "TX", Name = "事务测试学院" });
|
||||
await db.SaveChangesAsync();
|
||||
await transaction.CommitAsync();
|
||||
},
|
||||
CancellationToken.None);
|
||||
|
||||
Assert.Equal(1, await db.Colleges.CountAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ActivateStudent_WorksWithRetryingExecutionStrategy()
|
||||
{
|
||||
|
||||
@@ -52,6 +52,25 @@ public sealed class MySqlMigrationTests
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MySql_guid_collections_use_provider_safe_predicates()
|
||||
{
|
||||
using var db = new AppDbContext(CreateMySqlOptions());
|
||||
var ids = new[]
|
||||
{
|
||||
Guid.Parse("11111111-1111-1111-1111-111111111111"),
|
||||
Guid.Parse("22222222-2222-2222-2222-222222222222")
|
||||
};
|
||||
|
||||
var sql = db.Colleges
|
||||
.WhereIn(ids, x => x.Id)
|
||||
.ToQueryString();
|
||||
|
||||
Assert.Contains(" IN (", sql, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains(ids[0].ToString(), sql, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains(ids[1].ToString(), sql, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static DbContextOptions<AppDbContext> CreateMySqlOptions() =>
|
||||
new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseMySQL(
|
||||
|
||||
@@ -74,8 +74,9 @@ public sealed class PersonnelControllerTests
|
||||
Assert.Equal(teacher.Name, user.DisplayName);
|
||||
Assert.Equal(teacher.CollegeId, user.CollegeId);
|
||||
Assert.True(await userManager.IsInRoleAsync(user, SystemRoles.Teacher));
|
||||
await db.Entry(teacher).ReloadAsync();
|
||||
Assert.Equal(user.Id, teacher.UserId);
|
||||
db.ChangeTracker.Clear();
|
||||
var linkedTeacher = await db.Teachers.SingleAsync(x => x.Id == teacher.Id);
|
||||
Assert.Equal(user.Id, linkedTeacher.UserId);
|
||||
}
|
||||
|
||||
private sealed class TestDataScope(Guid collegeId) : ICurrentUserDataScope
|
||||
|
||||
Reference in New Issue
Block a user