/
dev-npgsql
/
npgsql
Обзор
Документация
Войти
/
dev-npgsql
/
npgsql
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
test-logs
test/Npgsql.Tests/Types/FullTextSearchTests.cs
95 строк
4 KB
Nino Floris
Remove obsolete UTF-8 BOMs (#6542)
13 апр 2026, 17:13
Не верифицирован
13 апр 2026, 17:13
5225216
Код
Авторство
О чём код?
using System; using System.Collections; using System.Threading.Tasks; using Npgsql.Properties; using NpgsqlTypes; using NUnit.Framework; #pragma warning disable CS0618 // NpgsqlTsVector.Parse is obsolete namespace Npgsql.Tests.Types; public class FullTextSearchTests : TestBase { [Test] public Task TsVector() => AssertType( NpgsqlTsVector.Parse("'1' '2' 'a':24,25A,26B,27,28,12345C 'b' 'c' 'd'"), "'1' '2' 'a':24,25A,26B,27,28,12345C 'b' 'c' 'd'", "tsvector"); public static IEnumerable TsQueryTestCases() => new[] { [ "'a'", new NpgsqlTsQueryLexeme("a") ], [ "!'a'", new NpgsqlTsQueryNot( new NpgsqlTsQueryLexeme("a")) ], [ "'a' | 'b'", new NpgsqlTsQueryOr( new NpgsqlTsQueryLexeme("a"), new NpgsqlTsQueryLexeme("b")) ], [ "'a' & 'b'", new NpgsqlTsQueryAnd( new NpgsqlTsQueryLexeme("a"), new NpgsqlTsQueryLexeme("b")) ], new object[] { "'a' <-> 'b'", new NpgsqlTsQueryFollowedBy( new NpgsqlTsQueryLexeme("a"), 1, new NpgsqlTsQueryLexeme("b")) } }; [Test] [TestCaseSource(nameof(TsQueryTestCases))] public Task TsQuery(string sqlLiteral, NpgsqlTsQuery query) => AssertType(query, sqlLiteral, "tsquery"); [Test] public async Task Full_text_search_not_supported_by_default_on_NpgsqlSlimSourceBuilder() { var errorMessage = string.Format( NpgsqlStrings.FullTextSearchNotEnabled, nameof(NpgsqlSlimDataSourceBuilder.EnableFullTextSearch), nameof(NpgsqlSlimDataSourceBuilder)); var dataSourceBuilder = new NpgsqlSlimDataSourceBuilder(ConnectionString); await using var dataSource = dataSourceBuilder.Build(); var exception = await AssertTypeUnsupportedRead<NpgsqlTsQuery, InvalidCastException>("a", "tsquery", dataSource); Assert.That(exception.InnerException, Is.InstanceOf<NotSupportedException>()); Assert.That(exception.InnerException!.Message, Is.EqualTo(errorMessage)); exception = await AssertTypeUnsupportedWrite<NpgsqlTsQuery, InvalidCastException>(new NpgsqlTsQueryLexeme("a"), dataTypeName: null, dataSource); Assert.That(exception.InnerException, Is.InstanceOf<NotSupportedException>()); Assert.That(exception.InnerException!.Message, Is.EqualTo(errorMessage)); exception = await AssertTypeUnsupportedRead<NpgsqlTsVector, InvalidCastException>("1", "tsvector", dataSource); Assert.That(exception.InnerException, Is.InstanceOf<NotSupportedException>()); Assert.That(exception.InnerException!.Message, Is.EqualTo(errorMessage)); exception = await AssertTypeUnsupportedWrite<NpgsqlTsVector, InvalidCastException>(NpgsqlTsVector.Parse("'1'"), dataTypeName: null, dataSource); Assert.That(exception.InnerException, Is.InstanceOf<NotSupportedException>()); Assert.That(exception.InnerException!.Message, Is.EqualTo(errorMessage)); } [Test] public async Task NpgsqlSlimSourceBuilder_EnableFullTextSearch() { var dataSourceBuilder = new NpgsqlSlimDataSourceBuilder(ConnectionString); dataSourceBuilder.EnableFullTextSearch(); await using var dataSource = dataSourceBuilder.Build(); await AssertType<NpgsqlTsQuery>(new NpgsqlTsQueryLexeme("a"), "'a'", "tsquery"); await AssertType(NpgsqlTsVector.Parse("'1'"), "'1'", "tsvector"); } }