-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQLite: Make SqliteDbContextOptionsBuilder.CommandTimeout() also set …
…SqliteConnection.DefaultTimeout Fixes #18607
- Loading branch information
Showing
2 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
test/EFCore.Sqlite.Tests/Storage/SqliteRelationalConnectionTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.Data.Sqlite; | ||
using Microsoft.EntityFrameworkCore.TestUtilities; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Storage | ||
{ | ||
public class SqliteRelationalConnectionTest | ||
{ | ||
[Fact] | ||
public void Sets_DefaultTimeout_when_connectionString() | ||
{ | ||
var services = SqliteTestHelpers.Instance.CreateContextServices( | ||
new DbContextOptionsBuilder() | ||
.UseSqlite("Data Source=:memory:", x => x.CommandTimeout(42)) | ||
.Options); | ||
|
||
var connection = (SqliteConnection)services.GetRequiredService<IRelationalConnection>().DbConnection; | ||
|
||
Assert.Equal(42, connection.DefaultTimeout); | ||
} | ||
|
||
[Fact] | ||
public void Sets_DefaultTimeout_when_connection() | ||
{ | ||
var originalConnection = new SqliteConnection("Data Source=:memory:") | ||
{ | ||
DefaultTimeout = 21 | ||
}; | ||
var services = SqliteTestHelpers.Instance.CreateContextServices( | ||
new DbContextOptionsBuilder() | ||
.UseSqlite(originalConnection, x => x.CommandTimeout(42)) | ||
.Options); | ||
|
||
var connection = (SqliteConnection)services.GetRequiredService<IRelationalConnection>().DbConnection; | ||
|
||
Assert.Same(originalConnection, connection); | ||
Assert.Equal(42, originalConnection.DefaultTimeout); | ||
} | ||
} | ||
} |