Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a656d0c

Browse filesBrowse files
committed
Add ParameterStatus tests
1 parent fde680b commit a656d0c
Copy full SHA for a656d0c

1 file changed

+88Lines changed: 88 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/Npgsql.Tests/ConnectionTests.cs‎

Copy file name to clipboardExpand all lines: test/Npgsql.Tests/ConnectionTests.cs
+88Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,94 @@ await adminConn.ExecuteNonQueryAsync(
13711371
}
13721372
}
13731373

1374+
[Test]
1375+
public async Task Mid_session_SET_TIME_ZONE_updates_connector_timezone()
1376+
{
1377+
await using var dataSource = CreateDataSource();
1378+
await using var conn = await dataSource.OpenConnectionAsync();
1379+
1380+
var original = conn.Connector!.Timezone;
1381+
// Pick a different zone than whatever we started with so the SET produces a real change.
1382+
var target = string.Equals(original, "UTC", StringComparison.OrdinalIgnoreCase) ? "Europe/Amsterdam" : "UTC";
1383+
1384+
await conn.ExecuteNonQueryAsync($"SET TIME ZONE '{target}'");
1385+
1386+
Assert.That(conn.Connector.Timezone, Is.EqualTo(target));
1387+
}
1388+
1389+
[Test]
1390+
public async Task Mid_session_SET_client_encoding_updates_connector_text_encoding()
1391+
{
1392+
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
1393+
1394+
await using var dataSource = CreateDataSource();
1395+
await using var conn = await dataSource.OpenConnectionAsync();
1396+
1397+
Assert.That(conn.Connector!.TextEncoding.WebName, Is.EqualTo("utf-8"));
1398+
1399+
await conn.ExecuteNonQueryAsync("SET CLIENT_ENCODING TO 'WIN1252'");
1400+
Assert.That(conn.Connector.TextEncoding.WebName, Is.EqualTo("windows-1252"));
1401+
1402+
// Roundtrip non-ascii text through the rotated encoding to confirm the new encoding is wired
1403+
// end-to-end (not just the connector property).
1404+
const string text = "éàç";
1405+
var result = await conn.ExecuteScalarAsync($"SELECT '{text}'");
1406+
Assert.That(result, Is.EqualTo(text));
1407+
}
1408+
1409+
[Test]
1410+
public async Task SET_client_encoding_to_SQL_ASCII_rotates_back_to_settings_encoding()
1411+
{
1412+
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
1413+
1414+
await using var dataSource = CreateDataSource();
1415+
await using var conn = await dataSource.OpenConnectionAsync();
1416+
1417+
var settingsEncoding = conn.Connector!.TextEncoding;
1418+
Assert.That(settingsEncoding.WebName, Is.EqualTo("utf-8"));
1419+
1420+
// Move TextEncoding to something other than Settings.Encoding via a normal SET.
1421+
await conn.ExecuteNonQueryAsync("SET CLIENT_ENCODING TO 'WIN1252'");
1422+
Assert.That(conn.Connector.TextEncoding.WebName, Is.EqualTo("windows-1252"));
1423+
1424+
// SQL_ASCII semantically means "no PG-side encoding"; the .NET side rotates back to
1425+
// Settings.Encoding so the caller's interpretation choice resumes.
1426+
await conn.ExecuteNonQueryAsync("SET CLIENT_ENCODING TO 'SQL_ASCII'");
1427+
Assert.That(conn.Connector.TextEncoding.WebName, Is.EqualTo(settingsEncoding.WebName));
1428+
}
1429+
1430+
[Test]
1431+
public async Task Mid_session_client_encoding_change_invalidates_cached_bindings()
1432+
{
1433+
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
1434+
1435+
await using var dataSource = CreateDataSource();
1436+
await using var conn = await dataSource.OpenConnectionAsync();
1437+
1438+
// Prime the per-reader ConversionContextCache with a typed read so the cache has entries
1439+
// resolved against the original (UTF-8) ConversionContext.
1440+
await using (var cmd = new NpgsqlCommand("SELECT 'hello'::text", conn))
1441+
await using (var reader = await cmd.ExecuteReaderAsync())
1442+
{
1443+
Assert.That(await reader.ReadAsync());
1444+
Assert.That(reader.GetString(0), Is.EqualTo("hello"));
1445+
}
1446+
1447+
// Rotate the connector context.
1448+
await conn.ExecuteNonQueryAsync("SET CLIENT_ENCODING TO 'WIN1252'");
1449+
1450+
// After rotation, a subsequent read with non-ascii data should still produce correct values —
1451+
// the cached bindings in any reused RowDescription / ConversionContextCache must invalidate so
1452+
// the new context flows into the next read's binding.
1453+
const string nonAscii = "éàç";
1454+
await using (var cmd = new NpgsqlCommand($"SELECT '{nonAscii}'::text", conn))
1455+
await using (var reader = await cmd.ExecuteReaderAsync())
1456+
{
1457+
Assert.That(await reader.ReadAsync());
1458+
Assert.That(reader.GetString(0), Is.EqualTo(nonAscii));
1459+
}
1460+
}
1461+
13741462
[Test]
13751463
public async Task Oversize_buffer()
13761464
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.