diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..08522dc4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +root = true + +[*.cs] + +csharp_style_expression_bodied_methods = true:suggestion \ No newline at end of file diff --git a/examples/src/BasicExample/Program.cs b/examples/src/BasicExample/Program.cs index b0c08eb8..2c5895a1 100644 --- a/examples/src/BasicExample/Program.cs +++ b/examples/src/BasicExample/Program.cs @@ -22,12 +22,9 @@ internal class CmdOptions internal static class Program { - private static ServiceProvider GetServiceProvider() - { - return new ServiceCollection() - .AddLogging(configure => configure.AddConsole().SetMinimumLevel(LogLevel.Information)) - .BuildServiceProvider(); - } + private static ServiceProvider GetServiceProvider() => new ServiceCollection() + .AddLogging(configure => configure.AddConsole().SetMinimumLevel(LogLevel.Information)) + .BuildServiceProvider(); private static async Task Run(CmdOptions cmdOptions) { diff --git a/examples/src/Common/AuthUtils.cs b/examples/src/Common/AuthUtils.cs index 5a9824d5..4c549870 100644 --- a/examples/src/Common/AuthUtils.cs +++ b/examples/src/Common/AuthUtils.cs @@ -52,16 +52,10 @@ public static async Task MakeCredentialsFromEnv( throw new InvalidOperationException("Failed to parse credentials from environmet, no valid options found."); } - public static X509Certificate GetCustomServerCertificate() - { - return YcCerts.GetDefaultServerCertificate(); - } + public static X509Certificate GetCustomServerCertificate() => YcCerts.GetDefaultServerCertificate(); - private static bool IsTrueValue(string value) - { - return - value == "1" || - value.ToLower() == "yes" || - value.ToLower() == "true"; - } + private static bool IsTrueValue(string value) => + value == "1" || + value.ToLower() == "yes" || + value.ToLower() == "true"; } \ No newline at end of file diff --git a/examples/src/Common/DataUtils.cs b/examples/src/Common/DataUtils.cs index fbe048ce..6cf9b191 100644 --- a/examples/src/Common/DataUtils.cs +++ b/examples/src/Common/DataUtils.cs @@ -7,31 +7,27 @@ namespace Ydb.Sdk.Examples; public record Series(ulong SeriesId, string Title, DateTime ReleaseDate, string Info) { - public static Series FromRow(Value.ResultSet.Row row) - { - return new Series( + public static Series FromRow(Value.ResultSet.Row row) => + new( SeriesId: (ulong)row["series_id"].GetOptionalUint64()!, Title: (string)row["title"]!, ReleaseDate: (DateTime)row["release_date"].GetOptionalDate()!, Info: (string)row["series_info"]! ); - } } public record Season(ulong SeriesId, ulong SeasonId, string Title, DateTime FirstAired, DateTime LastAired); public record Episode(ulong SeriesId, ulong SeasonId, ulong EpisodeId, string Title, DateTime AirDate) { - public static Episode FromRow(Value.ResultSet.Row row) - { - return new Episode( + public static Episode FromRow(Value.ResultSet.Row row) => + new( SeriesId: (ulong)row["series_id"].GetOptionalUint64()!, SeasonId: (ulong)row["season_id"].GetOptionalUint64()!, EpisodeId: (ulong)row["episode_id"].GetOptionalUint64()!, Title: (string)row["title"]!, AirDate: (DateTime)row["air_date"].GetOptionalDate()! ); - } } public static class DataUtils diff --git a/examples/src/Common/TableExampleBase.cs b/examples/src/Common/TableExampleBase.cs index 5e12f1c3..168f8f51 100644 --- a/examples/src/Common/TableExampleBase.cs +++ b/examples/src/Common/TableExampleBase.cs @@ -13,8 +13,5 @@ protected TableExampleBase(TableClient client, string database, string path) BasePath = string.Join('/', database, path); } - protected string FullTablePath(string table) - { - return string.Join('/', BasePath, table); - } + protected string FullTablePath(string table) => string.Join('/', BasePath, table); } \ No newline at end of file diff --git a/examples/src/DapperExample/Program.cs b/examples/src/DapperExample/Program.cs index d563e5e9..4f554819 100644 --- a/examples/src/DapperExample/Program.cs +++ b/examples/src/DapperExample/Program.cs @@ -29,8 +29,5 @@ internal class User public string Name { get; init; } = null!; public string Email { get; init; } = null!; - public override string ToString() - { - return $"Id: {Id}, Name: {Name}, Email: {Email}"; - } + public override string ToString() => $"Id: {Id}, Name: {Name}, Email: {Email}"; } \ No newline at end of file diff --git a/examples/src/QueryExample/Program.cs b/examples/src/QueryExample/Program.cs index ea237423..8e8d8b0e 100644 --- a/examples/src/QueryExample/Program.cs +++ b/examples/src/QueryExample/Program.cs @@ -24,12 +24,10 @@ internal class CmdOptions internal static class Program { - private static ServiceProvider GetServiceProvider() - { - return new ServiceCollection() + private static ServiceProvider GetServiceProvider() => + new ServiceCollection() .AddLogging(configure => configure.AddConsole().SetMinimumLevel(LogLevel.Information)) .BuildServiceProvider(); - } private static async Task Run(CmdOptions cmdOptions) { diff --git a/examples/src/QueryExample/QueryExample.cs b/examples/src/QueryExample/QueryExample.cs index 796a2688..d189284f 100644 --- a/examples/src/QueryExample/QueryExample.cs +++ b/examples/src/QueryExample/QueryExample.cs @@ -180,9 +180,8 @@ await Client.Exec( } - private async Task InteractiveTx() - { - await Client.DoTx(async tx => + private Task InteractiveTx() => + Client.DoTx(async tx => { var query1 = @$" PRAGMA TablePathPrefix('{BasePath}'); @@ -217,7 +216,6 @@ UPSERT INTO seasons (series_id, season_id, first_aired) VALUES await tx.Exec(query2, parameters2); } ); - } private async Task StreamSelect() { diff --git a/slo/src/Internal/ConfigBinders.cs b/slo/src/Internal/ConfigBinders.cs index 6733ff8d..d4137865 100644 --- a/slo/src/Internal/ConfigBinders.cs +++ b/slo/src/Internal/ConfigBinders.cs @@ -13,9 +13,8 @@ public class CreateConfigBinder( Option writeTimeoutOption) : BinderBase { - protected override CreateConfig GetBoundValue(BindingContext bindingContext) - { - return new CreateConfig( + protected override CreateConfig GetBoundValue(BindingContext bindingContext) => + new( bindingContext.ParseResult.GetValueForArgument(endpointArgument), bindingContext.ParseResult.GetValueForArgument(dbArgument), bindingContext.ParseResult.GetValueForOption(resourceYdbPath)!, @@ -24,7 +23,6 @@ protected override CreateConfig GetBoundValue(BindingContext bindingContext) bindingContext.ParseResult.GetValueForOption(initialDataCountOption), bindingContext.ParseResult.GetValueForOption(writeTimeoutOption) ); - } } internal class RunConfigBinder( @@ -40,9 +38,8 @@ internal class RunConfigBinder( Option timeOption) : BinderBase { - protected override RunConfig GetBoundValue(BindingContext bindingContext) - { - return new RunConfig( + protected override RunConfig GetBoundValue(BindingContext bindingContext) => + new( bindingContext.ParseResult.GetValueForArgument(endpointArgument), bindingContext.ParseResult.GetValueForArgument(dbArgument), bindingContext.ParseResult.GetValueForOption(resourceYdbPath)!, @@ -54,5 +51,4 @@ protected override RunConfig GetBoundValue(BindingContext bindingContext) bindingContext.ParseResult.GetValueForOption(writeTimeoutOption), bindingContext.ParseResult.GetValueForOption(timeOption) ); - } } \ No newline at end of file diff --git a/slo/src/TableService/SloTableContext.cs b/slo/src/TableService/SloTableContext.cs index b8508b0a..105d462a 100644 --- a/slo/src/TableService/SloTableContext.cs +++ b/slo/src/TableService/SloTableContext.cs @@ -77,9 +77,7 @@ protected override async Task Create(TableClient client, string createTableSql, response.Status.IsSuccess ? response.Result.ResultSets[0].Rows[0][0].GetOptionalInt32() : null); } - protected override async Task CreateClient(Config config) - { - return new TableClient(await Driver.CreateInitialized(new DriverConfig(config.Endpoint, config.Db), - ISloContext.Factory)); - } + protected override async Task CreateClient(Config config) => new( + await Driver.CreateInitialized(new DriverConfig(config.Endpoint, config.Db), ISloContext.Factory) + ); } \ No newline at end of file diff --git a/slo/src/TopicService/SloTopicContext.cs b/slo/src/TopicService/SloTopicContext.cs index bb41c9a7..c5cfee3f 100644 --- a/slo/src/TopicService/SloTopicContext.cs +++ b/slo/src/TopicService/SloTopicContext.cs @@ -346,12 +346,10 @@ private static void CheckMessage(ConcurrentDictionary> localStore) - { - return "[" + - string.Join("\n", localStore.Select(pair => pair.Key + ": " + string.Join(", ", pair.Value))) + - "]"; - } + private static string PrintLocalStore(ConcurrentDictionary> localStore) => + "[" + + string.Join("\n", localStore.Select(pair => pair.Key + ": " + string.Join(", ", pair.Value))) + + "]"; private static void AssertMessage(Ydb.Sdk.Services.Topic.Reader.Message message, string expectedMessageData) { diff --git a/src/Ydb.Sdk/src/Ado/ThrowHelper.cs b/src/Ydb.Sdk/src/Ado/ThrowHelper.cs index d665936b..4dd739d7 100644 --- a/src/Ydb.Sdk/src/Ado/ThrowHelper.cs +++ b/src/Ydb.Sdk/src/Ado/ThrowHelper.cs @@ -4,18 +4,12 @@ namespace Ydb.Sdk.Ado; internal static class ThrowHelper { - internal static T ThrowInvalidCast(YdbValue ydbValue) - { + internal static T ThrowInvalidCast(YdbValue ydbValue) => throw new InvalidCastException($"Field YDB type {ydbValue.TypeId} can't be cast to {typeof(T)} type."); - } - internal static void ThrowIndexOutOfRangeException(int columnCount) - { + internal static void ThrowIndexOutOfRangeException(int columnCount) => throw new IndexOutOfRangeException("Ordinal must be between 0 and " + (columnCount - 1)); - } - internal static void ThrowInvalidCastException(string expectedType, string actualType) - { + internal static void ThrowInvalidCastException(string expectedType, string actualType) => throw new InvalidCastException($"Invalid type of YDB value, expected: {expectedType}, actual: {actualType}."); - } } diff --git a/src/Ydb.Sdk/src/Ado/YdbCommand.cs b/src/Ydb.Sdk/src/Ado/YdbCommand.cs index 01cb989b..9fece60e 100644 --- a/src/Ydb.Sdk/src/Ado/YdbCommand.cs +++ b/src/Ydb.Sdk/src/Ado/YdbCommand.cs @@ -28,10 +28,7 @@ public override void Cancel() { } - public override int ExecuteNonQuery() - { - return ExecuteNonQueryAsync().GetAwaiter().GetResult(); - } + public override int ExecuteNonQuery() => ExecuteNonQueryAsync().GetAwaiter().GetResult(); public override async Task ExecuteNonQueryAsync(CancellationToken cancellationToken) { @@ -44,10 +41,7 @@ public override async Task ExecuteNonQueryAsync(CancellationToken cancellat return dataReader.RecordsAffected; } - public override object? ExecuteScalar() - { - return ExecuteScalarAsync().GetAwaiter().GetResult(); - } + public override object? ExecuteScalar() => ExecuteScalarAsync().GetAwaiter().GetResult(); public override async Task ExecuteScalarAsync(CancellationToken cancellationToken) { @@ -164,20 +158,13 @@ protected override DbTransaction? DbTransaction public override bool DesignTimeVisible { get; set; } - protected override YdbParameter CreateDbParameter() - { - return new YdbParameter(); - } + protected override YdbParameter CreateDbParameter() => new(); - public new YdbDataReader ExecuteReader(CommandBehavior behavior = CommandBehavior.Default) - { - return ExecuteDbDataReader(behavior); - } + public new YdbDataReader ExecuteReader(CommandBehavior behavior = CommandBehavior.Default) => + ExecuteDbDataReader(behavior); - protected override YdbDataReader ExecuteDbDataReader(CommandBehavior behavior) - { - return ExecuteReaderAsync(behavior).GetAwaiter().GetResult(); - } + protected override YdbDataReader ExecuteDbDataReader(CommandBehavior behavior) => + ExecuteReaderAsync(behavior).GetAwaiter().GetResult(); protected override async Task ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) @@ -236,26 +223,18 @@ await YdbConnection.Session.ExecuteQuery( return ydbDataReader; } - public new async Task ExecuteReaderAsync() - { - return (YdbDataReader)await ExecuteDbDataReaderAsync(CommandBehavior.Default, CancellationToken.None); - } + public new async Task ExecuteReaderAsync() => + (YdbDataReader)await ExecuteDbDataReaderAsync(CommandBehavior.Default, CancellationToken.None); - public new Task ExecuteReaderAsync(CancellationToken cancellationToken) - { - return ExecuteReaderAsync(CommandBehavior.Default, cancellationToken); - } + public new Task ExecuteReaderAsync(CancellationToken cancellationToken) => + ExecuteReaderAsync(CommandBehavior.Default, cancellationToken); // ReSharper disable once MemberCanBePrivate.Global - public new Task ExecuteReaderAsync(CommandBehavior behavior) - { - return ExecuteReaderAsync(behavior, CancellationToken.None); - } + public new Task ExecuteReaderAsync(CommandBehavior behavior) => + ExecuteReaderAsync(behavior, CancellationToken.None); // ReSharper disable once MemberCanBePrivate.Global public new async Task ExecuteReaderAsync(CommandBehavior behavior, - CancellationToken cancellationToken) - { - return (YdbDataReader)await ExecuteDbDataReaderAsync(behavior, cancellationToken); - } + CancellationToken cancellationToken) => + (YdbDataReader)await ExecuteDbDataReaderAsync(behavior, cancellationToken); } diff --git a/src/Ydb.Sdk/src/Ado/YdbConnection.cs b/src/Ydb.Sdk/src/Ado/YdbConnection.cs index 49864269..1c82aadc 100644 --- a/src/Ydb.Sdk/src/Ado/YdbConnection.cs +++ b/src/Ydb.Sdk/src/Ado/YdbConnection.cs @@ -62,10 +62,7 @@ protected override YdbTransaction BeginDbTransaction(IsolationLevel isolationLev }); } - public new YdbTransaction BeginTransaction(IsolationLevel isolationLevel) - { - return BeginDbTransaction(isolationLevel); - } + public new YdbTransaction BeginTransaction(IsolationLevel isolationLevel) => BeginDbTransaction(isolationLevel); public YdbTransaction BeginTransaction(TxMode txMode = TxMode.SerializableRw) { @@ -87,15 +84,9 @@ public override void ChangeDatabase(string databaseName) { } - public override void Close() - { - CloseAsync().GetAwaiter().GetResult(); - } + public override void Close() => CloseAsync().GetAwaiter().GetResult(); - public override void Open() - { - OpenAsync().GetAwaiter().GetResult(); - } + public override void Open() => OpenAsync().GetAwaiter().GetResult(); public override async Task OpenAsync(CancellationToken cancellationToken) { @@ -186,48 +177,30 @@ public override string ServerVersion } } - protected override YdbCommand CreateDbCommand() - { - return new YdbCommand(this); - } + protected override YdbCommand CreateDbCommand() => new(this); - public new YdbCommand CreateCommand() - { - return CreateDbCommand(); - } + public new YdbCommand CreateCommand() => CreateDbCommand(); - public override DataTable GetSchema() - { - return GetSchemaAsync().GetAwaiter().GetResult(); - } + public override DataTable GetSchema() => GetSchemaAsync().GetAwaiter().GetResult(); - public override DataTable GetSchema(string collectionName) - { - return GetSchemaAsync(collectionName).GetAwaiter().GetResult(); - } + public override DataTable GetSchema(string collectionName) => + GetSchemaAsync(collectionName).GetAwaiter().GetResult(); - public override DataTable GetSchema(string collectionName, string?[] restrictionValues) - { - return GetSchemaAsync(collectionName, restrictionValues).GetAwaiter().GetResult(); - } + public override DataTable GetSchema(string collectionName, string?[] restrictionValues) => + GetSchemaAsync(collectionName, restrictionValues).GetAwaiter().GetResult(); - public override Task GetSchemaAsync(CancellationToken cancellationToken = default) - { - return GetSchemaAsync("MetaDataCollections", cancellationToken); - } + public override Task GetSchemaAsync(CancellationToken cancellationToken = default) => + GetSchemaAsync("MetaDataCollections", cancellationToken); - public override Task GetSchemaAsync(string collectionName, CancellationToken cancellationToken = default) - { - return GetSchemaAsync(collectionName, new string[4], cancellationToken); - } + public override Task + GetSchemaAsync(string collectionName, CancellationToken cancellationToken = default) => + GetSchemaAsync(collectionName, new string[4], cancellationToken); public override Task GetSchemaAsync( string collectionName, string?[] restrictionValues, - CancellationToken cancellationToken = default) - { - return YdbSchema.GetSchemaAsync(this, collectionName, restrictionValues, cancellationToken); - } + CancellationToken cancellationToken = default + ) => YdbSchema.GetSchemaAsync(this, collectionName, restrictionValues, cancellationToken); internal void EnsureConnectionOpen() { @@ -281,18 +254,12 @@ public override async ValueTask DisposeAsync() /// immediately closed, and any busy connections which were opened before was called /// will be closed when returned to the pool. /// - public static Task ClearPool(YdbConnection connection) - { - return PoolManager.ClearPool(connection.ConnectionString); - } + public static Task ClearPool(YdbConnection connection) => PoolManager.ClearPool(connection.ConnectionString); /// /// Clear all connection pools. All idle physical connections in all pools are immediately closed, and any busy /// connections which were opened before was called will be closed when returned /// to their pool. /// - public static Task ClearAllPools() - { - return PoolManager.ClearAllPools(); - } + public static Task ClearAllPools() => PoolManager.ClearAllPools(); } diff --git a/src/Ydb.Sdk/src/Ado/YdbConnectionStringBuilder.cs b/src/Ydb.Sdk/src/Ado/YdbConnectionStringBuilder.cs index b4eb9651..3d519c1b 100644 --- a/src/Ydb.Sdk/src/Ado/YdbConnectionStringBuilder.cs +++ b/src/Ydb.Sdk/src/Ado/YdbConnectionStringBuilder.cs @@ -241,10 +241,8 @@ private abstract class YdbConnectionOption }; [DoesNotReturn] - private static T UnexpectedArgumentException(string key, object value) - { + private static T UnexpectedArgumentException(string key, object value) => throw new ArgumentException($"Expected type {typeof(T)} for key {key}, but actual {value.GetType()}"); - } public static readonly Dictionary KeyToOption = new(); diff --git a/src/Ydb.Sdk/src/Ado/YdbDataReader.cs b/src/Ydb.Sdk/src/Ado/YdbDataReader.cs index 8dcab086..05ac025d 100644 --- a/src/Ydb.Sdk/src/Ado/YdbDataReader.cs +++ b/src/Ydb.Sdk/src/Ado/YdbDataReader.cs @@ -83,26 +83,14 @@ private async Task Init() ReaderState = State.ReadResultSet; } - public override bool GetBoolean(int ordinal) - { - return GetFieldYdbValue(ordinal).GetBool(); - } + public override bool GetBoolean(int ordinal) => GetFieldYdbValue(ordinal).GetBool(); - public override byte GetByte(int ordinal) - { - return GetFieldYdbValue(ordinal).GetUint8(); - } + public override byte GetByte(int ordinal) => GetFieldYdbValue(ordinal).GetUint8(); - public sbyte GetSByte(int ordinal) - { - return GetFieldYdbValue(ordinal).GetInt8(); - } + public sbyte GetSByte(int ordinal) => GetFieldYdbValue(ordinal).GetInt8(); // ReSharper disable once MemberCanBePrivate.Global - public byte[] GetBytes(int ordinal) - { - return GetFieldYdbValue(ordinal).GetString(); - } + public byte[] GetBytes(int ordinal) => GetFieldYdbValue(ordinal).GetString(); public override long GetBytes(int ordinal, long dataOffset, byte[]? buffer, int bufferOffset, int length) { @@ -179,10 +167,7 @@ private static void CheckOffsets(long dataOffset, T[]? buffer, int bufferOffs } } - public override string GetDataTypeName(int ordinal) - { - return ReaderMetadata.GetColumn(ordinal).Type.YqlTableType(); - } + public override string GetDataTypeName(int ordinal) => ReaderMetadata.GetColumn(ordinal).Type.YqlTableType(); public override DateTime GetDateTime(int ordinal) { @@ -197,15 +182,9 @@ public override DateTime GetDateTime(int ordinal) }; } - public TimeSpan GetInterval(int ordinal) - { - return GetFieldYdbValue(ordinal).GetInterval(); - } + public TimeSpan GetInterval(int ordinal) => GetFieldYdbValue(ordinal).GetInterval(); - public override decimal GetDecimal(int ordinal) - { - return GetFieldYdbValue(ordinal).GetDecimal(); - } + public override decimal GetDecimal(int ordinal) => GetFieldYdbValue(ordinal).GetDecimal(); public override double GetDouble(int ordinal) { @@ -274,15 +253,9 @@ public override System.Type GetFieldType(int ordinal) return systemType; } - public override float GetFloat(int ordinal) - { - return GetFieldYdbValue(ordinal).GetFloat(); - } + public override float GetFloat(int ordinal) => GetFieldYdbValue(ordinal).GetFloat(); - public override Guid GetGuid(int ordinal) - { - return GetFieldYdbValue(ordinal).GetUuid(); - } + public override Guid GetGuid(int ordinal) => GetFieldYdbValue(ordinal).GetUuid(); public override short GetInt16(int ordinal) { @@ -368,10 +341,7 @@ public ulong GetUint64(int ordinal) }; } - public override string GetName(int ordinal) - { - return ReaderMetadata.GetColumn(ordinal).Name; - } + public override string GetName(int ordinal) => ReaderMetadata.GetColumn(ordinal).Name; public override int GetOrdinal(string name) { @@ -383,25 +353,13 @@ public override int GetOrdinal(string name) throw new IndexOutOfRangeException($"Field not found in row: {name}"); } - public override string GetString(int ordinal) - { - return GetFieldYdbValue(ordinal).GetUtf8(); - } + public override string GetString(int ordinal) => GetFieldYdbValue(ordinal).GetUtf8(); - public override TextReader GetTextReader(int ordinal) - { - return new StringReader(GetString(ordinal)); - } + public override TextReader GetTextReader(int ordinal) => new StringReader(GetString(ordinal)); - public string GetJson(int ordinal) - { - return GetFieldYdbValue(ordinal).GetJson(); - } + public string GetJson(int ordinal) => GetFieldYdbValue(ordinal).GetJson(); - public string GetJsonDocument(int ordinal) - { - return GetFieldYdbValue(ordinal).GetJsonDocument(); - } + public string GetJsonDocument(int ordinal) => GetFieldYdbValue(ordinal).GetJsonDocument(); public override object GetValue(int ordinal) { @@ -464,11 +422,9 @@ public override int GetValues(object[] values) return count; } - public override bool IsDBNull(int ordinal) - { - return CurrentRow[ordinal].TypeId == YdbTypeId.Null || - (CurrentRow[ordinal].TypeId == YdbTypeId.OptionalType && CurrentRow[ordinal].GetOptional() == null); - } + public override bool IsDBNull(int ordinal) => + CurrentRow[ordinal].TypeId == YdbTypeId.Null || + (CurrentRow[ordinal].TypeId == YdbTypeId.OptionalType && CurrentRow[ordinal].GetOptional() == null); public override int FieldCount => ReaderMetadata.FieldCount; public override object this[int ordinal] => GetValue(ordinal); @@ -477,15 +433,9 @@ public override bool IsDBNull(int ordinal) public override bool HasRows => ReaderMetadata.RowsCount > 0; public override bool IsClosed => ReaderState == State.Close; - public override bool NextResult() - { - return NextResultAsync().GetAwaiter().GetResult(); - } + public override bool NextResult() => NextResultAsync().GetAwaiter().GetResult(); - public override bool Read() - { - return ReadAsync().GetAwaiter().GetResult(); - } + public override bool Read() => ReadAsync().GetAwaiter().GetResult(); public override async Task NextResultAsync(CancellationToken cancellationToken) { @@ -581,10 +531,7 @@ public override async Task CloseAsync() } } - public override void Close() - { - CloseAsync().GetAwaiter().GetResult(); - } + public override void Close() => CloseAsync().GetAwaiter().GetResult(); private YdbValue GetFieldYdbValue(int ordinal) { @@ -663,10 +610,7 @@ private void OnFailReadStream() } } - public override async ValueTask DisposeAsync() - { - await CloseAsync(); - } + public override async ValueTask DisposeAsync() => await CloseAsync(); public async IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = new()) { @@ -690,10 +634,8 @@ private EmptyMetadata() public int FieldCount => 0; public int RowsCount => 0; - public Value.ResultSet.Column GetColumn(int ordinal) - { + public Value.ResultSet.Column GetColumn(int ordinal) => throw new InvalidOperationException("No resultset is currently being traversed"); - } } private class CloseMetadata : IMetadata @@ -710,10 +652,8 @@ private CloseMetadata() public int FieldCount => throw new InvalidOperationException("The reader is closed"); public int RowsCount => 0; - public Value.ResultSet.Column GetColumn(int ordinal) - { + public Value.ResultSet.Column GetColumn(int ordinal) => throw new InvalidOperationException("The reader is closed"); - } } private class Metadata : IMetadata diff --git a/src/Ydb.Sdk/src/Ado/YdbDataRecord.cs b/src/Ydb.Sdk/src/Ado/YdbDataRecord.cs index acc9c5ed..2225cf71 100644 --- a/src/Ydb.Sdk/src/Ado/YdbDataRecord.cs +++ b/src/Ydb.Sdk/src/Ado/YdbDataRecord.cs @@ -11,110 +11,49 @@ internal YdbDataRecord(YdbDataReader ydbDataReader) _ydbDataReader = ydbDataReader; } - public override bool GetBoolean(int i) - { - return _ydbDataReader.GetBoolean(i); - } + public override bool GetBoolean(int i) => _ydbDataReader.GetBoolean(i); - public override byte GetByte(int i) - { - return _ydbDataReader.GetByte(i); - } + public override byte GetByte(int i) => _ydbDataReader.GetByte(i); - public override long GetBytes(int i, long dataIndex, byte[]? buffer, int bufferIndex, int length) - { - return _ydbDataReader.GetBytes(i, dataIndex, buffer, bufferIndex, length); - } + public override long GetBytes(int i, long dataIndex, byte[]? buffer, int bufferIndex, int length) => + _ydbDataReader.GetBytes(i, dataIndex, buffer, bufferIndex, length); - public override char GetChar(int i) - { - return _ydbDataReader.GetChar(i); - } + public override char GetChar(int i) => _ydbDataReader.GetChar(i); - public override long GetChars(int i, long dataIndex, char[]? buffer, int bufferIndex, int length) - { - return _ydbDataReader.GetChars(i, dataIndex, buffer, bufferIndex, length); - } + public override long GetChars(int i, long dataIndex, char[]? buffer, int bufferIndex, int length) => + _ydbDataReader.GetChars(i, dataIndex, buffer, bufferIndex, length); - public override string GetDataTypeName(int i) - { - return _ydbDataReader.GetDataTypeName(i); - } + public override string GetDataTypeName(int i) => _ydbDataReader.GetDataTypeName(i); - public override DateTime GetDateTime(int i) - { - return _ydbDataReader.GetDateTime(i); - } + public override DateTime GetDateTime(int i) => _ydbDataReader.GetDateTime(i); - public override decimal GetDecimal(int i) - { - return _ydbDataReader.GetDecimal(i); - } + public override decimal GetDecimal(int i) => _ydbDataReader.GetDecimal(i); - public override double GetDouble(int i) - { - return _ydbDataReader.GetDouble(i); - } + public override double GetDouble(int i) => _ydbDataReader.GetDouble(i); - public override System.Type GetFieldType(int i) - { - return _ydbDataReader.GetFieldType(i); - } + public override System.Type GetFieldType(int i) => _ydbDataReader.GetFieldType(i); - public override float GetFloat(int i) - { - return _ydbDataReader.GetFloat(i); - } + public override float GetFloat(int i) => _ydbDataReader.GetFloat(i); - public override Guid GetGuid(int i) - { - return _ydbDataReader.GetGuid(i); - } + public override Guid GetGuid(int i) => _ydbDataReader.GetGuid(i); - public override short GetInt16(int i) - { - return _ydbDataReader.GetInt16(i); - } + public override short GetInt16(int i) => _ydbDataReader.GetInt16(i); - public override int GetInt32(int i) - { - return _ydbDataReader.GetInt32(i); - } + public override int GetInt32(int i) => _ydbDataReader.GetInt32(i); - public override long GetInt64(int i) - { - return _ydbDataReader.GetInt64(i); - } + public override long GetInt64(int i) => _ydbDataReader.GetInt64(i); - public override string GetName(int i) - { - return _ydbDataReader.GetName(i); - } + public override string GetName(int i) => _ydbDataReader.GetName(i); - public override int GetOrdinal(string name) - { - return _ydbDataReader.GetOrdinal(name); - } + public override int GetOrdinal(string name) => _ydbDataReader.GetOrdinal(name); - public override string GetString(int i) - { - return _ydbDataReader.GetString(i); - } + public override string GetString(int i) => _ydbDataReader.GetString(i); - public override object GetValue(int i) - { - return _ydbDataReader.GetValue(i); - } + public override object GetValue(int i) => _ydbDataReader.GetValue(i); - public override int GetValues(object[] values) - { - return _ydbDataReader.GetValues(values); - } + public override int GetValues(object[] values) => _ydbDataReader.GetValues(values); - public override bool IsDBNull(int i) - { - return _ydbDataReader.IsDBNull(i); - } + public override bool IsDBNull(int i) => _ydbDataReader.IsDBNull(i); public override int FieldCount => _ydbDataReader.FieldCount; @@ -122,43 +61,19 @@ public override bool IsDBNull(int i) public override object this[string name] => _ydbDataReader[name]; - public byte[] GetBytes(int i) - { - return _ydbDataReader.GetBytes(i); - } + public byte[] GetBytes(int i) => _ydbDataReader.GetBytes(i); - public sbyte GetSByte(int i) - { - return _ydbDataReader.GetSByte(i); - } + public sbyte GetSByte(int i) => _ydbDataReader.GetSByte(i); - public ulong GetUint16(int i) - { - return _ydbDataReader.GetUint16(i); - } + public ulong GetUint16(int i) => _ydbDataReader.GetUint16(i); - public ulong GetUint32(int i) - { - return _ydbDataReader.GetUint32(i); - } + public ulong GetUint32(int i) => _ydbDataReader.GetUint32(i); - public ulong GetUint64(int i) - { - return _ydbDataReader.GetUint64(i); - } + public ulong GetUint64(int i) => _ydbDataReader.GetUint64(i); - public string GetJson(int i) - { - return _ydbDataReader.GetJson(i); - } + public string GetJson(int i) => _ydbDataReader.GetJson(i); - public string GetJsonDocument(int i) - { - return _ydbDataReader.GetJsonDocument(i); - } + public string GetJsonDocument(int i) => _ydbDataReader.GetJsonDocument(i); - public TimeSpan GetInterval(int i) - { - return _ydbDataReader.GetInterval(i); - } + public TimeSpan GetInterval(int i) => _ydbDataReader.GetInterval(i); } diff --git a/src/Ydb.Sdk/src/Ado/YdbDataSource.cs b/src/Ydb.Sdk/src/Ado/YdbDataSource.cs index 8f9e22b3..2a701ead 100644 --- a/src/Ydb.Sdk/src/Ado/YdbDataSource.cs +++ b/src/Ydb.Sdk/src/Ado/YdbDataSource.cs @@ -22,10 +22,7 @@ public YdbDataSource() _ydbConnectionStringBuilder = new YdbConnectionStringBuilder(); } - protected override YdbConnection CreateDbConnection() - { - return new YdbConnection(_ydbConnectionStringBuilder); - } + protected override YdbConnection CreateDbConnection() => new(_ydbConnectionStringBuilder); protected override YdbConnection OpenDbConnection() { @@ -42,15 +39,9 @@ protected override YdbConnection OpenDbConnection() } } - public new YdbConnection CreateConnection() - { - return CreateDbConnection(); - } + public new YdbConnection CreateConnection() => CreateDbConnection(); - public new YdbConnection OpenConnection() - { - return OpenDbConnection(); - } + public new YdbConnection OpenConnection() => OpenDbConnection(); public new async ValueTask OpenConnectionAsync(CancellationToken cancellationToken = default) { @@ -70,15 +61,10 @@ protected override YdbConnection OpenDbConnection() public override string ConnectionString => _ydbConnectionStringBuilder.ConnectionString; - protected override async ValueTask DisposeAsyncCore() - { + protected override async ValueTask DisposeAsyncCore() => await PoolManager.ClearPool(_ydbConnectionStringBuilder.ConnectionString); - } - protected override void Dispose(bool disposing) - { - DisposeAsyncCore().AsTask().GetAwaiter().GetResult(); - } + protected override void Dispose(bool disposing) => DisposeAsyncCore().AsTask().GetAwaiter().GetResult(); } #endif diff --git a/src/Ydb.Sdk/src/Ado/YdbParameter.cs b/src/Ydb.Sdk/src/Ado/YdbParameter.cs index 2712b0c0..00a9cde4 100644 --- a/src/Ydb.Sdk/src/Ado/YdbParameter.cs +++ b/src/Ydb.Sdk/src/Ado/YdbParameter.cs @@ -70,16 +70,13 @@ public override void ResetDbType() public override string ParameterName { get => _parameterName; - set + set => _parameterName = value switch { - _parameterName = value switch - { - null => string.Empty, - _ when value.StartsWith("$") => value, - _ when value.StartsWith("@") && value.Length > 1 => $"${value[1..]}", - _ => $"${value}" - }; - } + null => string.Empty, + _ when value.StartsWith("$") => value, + _ when value.StartsWith("@") && value.Length > 1 => $"${value[1..]}", + _ => $"${value}" + }; } private string _sourceColumn = string.Empty; @@ -96,99 +93,90 @@ public override string SourceColumn public override bool SourceColumnNullMapping { get; set; } public override int Size { get; set; } - internal YdbValue YdbValue + internal YdbValue YdbValue => Value switch { - get + YdbValue ydbValue => ydbValue, + null or DBNull when YdbNullByDbType.TryGetValue(DbType, out var value) => value, + string valueString when DbType is DbType.String or DbType.AnsiString or DbType.AnsiStringFixedLength + or DbType.StringFixedLength or DbType.Object => YdbValue.MakeUtf8(valueString), + bool boolValue when DbType is DbType.Boolean or DbType.Object => YdbValue.MakeBool(boolValue), + DateTime dateTimeValue => DbType switch { - return Value switch - { - YdbValue ydbValue => ydbValue, - null or DBNull when YdbNullByDbType.TryGetValue(DbType, out var value) => value, - string valueString when DbType is DbType.String or DbType.AnsiString or DbType.AnsiStringFixedLength - or DbType.StringFixedLength or DbType.Object => YdbValue.MakeUtf8(valueString), - bool boolValue when DbType is DbType.Boolean or DbType.Object => YdbValue.MakeBool(boolValue), - DateTime dateTimeValue => DbType switch - { - DbType.Date => YdbValue.MakeDate(dateTimeValue), - DbType.DateTime => YdbValue.MakeDatetime(dateTimeValue), - DbType.DateTime2 or DbType.Object => YdbValue.MakeTimestamp(dateTimeValue), - _ => ThrowInvalidOperation() - }, - DateTimeOffset dateTimeOffset when DbType is DbType.DateTimeOffset or DbType.Object => - YdbValue.MakeTimestamp(dateTimeOffset.UtcDateTime), - float floatValue => DbType switch - { - DbType.Single or DbType.Object => YdbValue.MakeFloat(floatValue), - DbType.Double => YdbValue.MakeDouble(floatValue), - _ => ThrowInvalidOperation() - }, - double doubleValue when DbType is DbType.Double or DbType.Object => YdbValue.MakeDouble(doubleValue), - int intValue => DbType switch - { - DbType.Int32 or DbType.Object => YdbValue.MakeInt32(intValue), - DbType.Int64 => YdbValue.MakeInt64(intValue), - _ => ThrowInvalidOperation() - }, - long longValue when DbType is DbType.Int64 or DbType.Object => YdbValue.MakeInt64(longValue), - decimal decimalValue when DbType is DbType.Decimal or DbType.Currency or DbType.Object => - YdbValue.MakeDecimal(decimalValue), - ulong ulongValue when DbType is DbType.UInt64 or DbType.Object => YdbValue.MakeUint64(ulongValue), - uint uintValue => DbType switch - { - DbType.UInt32 or DbType.Object => YdbValue.MakeUint32(uintValue), - DbType.UInt64 => YdbValue.MakeUint64(uintValue), - DbType.Int64 => YdbValue.MakeInt64(uintValue), - _ => ThrowInvalidOperation() - }, - byte byteValue => DbType switch - { - DbType.Byte or DbType.Object => YdbValue.MakeUint8(byteValue), - DbType.Int64 => YdbValue.MakeInt64(byteValue), - DbType.Int32 => YdbValue.MakeInt32(byteValue), - DbType.Int16 => YdbValue.MakeInt16(byteValue), - DbType.UInt64 => YdbValue.MakeUint64(byteValue), - DbType.UInt32 => YdbValue.MakeUint32(byteValue), - DbType.UInt16 => YdbValue.MakeUint16(byteValue), - _ => ThrowInvalidOperation() - }, - sbyte sbyteValue => DbType switch - { - DbType.SByte or DbType.Object => YdbValue.MakeInt8(sbyteValue), - DbType.Int64 => YdbValue.MakeInt64(sbyteValue), - DbType.Int32 => YdbValue.MakeInt32(sbyteValue), - DbType.Int16 => YdbValue.MakeInt16(sbyteValue), - _ => ThrowInvalidOperation() - }, - ushort ushortValue => DbType switch - { - DbType.UInt16 or DbType.Object => YdbValue.MakeUint16(ushortValue), - DbType.Int64 => YdbValue.MakeInt64(ushortValue), - DbType.Int32 => YdbValue.MakeInt32(ushortValue), - DbType.UInt64 => YdbValue.MakeUint64(ushortValue), - DbType.UInt32 => YdbValue.MakeUint32(ushortValue), - _ => ThrowInvalidOperation() - }, - short shortValue => DbType switch - { - DbType.Int16 or DbType.Object => YdbValue.MakeInt16(shortValue), - DbType.Int64 => YdbValue.MakeInt64(shortValue), - DbType.Int32 => YdbValue.MakeInt32(shortValue), - _ => ThrowInvalidOperation() - }, - byte[] bytesValue when DbType is DbType.Binary or DbType.Object => YdbValue.MakeString(bytesValue), - Guid guidValue when DbType is DbType.Guid or DbType.Object => YdbValue.MakeUuid(guidValue), - MemoryStream memoryStream when DbType is DbType.Binary or DbType.Object => YdbValue.MakeString( - memoryStream.ToArray()), - _ when DbType is DbType.VarNumeric or DbType.Xml or DbType.Time => - throw new YdbException($"Ydb don't supported this DbType: {DbType}"), - _ => ThrowInvalidOperation() - }; - } - } + DbType.Date => YdbValue.MakeDate(dateTimeValue), + DbType.DateTime => YdbValue.MakeDatetime(dateTimeValue), + DbType.DateTime2 or DbType.Object => YdbValue.MakeTimestamp(dateTimeValue), + _ => ThrowInvalidOperation() + }, + DateTimeOffset dateTimeOffset when DbType is DbType.DateTimeOffset or DbType.Object => + YdbValue.MakeTimestamp(dateTimeOffset.UtcDateTime), + float floatValue => DbType switch + { + DbType.Single or DbType.Object => YdbValue.MakeFloat(floatValue), + DbType.Double => YdbValue.MakeDouble(floatValue), + _ => ThrowInvalidOperation() + }, + double doubleValue when DbType is DbType.Double or DbType.Object => YdbValue.MakeDouble(doubleValue), + int intValue => DbType switch + { + DbType.Int32 or DbType.Object => YdbValue.MakeInt32(intValue), + DbType.Int64 => YdbValue.MakeInt64(intValue), + _ => ThrowInvalidOperation() + }, + long longValue when DbType is DbType.Int64 or DbType.Object => YdbValue.MakeInt64(longValue), + decimal decimalValue when DbType is DbType.Decimal or DbType.Currency or DbType.Object => + YdbValue.MakeDecimal(decimalValue), + ulong ulongValue when DbType is DbType.UInt64 or DbType.Object => YdbValue.MakeUint64(ulongValue), + uint uintValue => DbType switch + { + DbType.UInt32 or DbType.Object => YdbValue.MakeUint32(uintValue), + DbType.UInt64 => YdbValue.MakeUint64(uintValue), + DbType.Int64 => YdbValue.MakeInt64(uintValue), + _ => ThrowInvalidOperation() + }, + byte byteValue => DbType switch + { + DbType.Byte or DbType.Object => YdbValue.MakeUint8(byteValue), + DbType.Int64 => YdbValue.MakeInt64(byteValue), + DbType.Int32 => YdbValue.MakeInt32(byteValue), + DbType.Int16 => YdbValue.MakeInt16(byteValue), + DbType.UInt64 => YdbValue.MakeUint64(byteValue), + DbType.UInt32 => YdbValue.MakeUint32(byteValue), + DbType.UInt16 => YdbValue.MakeUint16(byteValue), + _ => ThrowInvalidOperation() + }, + sbyte sbyteValue => DbType switch + { + DbType.SByte or DbType.Object => YdbValue.MakeInt8(sbyteValue), + DbType.Int64 => YdbValue.MakeInt64(sbyteValue), + DbType.Int32 => YdbValue.MakeInt32(sbyteValue), + DbType.Int16 => YdbValue.MakeInt16(sbyteValue), + _ => ThrowInvalidOperation() + }, + ushort ushortValue => DbType switch + { + DbType.UInt16 or DbType.Object => YdbValue.MakeUint16(ushortValue), + DbType.Int64 => YdbValue.MakeInt64(ushortValue), + DbType.Int32 => YdbValue.MakeInt32(ushortValue), + DbType.UInt64 => YdbValue.MakeUint64(ushortValue), + DbType.UInt32 => YdbValue.MakeUint32(ushortValue), + _ => ThrowInvalidOperation() + }, + short shortValue => DbType switch + { + DbType.Int16 or DbType.Object => YdbValue.MakeInt16(shortValue), + DbType.Int64 => YdbValue.MakeInt64(shortValue), + DbType.Int32 => YdbValue.MakeInt32(shortValue), + _ => ThrowInvalidOperation() + }, + byte[] bytesValue when DbType is DbType.Binary or DbType.Object => YdbValue.MakeString(bytesValue), + Guid guidValue when DbType is DbType.Guid or DbType.Object => YdbValue.MakeUuid(guidValue), + MemoryStream memoryStream when DbType is DbType.Binary or DbType.Object => YdbValue.MakeString( + memoryStream.ToArray()), + _ when DbType is DbType.VarNumeric or DbType.Xml or DbType.Time => + throw new YdbException($"Ydb don't supported this DbType: {DbType}"), + _ => ThrowInvalidOperation() + }; - private YdbValue ThrowInvalidOperation() - { - throw new InvalidOperationException( - $"Writing value of '{Value?.GetType().ToString() ?? "null"}' is not supported for parameters having DbType '{DbType}'"); - } + private YdbValue ThrowInvalidOperation() => throw new InvalidOperationException( + $"Writing value of '{Value?.GetType().ToString() ?? "null"}' is not supported for parameters having DbType '{DbType}'"); } diff --git a/src/Ydb.Sdk/src/Ado/YdbParameterCollection.cs b/src/Ydb.Sdk/src/Ado/YdbParameterCollection.cs index 3f0c5016..b98e341e 100644 --- a/src/Ydb.Sdk/src/Ado/YdbParameterCollection.cs +++ b/src/Ydb.Sdk/src/Ado/YdbParameterCollection.cs @@ -22,10 +22,7 @@ internal YdbParameterCollection() /// /// The name of the . /// The value of the to add to the collection. - public void AddWithValue(string parameterName, object value) - { - Add(new YdbParameter(parameterName, value)); - } + public void AddWithValue(string parameterName, object value) => Add(new YdbParameter(parameterName, value)); /// /// Adds a to the given the specified parameter name, @@ -35,22 +32,14 @@ public void AddWithValue(string parameterName, object value) /// One of the NpgsqlDbType values. /// The value of the to add to the collection. /// The parameter that was added. - public void AddWithValue(string parameterName, DbType parameterType, object? value = null) - { + public void AddWithValue(string parameterName, DbType parameterType, object? value = null) => Add(new YdbParameter(parameterName, parameterType) { Value = value }); - } /// - void ICollection.Add(YdbParameter item) - { - Add(item); - } + void ICollection.Add(YdbParameter item) => Add(item); /// - public override int Add(object value) - { - return Add(Cast(value)); - } + public override int Add(object value) => Add(Cast(value)); /// /// Adds the specified object to the . @@ -66,88 +55,55 @@ public int Add(YdbParameter item) /// /// Removes all items from the collection. /// - public override void Clear() - { - _parameters.Clear(); - } + public override void Clear() => _parameters.Clear(); /// /// Report whether the specified parameter is present in the collection. /// /// Parameter to find. /// True if the parameter was found, otherwise false. - public bool Contains(YdbParameter item) - { - return _parameters.Contains(item); - } + public bool Contains(YdbParameter item) => _parameters.Contains(item); /// - public override bool Contains(object value) - { - return _parameters.Contains(value); - } + public override bool Contains(object value) => _parameters.Contains(value); /// - public void CopyTo(YdbParameter[] array, int arrayIndex) - { - _parameters.CopyTo(array, arrayIndex); - } + public void CopyTo(YdbParameter[] array, int arrayIndex) => _parameters.CopyTo(array, arrayIndex); /// /// Remove the specified parameter from the collection. /// /// Parameter to remove. /// True if the parameter was found and removed, otherwise false. - public bool Remove(YdbParameter item) - { - return _parameters.Remove(item); - } + public bool Remove(YdbParameter item) => _parameters.Remove(item); /// - public override int IndexOf(object? value) - { - return _parameters.IndexOf(Cast(value)); - } + public override int IndexOf(object? value) => _parameters.IndexOf(Cast(value)); /// - public override void Insert(int index, object value) - { - _parameters.Insert(index, Cast(value)); - } + public override void Insert(int index, object value) => _parameters.Insert(index, Cast(value)); /// /// Removes the specified from the collection. /// /// The to remove from the collection. - public override void Remove(object value) - { - Remove(Cast(value)); - } + public override void Remove(object value) => Remove(Cast(value)); /// /// Report the offset within the collection of the given parameter. /// /// Parameter to find. /// Index of the parameter, or -1 if the parameter is not present. - public int IndexOf(YdbParameter item) - { - return _parameters.IndexOf(item); - } + public int IndexOf(YdbParameter item) => _parameters.IndexOf(item); /// - public void Insert(int index, YdbParameter item) - { - _parameters[index] = item; - } + public void Insert(int index, YdbParameter item) => _parameters[index] = item; /// /// Removes the specified from the collection using a specific index. /// /// The zero-based index of the parameter. - public override void RemoveAt(int index) - { - _parameters.RemoveAt(index); - } + public override void RemoveAt(int index) => _parameters.RemoveAt(index); /// /// Gets the at the specified index. @@ -161,16 +117,10 @@ public override void RemoveAt(int index) } /// - public override void RemoveAt(string parameterName) - { - RemoveAt(IndexOf(parameterName)); - } + public override void RemoveAt(string parameterName) => RemoveAt(IndexOf(parameterName)); /// - protected override void SetParameter(int index, DbParameter value) - { - Insert(index, Cast(value)); - } + protected override void SetParameter(int index, DbParameter value) => Insert(index, Cast(value)); /// protected override void SetParameter(string parameterName, DbParameter value) @@ -210,34 +160,19 @@ public override int IndexOf(string parameterName) } /// - public override bool Contains(string parameterName) - { - return IndexOf(parameterName) != -1; - } + public override bool Contains(string parameterName) => IndexOf(parameterName) != -1; /// - public override void CopyTo(Array array, int index) - { - ((ICollection)_parameters).CopyTo(array, index); - } + public override void CopyTo(Array array, int index) => ((ICollection)_parameters).CopyTo(array, index); /// - IEnumerator IEnumerable.GetEnumerator() - { - return _parameters.GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => _parameters.GetEnumerator(); /// - public override IEnumerator GetEnumerator() - { - return _parameters.GetEnumerator(); - } + public override IEnumerator GetEnumerator() => _parameters.GetEnumerator(); /// - protected override YdbParameter GetParameter(int index) - { - return this[index]; - } + protected override YdbParameter GetParameter(int index) => this[index]; /// protected override YdbParameter GetParameter(string parameterName) diff --git a/src/Ydb.Sdk/src/Ado/YdbProviderFactory.cs b/src/Ydb.Sdk/src/Ado/YdbProviderFactory.cs index 120a0d9d..9f6731be 100644 --- a/src/Ydb.Sdk/src/Ado/YdbProviderFactory.cs +++ b/src/Ydb.Sdk/src/Ado/YdbProviderFactory.cs @@ -6,30 +6,15 @@ public class YdbProviderFactory : DbProviderFactory { public static readonly YdbProviderFactory Instance = new(); - public override YdbCommand CreateCommand() - { - return new YdbCommand(); - } + public override YdbCommand CreateCommand() => new(); - public override YdbConnection CreateConnection() - { - return new YdbConnection(); - } + public override YdbConnection CreateConnection() => new(); - public override YdbConnectionStringBuilder CreateConnectionStringBuilder() - { - return new YdbConnectionStringBuilder(); - } + public override YdbConnectionStringBuilder CreateConnectionStringBuilder() => new(); - public override DbParameter CreateParameter() - { - return new YdbParameter(); - } + public override DbParameter CreateParameter() => new YdbParameter(); #if NET7_0_OR_GREATER - public override YdbDataSource CreateDataSource(string connectionString) - { - return new YdbDataSource(); - } + public override YdbDataSource CreateDataSource(string connectionString) => new(); #endif } diff --git a/src/Ydb.Sdk/src/Ado/YdbSchema.cs b/src/Ydb.Sdk/src/Ado/YdbSchema.cs index d9ba68c3..dc1c8fe7 100644 --- a/src/Ydb.Sdk/src/Ado/YdbSchema.cs +++ b/src/Ydb.Sdk/src/Ado/YdbSchema.cs @@ -444,27 +444,16 @@ private static DataTable GetRestrictions() return table; } - private static string WithSuffix(string path) - { - return path.EndsWith('/') ? path : path + '/'; - } + private static string WithSuffix(string path) => path.EndsWith('/') ? path : path + '/'; - private static bool IsSystem(this string tablePath) - { - return tablePath.StartsWith(".sys/") - || tablePath.StartsWith(".sys_health/") - || tablePath.StartsWith(".sys_health_dev/"); - } + private static bool IsSystem(this string tablePath) => tablePath.StartsWith(".sys/") + || tablePath.StartsWith(".sys_health/") + || tablePath.StartsWith(".sys_health_dev/"); - private static bool IsPattern(this string tableType, string? expectedTableType) - { - return expectedTableType == null || expectedTableType.Equals(tableType, StringComparison.OrdinalIgnoreCase); - } + private static bool IsPattern(this string tableType, string? expectedTableType) => + expectedTableType == null || expectedTableType.Equals(tableType, StringComparison.OrdinalIgnoreCase); - internal static string YqlTableType(this Type type) - { - return type.TypeCase == Type.TypeOneofCase.OptionalType - ? type.OptionalType.Item.TypeId.ToString() - : type.TypeId.ToString(); - } + internal static string YqlTableType(this Type type) => type.TypeCase == Type.TypeOneofCase.OptionalType + ? type.OptionalType.Item.TypeId.ToString() + : type.TypeId.ToString(); } diff --git a/src/Ydb.Sdk/src/Ado/YdbTransaction.cs b/src/Ydb.Sdk/src/Ado/YdbTransaction.cs index 35259104..32ba5f89 100644 --- a/src/Ydb.Sdk/src/Ado/YdbTransaction.cs +++ b/src/Ydb.Sdk/src/Ado/YdbTransaction.cs @@ -38,21 +38,13 @@ internal YdbTransaction(YdbConnection ydbConnection, TxMode txMode) _txMode = txMode; } - public override void Commit() - { - CommitAsync().GetAwaiter().GetResult(); - } + public override void Commit() => CommitAsync().GetAwaiter().GetResult(); // TODO propagate cancellation token - public override async Task CommitAsync(CancellationToken cancellationToken = new()) - { + public override async Task CommitAsync(CancellationToken cancellationToken = new()) => await FinishTransaction(txId => DbConnection!.Session.CommitTransaction(txId)); - } - public override void Rollback() - { - RollbackAsync().GetAwaiter().GetResult(); - } + public override void Rollback() => RollbackAsync().GetAwaiter().GetResult(); // TODO propagate cancellation token public override async Task RollbackAsync(CancellationToken cancellationToken = new()) diff --git a/src/Ydb.Sdk/src/Auth/AnonymousProvider.cs b/src/Ydb.Sdk/src/Auth/AnonymousProvider.cs index fbde0a1f..b99873b3 100644 --- a/src/Ydb.Sdk/src/Auth/AnonymousProvider.cs +++ b/src/Ydb.Sdk/src/Auth/AnonymousProvider.cs @@ -2,8 +2,5 @@ public class AnonymousProvider : ICredentialsProvider { - public string? GetAuthInfo() - { - return null; - } + public string? GetAuthInfo() => null; } diff --git a/src/Ydb.Sdk/src/Auth/ICredentialsProvider.cs b/src/Ydb.Sdk/src/Auth/ICredentialsProvider.cs index a3f7f8d0..3f270de0 100644 --- a/src/Ydb.Sdk/src/Auth/ICredentialsProvider.cs +++ b/src/Ydb.Sdk/src/Auth/ICredentialsProvider.cs @@ -7,13 +7,7 @@ public interface ICredentialsProvider // For removal in 1.* string? GetAuthInfo(); - ValueTask GetAuthInfoAsync() - { - return ValueTask.FromResult(GetAuthInfo()); - } + ValueTask GetAuthInfoAsync() => ValueTask.FromResult(GetAuthInfo()); - Task ProvideAuthClient(AuthClient authClient) - { - return Task.CompletedTask; - } + Task ProvideAuthClient(AuthClient authClient) => Task.CompletedTask; } diff --git a/src/Ydb.Sdk/src/Auth/StaticCredentialsProvider.cs b/src/Ydb.Sdk/src/Auth/StaticCredentialsProvider.cs index e72e454b..b6d09006 100644 --- a/src/Ydb.Sdk/src/Auth/StaticCredentialsProvider.cs +++ b/src/Ydb.Sdk/src/Auth/StaticCredentialsProvider.cs @@ -36,10 +36,7 @@ public StaticCredentialsProvider(string user, string? password, ILoggerFactory? _logger = loggerFactory.CreateLogger(); } - private async Task UpdateToken() - { - _token = await ReceiveToken(); - } + private async Task UpdateToken() => _token = await ReceiveToken(); public string GetAuthInfo() { @@ -188,15 +185,9 @@ public TokenData(string token, DateTime expiresAt, float refreshInterval) private DateTime RefreshAt { get; } - public bool IsExpired() - { - return DateTime.UtcNow >= ExpiresAt; - } + public bool IsExpired() => DateTime.UtcNow >= ExpiresAt; - public bool IsRefreshNeeded() - { - return DateTime.UtcNow >= RefreshAt; - } + public bool IsRefreshNeeded() => DateTime.UtcNow >= RefreshAt; } } diff --git a/src/Ydb.Sdk/src/Auth/TokenProvider.cs b/src/Ydb.Sdk/src/Auth/TokenProvider.cs index 03b71af9..2822bbf6 100644 --- a/src/Ydb.Sdk/src/Auth/TokenProvider.cs +++ b/src/Ydb.Sdk/src/Auth/TokenProvider.cs @@ -9,8 +9,5 @@ public TokenProvider(string token) _token = token; } - public string GetAuthInfo() - { - return _token; - } + public string GetAuthInfo() => _token; } diff --git a/src/Ydb.Sdk/src/Client/ClientOperation.cs b/src/Ydb.Sdk/src/Client/ClientOperation.cs index 53b9f74d..a9cbba9d 100644 --- a/src/Ydb.Sdk/src/Client/ClientOperation.cs +++ b/src/Ydb.Sdk/src/Client/ClientOperation.cs @@ -82,10 +82,7 @@ public void EnsureReady() return _result.Unpack(); } - internal static ClientOperation FromProto(Operations.Operation operationProto) - { - return new ClientOperation(operationProto); - } + internal static ClientOperation FromProto(Operations.Operation operationProto) => new(operationProto); } public class OperationException : Exception diff --git a/src/Ydb.Sdk/src/Client/Response.cs b/src/Ydb.Sdk/src/Client/Response.cs index 3e433fe7..9f0a297a 100644 --- a/src/Ydb.Sdk/src/Client/Response.cs +++ b/src/Ydb.Sdk/src/Client/Response.cs @@ -16,10 +16,7 @@ protected ResponseBase(Status status) Status = status; } - public void EnsureSuccess() - { - Status.EnsureSuccess(); - } + public void EnsureSuccess() => Status.EnsureSuccess(); } public class ClientInternalErrorResponse : ResponseBase diff --git a/src/Ydb.Sdk/src/Driver.cs b/src/Ydb.Sdk/src/Driver.cs index f5b13724..81f5de90 100644 --- a/src/Ydb.Sdk/src/Driver.cs +++ b/src/Ydb.Sdk/src/Driver.cs @@ -46,10 +46,7 @@ public static async Task CreateInitialized(DriverConfig config, ILoggerF return driver; } - protected override ValueTask InternalDispose() - { - return _channelPool.DisposeAsync(); - } + protected override ValueTask InternalDispose() => _channelPool.DisposeAsync(); public async Task Initialize() { diff --git a/src/Ydb.Sdk/src/IDriver.cs b/src/Ydb.Sdk/src/IDriver.cs index cfa4a0ed..064d8a1a 100644 --- a/src/Ydb.Sdk/src/IDriver.cs +++ b/src/Ydb.Sdk/src/IDriver.cs @@ -166,10 +166,7 @@ protected async ValueTask GetCallOptions(GrpcRequestSettings settin public ILoggerFactory LoggerFactory { get; } - public void Dispose() - { - DisposeAsync().AsTask().GetAwaiter().GetResult(); - } + public void Dispose() => DisposeAsync().AsTask().GetAwaiter().GetResult(); public async ValueTask DisposeAsync() { @@ -216,10 +213,7 @@ public async ValueTask MoveNextAsync() public TResponse Current => _stream.ResponseStream.Current; - public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = new()) - { - return this; - } + public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = new()) => this; } internal class BidirectionalStream : IBidirectionalStream @@ -282,8 +276,5 @@ public async Task RequestStreamComplete() } } - public void Dispose() - { - _stream.Dispose(); - } + public void Dispose() => _stream.Dispose(); } diff --git a/src/Ydb.Sdk/src/Pool/ChannelPool.cs b/src/Ydb.Sdk/src/Pool/ChannelPool.cs index d9d93d98..437f55f3 100644 --- a/src/Ydb.Sdk/src/Pool/ChannelPool.cs +++ b/src/Ydb.Sdk/src/Pool/ChannelPool.cs @@ -21,10 +21,8 @@ public ChannelPool(ILogger> logger, IChannelFactory channelFac _channelFactory = channelFactory; } - public T GetChannel(string endpoint) - { - return _channels.GetOrAdd(endpoint, new Lazy(() => _channelFactory.CreateChannel(endpoint))).Value; - } + public T GetChannel(string endpoint) => + _channels.GetOrAdd(endpoint, new Lazy(() => _channelFactory.CreateChannel(endpoint))).Value; public async ValueTask RemoveChannels(ImmutableArray removedEndpoints) { diff --git a/src/Ydb.Sdk/src/Pool/EndpointPool.cs b/src/Ydb.Sdk/src/Pool/EndpointPool.cs index fbe02c10..070cc1f2 100644 --- a/src/Ydb.Sdk/src/Pool/EndpointPool.cs +++ b/src/Ydb.Sdk/src/Pool/EndpointPool.cs @@ -145,10 +145,7 @@ private record PriorityEndpoint(string Endpoint) { internal int Priority { get; private set; } - internal void Pessimize() - { - Priority = int.MaxValue; - } + internal void Pessimize() => Priority = int.MaxValue; internal bool IsPessimized => Priority == int.MaxValue; } @@ -173,8 +170,5 @@ private ThreadLocalRandom() { } - public int Next(int maxValue) - { - return ThreadStaticRandom.Next(maxValue); - } + public int Next(int maxValue) => ThreadStaticRandom.Next(maxValue); } diff --git a/src/Ydb.Sdk/src/Pool/SessionPool.cs b/src/Ydb.Sdk/src/Pool/SessionPool.cs index 48e4c054..67809a6b 100644 --- a/src/Ydb.Sdk/src/Pool/SessionPool.cs +++ b/src/Ydb.Sdk/src/Pool/SessionPool.cs @@ -155,18 +155,13 @@ internal async ValueTask ReleaseSession(TSession session) } } - private void Release() - { - _semaphore.Release(); - } + private void Release() => _semaphore.Release(); - private Task DeleteSession(TSession session) - { - return session.DeleteSession().ContinueWith(s => + private Task DeleteSession(TSession session) => + session.DeleteSession().ContinueWith(s => { Logger.LogDebug("Session[{id}] removed with status {status}", session.SessionId, s.Result); }); - } public async ValueTask DisposeAsync() { @@ -187,10 +182,7 @@ public async ValueTask DisposeAsync() await TryDriverDispose(_size); } - protected virtual ValueTask DisposeDriver() - { - return default; - } + protected virtual ValueTask DisposeDriver() => default; private async ValueTask TryDriverDispose(int expectedCurrentCount) { @@ -236,10 +228,7 @@ StatusCode.Unavailable or } } - internal ValueTask Release() - { - return _sessionPool.ReleaseSession((T)this); - } + internal ValueTask Release() => _sessionPool.ReleaseSession((T)this); internal TS MakeGrpcRequestSettings(TS settings) where TS : GrpcRequestSettings { diff --git a/src/Ydb.Sdk/src/Retry.cs b/src/Ydb.Sdk/src/Retry.cs index 5199d46f..65735f6f 100644 --- a/src/Ydb.Sdk/src/Retry.cs +++ b/src/Ydb.Sdk/src/Retry.cs @@ -84,38 +84,35 @@ public RetrySettings( private static readonly BackoffSettings NoBackoff = new(TimeSpan.Zero, 10, 0.5); - public RetryRule GetRetryRule(StatusCode statusCode) + public RetryRule GetRetryRule(StatusCode statusCode) => statusCode switch { - return statusCode switch - { - StatusCode.Unspecified => new RetryRule(NoBackoff, false, RetryPolicy.None), - StatusCode.BadRequest => new RetryRule(NoBackoff, false, RetryPolicy.None), - StatusCode.Unauthorized => new RetryRule(NoBackoff, false, RetryPolicy.None), - StatusCode.InternalError => new RetryRule(NoBackoff, false, RetryPolicy.None), - StatusCode.Aborted => new RetryRule(FastBackoff, false, RetryPolicy.Unconditional), - StatusCode.Unavailable => new RetryRule(FastBackoff, false, RetryPolicy.Unconditional), - StatusCode.Overloaded => new RetryRule(SlowBackoff, false, RetryPolicy.Unconditional), - StatusCode.SchemeError => new RetryRule(NoBackoff, false, RetryPolicy.None), - StatusCode.GenericError => new RetryRule(NoBackoff, false, RetryPolicy.None), - StatusCode.Timeout => new RetryRule(NoBackoff, false, RetryPolicy.None), - StatusCode.BadSession => new RetryRule(NoBackoff, true, RetryPolicy.Unconditional), - StatusCode.PreconditionFailed => new RetryRule(NoBackoff, false, RetryPolicy.None), - StatusCode.AlreadyExists => new RetryRule(NoBackoff, false, RetryPolicy.None), - StatusCode.NotFound => new RetryRule(NoBackoff, false, RetryPolicy.None), - StatusCode.SessionExpired => new RetryRule(NoBackoff, true, RetryPolicy.None), - StatusCode.Cancelled => new RetryRule(FastBackoff, false, RetryPolicy.None), - StatusCode.Undetermined => new RetryRule(FastBackoff, false, RetryPolicy.IdempotentOnly), - StatusCode.Unsupported => new RetryRule(NoBackoff, false, RetryPolicy.None), - StatusCode.SessionBusy => new RetryRule(FastBackoff, true, RetryPolicy.Unconditional), - StatusCode.Success => new RetryRule(NoBackoff, false, RetryPolicy.None), - StatusCode.ClientResourceExhausted => new RetryRule(SlowBackoff, false, RetryPolicy.Unconditional), - StatusCode.ClientInternalError => new RetryRule(FastBackoff, true, RetryPolicy.IdempotentOnly), - StatusCode.ClientTransportUnknown => new RetryRule(NoBackoff, true, RetryPolicy.None), - StatusCode.ClientTransportUnavailable => new RetryRule(FastBackoff, true, RetryPolicy.IdempotentOnly), - StatusCode.ClientTransportTimeout => new RetryRule(FastBackoff, true, RetryPolicy.IdempotentOnly), - StatusCode.ClientTransportResourceExhausted => new RetryRule(SlowBackoff, true, RetryPolicy.Unconditional), - StatusCode.ClientTransportUnimplemented => new RetryRule(NoBackoff, true, RetryPolicy.None), - _ => throw new ArgumentOutOfRangeException(nameof(statusCode), statusCode, null) - }; - } + StatusCode.Unspecified => new RetryRule(NoBackoff, false, RetryPolicy.None), + StatusCode.BadRequest => new RetryRule(NoBackoff, false, RetryPolicy.None), + StatusCode.Unauthorized => new RetryRule(NoBackoff, false, RetryPolicy.None), + StatusCode.InternalError => new RetryRule(NoBackoff, false, RetryPolicy.None), + StatusCode.Aborted => new RetryRule(FastBackoff, false, RetryPolicy.Unconditional), + StatusCode.Unavailable => new RetryRule(FastBackoff, false, RetryPolicy.Unconditional), + StatusCode.Overloaded => new RetryRule(SlowBackoff, false, RetryPolicy.Unconditional), + StatusCode.SchemeError => new RetryRule(NoBackoff, false, RetryPolicy.None), + StatusCode.GenericError => new RetryRule(NoBackoff, false, RetryPolicy.None), + StatusCode.Timeout => new RetryRule(NoBackoff, false, RetryPolicy.None), + StatusCode.BadSession => new RetryRule(NoBackoff, true, RetryPolicy.Unconditional), + StatusCode.PreconditionFailed => new RetryRule(NoBackoff, false, RetryPolicy.None), + StatusCode.AlreadyExists => new RetryRule(NoBackoff, false, RetryPolicy.None), + StatusCode.NotFound => new RetryRule(NoBackoff, false, RetryPolicy.None), + StatusCode.SessionExpired => new RetryRule(NoBackoff, true, RetryPolicy.None), + StatusCode.Cancelled => new RetryRule(FastBackoff, false, RetryPolicy.None), + StatusCode.Undetermined => new RetryRule(FastBackoff, false, RetryPolicy.IdempotentOnly), + StatusCode.Unsupported => new RetryRule(NoBackoff, false, RetryPolicy.None), + StatusCode.SessionBusy => new RetryRule(FastBackoff, true, RetryPolicy.Unconditional), + StatusCode.Success => new RetryRule(NoBackoff, false, RetryPolicy.None), + StatusCode.ClientResourceExhausted => new RetryRule(SlowBackoff, false, RetryPolicy.Unconditional), + StatusCode.ClientInternalError => new RetryRule(FastBackoff, true, RetryPolicy.IdempotentOnly), + StatusCode.ClientTransportUnknown => new RetryRule(NoBackoff, true, RetryPolicy.None), + StatusCode.ClientTransportUnavailable => new RetryRule(FastBackoff, true, RetryPolicy.IdempotentOnly), + StatusCode.ClientTransportTimeout => new RetryRule(FastBackoff, true, RetryPolicy.IdempotentOnly), + StatusCode.ClientTransportResourceExhausted => new RetryRule(SlowBackoff, true, RetryPolicy.Unconditional), + StatusCode.ClientTransportUnimplemented => new RetryRule(NoBackoff, true, RetryPolicy.None), + _ => throw new ArgumentOutOfRangeException(nameof(statusCode), statusCode, null) + }; } diff --git a/src/Ydb.Sdk/src/Services/Query/QueryClient.cs b/src/Ydb.Sdk/src/Services/Query/QueryClient.cs index c6109daf..142884a3 100644 --- a/src/Ydb.Sdk/src/Services/Query/QueryClient.cs +++ b/src/Ydb.Sdk/src/Services/Query/QueryClient.cs @@ -35,29 +35,24 @@ public QueryClient(Driver driver, QueryClientConfig? config = null) public Task Stream(string query, Func> onStream, Dictionary? parameters = null, TxMode txMode = TxMode.NoTx, - ExecuteQuerySettings? settings = null) - { - return _sessionPool.ExecOnSession(async session => await onStream(new ExecuteQueryStream( + ExecuteQuerySettings? settings = null) => + _sessionPool.ExecOnSession(async session => await onStream(new ExecuteQueryStream( await session.ExecuteQuery(query, parameters, settings, txMode.TransactionControl()))) ); - } public Task Stream(string query, Func onStream, Dictionary? parameters = null, TxMode txMode = TxMode.NoTx, - ExecuteQuerySettings? settings = null) - { - return Stream(query, async stream => + ExecuteQuerySettings? settings = null) => + Stream(query, async stream => { await onStream(stream); return None; }, parameters, txMode, settings); - } public Task> ReadAllRows(string query, Dictionary? parameters = null, TxMode txMode = TxMode.NoTx, - ExecuteQuerySettings? settings = null) - { - return Stream>(query, async stream => + ExecuteQuerySettings? settings = null) => + Stream>(query, async stream => { await using var uStream = stream; List rows = new(); @@ -74,7 +69,6 @@ public Task Stream(string query, Func onStream, return rows.AsReadOnly(); }, parameters, txMode, settings); - } public async Task ReadRow(string query, Dictionary? parameters = null, TxMode txMode = TxMode.NoTx, @@ -86,15 +80,13 @@ public Task Stream(string query, Func onStream, } public async Task Exec(string query, Dictionary? parameters = null, - TxMode txMode = TxMode.NoTx, ExecuteQuerySettings? settings = null) - { + TxMode txMode = TxMode.NoTx, ExecuteQuerySettings? settings = null) => await Stream(query, async stream => { await using var uStream = stream; _ = await stream.MoveNextAsync(); }, parameters, txMode, settings); - } public Task DoTx(Func> queryTx, TxMode txMode = TxMode.SerializableRw) { @@ -137,15 +129,13 @@ public Task DoTx(Func> queryTx, TxMode txMode = TxMode.Se private static readonly object None = new(); - public async Task DoTx(Func queryTx, TxMode txMode = TxMode.SerializableRw) - { + public async Task DoTx(Func queryTx, TxMode txMode = TxMode.SerializableRw) => await DoTx(async tx => { await queryTx(tx); return None; }, txMode); - } public ValueTask DisposeAsync() { diff --git a/src/Ydb.Sdk/src/Services/Query/QueryTx.cs b/src/Ydb.Sdk/src/Services/Query/QueryTx.cs index 962ec16a..ddb9b320 100644 --- a/src/Ydb.Sdk/src/Services/Query/QueryTx.cs +++ b/src/Ydb.Sdk/src/Services/Query/QueryTx.cs @@ -28,12 +28,10 @@ internal QueryTx(Session session, TxMode txMode) } public async ValueTask Stream(string query, Dictionary? parameters = null, - bool commit = false, ExecuteQuerySettings? settings = null) - { - return new ExecuteQueryStream( + bool commit = false, ExecuteQuerySettings? settings = null) => + new( await _session.ExecuteQuery(query, parameters, settings, TxControl(commit)), txId => TxId = txId ); - } public async Task> ReadAllRows(string query, Dictionary? parameters = null, bool commit = false, ExecuteQuerySettings? settings = null) diff --git a/src/Ydb.Sdk/src/Services/Query/SessionPool.cs b/src/Ydb.Sdk/src/Services/Query/SessionPool.cs index a04a8d14..a2157885 100644 --- a/src/Ydb.Sdk/src/Services/Query/SessionPool.cs +++ b/src/Ydb.Sdk/src/Services/Query/SessionPool.cs @@ -115,10 +115,7 @@ protected override async Task CreateSession() return session; } - protected override ValueTask DisposeDriver() - { - return _disposingDriver ? _driver.DisposeAsync() : default; - } + protected override ValueTask DisposeDriver() => _disposingDriver ? _driver.DisposeAsync() : default; } internal class Session : SessionBase diff --git a/src/Ydb.Sdk/src/Services/Query/Settings.cs b/src/Ydb.Sdk/src/Services/Query/Settings.cs index 70beb138..8d94ab68 100644 --- a/src/Ydb.Sdk/src/Services/Query/Settings.cs +++ b/src/Ydb.Sdk/src/Services/Query/Settings.cs @@ -53,9 +53,8 @@ internal static class TxModeExtensions private static readonly TransactionSettings OnlineInconsistentRo = new() { OnlineReadOnly = new OnlineModeSettings { AllowInconsistentReads = true } }; - internal static TransactionSettings? TransactionSettings(this TxMode mode) - { - return mode switch + internal static TransactionSettings? TransactionSettings(this TxMode mode) => + mode switch { TxMode.SerializableRw => SerializableRw, TxMode.SnapshotRo => SnapshotRo, @@ -64,16 +63,13 @@ internal static class TxModeExtensions TxMode.OnlineInconsistentRo => OnlineInconsistentRo, _ => null }; - } - internal static TransactionControl? TransactionControl(this TxMode mode, bool commit = true) - { - return mode switch + internal static TransactionControl? TransactionControl(this TxMode mode, bool commit = true) => + mode switch { TxMode.NoTx => null, _ => new TransactionControl { BeginTx = mode.TransactionSettings(), CommitTx = commit } }; - } } public class ExecuteQueryPart @@ -99,10 +95,7 @@ internal ExecuteQueryStream(IAsyncEnumerator stream, A _onTxId = onTx ?? (_ => { }); } - public ValueTask DisposeAsync() - { - return _stream.DisposeAsync(); - } + public ValueTask DisposeAsync() => _stream.DisposeAsync(); public async ValueTask MoveNextAsync() { @@ -122,8 +115,5 @@ public async ValueTask MoveNextAsync() public ExecuteQueryPart Current => new(_stream.Current); - public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = new()) - { - return this; - } + public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = new()) => this; } diff --git a/src/Ydb.Sdk/src/Services/Scheme/SchemeClient.cs b/src/Ydb.Sdk/src/Services/Scheme/SchemeClient.cs index e8757b61..1c2c4f71 100644 --- a/src/Ydb.Sdk/src/Services/Scheme/SchemeClient.cs +++ b/src/Ydb.Sdk/src/Services/Scheme/SchemeClient.cs @@ -32,12 +32,8 @@ public Permissions(string subject, IReadOnlyList permissionNames) public string Subject { get; } public IReadOnlyList PermissionNames { get; } - internal static Permissions FromProto(Ydb.Scheme.Permissions permissionsProto) - { - return new Permissions( - subject: permissionsProto.Subject, - permissionNames: permissionsProto.PermissionNames); - } + internal static Permissions FromProto(Ydb.Scheme.Permissions permissionsProto) => + new(subject: permissionsProto.Subject, permissionNames: permissionsProto.PermissionNames); } public class SchemeEntry diff --git a/src/Ydb.Sdk/src/Services/Sessions/SessionPoolBase.cs b/src/Ydb.Sdk/src/Services/Sessions/SessionPoolBase.cs index 6b93fbe1..571cd938 100644 --- a/src/Ydb.Sdk/src/Services/Sessions/SessionPoolBase.cs +++ b/src/Ydb.Sdk/src/Services/Sessions/SessionPoolBase.cs @@ -24,10 +24,7 @@ internal GetSessionResponse(Status status, TSession? session = null) : base(stat { } - public void Dispose() - { - Dispose(true); - } + public void Dispose() => Dispose(true); protected void Dispose(bool disposing) { @@ -45,10 +42,8 @@ internal interface ISessionPool : IDisposable where TSession : Session internal class NoPool : ISessionPool where TSession : SessionBase { - public Task> GetSession() - { + public Task> GetSession() => throw new InvalidOperationException("Unexpected session pool access."); - } public void Dispose() { @@ -158,10 +153,7 @@ internal void InvalidateSession(string id) } } - public void Dispose() - { - Dispose(true); - } + public void Dispose() => Dispose(true); private void Dispose(bool disposing) { diff --git a/src/Ydb.Sdk/src/Services/Table/AlterTable.cs b/src/Ydb.Sdk/src/Services/Table/AlterTable.cs index 19a3bb6d..c5d28e54 100644 --- a/src/Ydb.Sdk/src/Services/Table/AlterTable.cs +++ b/src/Ydb.Sdk/src/Services/Table/AlterTable.cs @@ -8,10 +8,7 @@ namespace Ydb.Sdk.Services.Table; public class IndexBuildMetadata { - internal static IndexBuildMetadata FromProto(Ydb.Table.IndexBuildMetadata metaProto) - { - return new IndexBuildMetadata(); - } + internal static IndexBuildMetadata FromProto(Ydb.Table.IndexBuildMetadata metaProto) => new(); } public class AlterTableMetadata @@ -27,12 +24,10 @@ private AlterTableMetadata() public IndexBuildMetadata? IndexBuild { get; } - internal static AlterTableMetadata FromProto(Any metaProto) - { - return metaProto.Is(Ydb.Table.IndexBuildMetadata.Descriptor) + internal static AlterTableMetadata FromProto(Any metaProto) => + metaProto.Is(Ydb.Table.IndexBuildMetadata.Descriptor) ? new AlterTableMetadata(metaProto.Unpack()) : new AlterTableMetadata(); - } } public sealed class AlterTableOperation : OperationResponse @@ -50,27 +45,17 @@ internal AlterTableOperation(OperationsClient operationsClient, Status status) { } - protected override EmptyResult UnpackResult(ClientOperation operation) - { - return new EmptyResult(); - } + protected override EmptyResult UnpackResult(ClientOperation operation) => new(); - protected override AlterTableMetadata UnpackMetadata(ClientOperation operation) - { - return AlterTableMetadata.FromProto(operation.Metadata); - } + protected override AlterTableMetadata UnpackMetadata(ClientOperation operation) => + AlterTableMetadata.FromProto(operation.Metadata); - public async Task Poll() - { - return new AlterTableOperation(_operationsClient, await _operationsClient.GetOperation(Id)); - } + public async Task Poll() => new(_operationsClient, await _operationsClient.GetOperation(Id)); public async Task PollReady(TimeSpan? delay = default, - CancellationToken cancellationToken = default) - { - return new AlterTableOperation(_operationsClient, + CancellationToken cancellationToken = default) => + new(_operationsClient, await _operationsClient.PollReady(Id, delay, cancellationToken)); - } } public class AddIndexSettings : OperationSettings diff --git a/src/Ydb.Sdk/src/Services/Table/CopyTable.cs b/src/Ydb.Sdk/src/Services/Table/CopyTable.cs index 13f87c94..b06d1583 100644 --- a/src/Ydb.Sdk/src/Services/Table/CopyTable.cs +++ b/src/Ydb.Sdk/src/Services/Table/CopyTable.cs @@ -18,15 +18,13 @@ public CopyTableItem(string sourcePath, string destinationPath, bool omitIndexes OmitIndexes = omitIndexes; } - public Ydb.Table.CopyTableItem GetProto(TableClient tableClient) - { - return new Ydb.Table.CopyTableItem + public Ydb.Table.CopyTableItem GetProto(TableClient tableClient) => + new() { SourcePath = tableClient.MakeTablePath(SourcePath), DestinationPath = tableClient.MakeTablePath(DestinationPath), OmitIndexes = OmitIndexes }; - } } public class CopyTableSettings : OperationSettings diff --git a/src/Ydb.Sdk/src/Services/Table/DescribeTable.cs b/src/Ydb.Sdk/src/Services/Table/DescribeTable.cs index 00cb9489..da8d5211 100644 --- a/src/Ydb.Sdk/src/Services/Table/DescribeTable.cs +++ b/src/Ydb.Sdk/src/Services/Table/DescribeTable.cs @@ -23,27 +23,23 @@ public enum IndexType internal static class TableEnumConverter { - internal static FeatureFlagStatus FromProto(this FeatureFlag.Types.Status proto) - { - return proto switch + internal static FeatureFlagStatus FromProto(this FeatureFlag.Types.Status proto) => + proto switch { FeatureFlag.Types.Status.Unspecified => FeatureFlagStatus.Unspecified, FeatureFlag.Types.Status.Enabled => FeatureFlagStatus.Enabled, FeatureFlag.Types.Status.Disabled => FeatureFlagStatus.Disabled, _ => throw new ArgumentOutOfRangeException() }; - } - internal static FeatureFlag.Types.Status GetProto(this FeatureFlagStatus status) - { - return status switch + internal static FeatureFlag.Types.Status GetProto(this FeatureFlagStatus status) => + status switch { FeatureFlagStatus.Unspecified => FeatureFlag.Types.Status.Unspecified, FeatureFlagStatus.Enabled => FeatureFlag.Types.Status.Enabled, FeatureFlagStatus.Disabled => FeatureFlag.Types.Status.Disabled, _ => throw new ArgumentOutOfRangeException(nameof(status), status, null) }; - } } public class PartitionStats @@ -100,14 +96,12 @@ public DateTypeColumnModeSettings(Ydb.Table.DateTypeColumnModeSettings proto) ExpireAfterSeconds = proto.ExpireAfterSeconds; } - public Ydb.Table.DateTypeColumnModeSettings GetProto() - { - return new Ydb.Table.DateTypeColumnModeSettings + public Ydb.Table.DateTypeColumnModeSettings GetProto() => + new() { ColumnName = ColumnName, ExpireAfterSeconds = ExpireAfterSeconds }; - } } public class ValueSinceUnixEpochModeSettings @@ -147,19 +141,16 @@ public ValueSinceUnixEpochModeSettings(Ydb.Table.ValueSinceUnixEpochModeSettings ExpireAfterSeconds = proto.ExpireAfterSeconds; } - public Ydb.Table.ValueSinceUnixEpochModeSettings GetProto() - { - return new Ydb.Table.ValueSinceUnixEpochModeSettings + public Ydb.Table.ValueSinceUnixEpochModeSettings GetProto() => + new() { ColumnName = ColumnName, ColumnUnit = GetProtoUnit(ColumnUnit), ExpireAfterSeconds = ExpireAfterSeconds }; - } - private static Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit GetProtoUnit(Unit unit) - { - return unit switch + private static Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit GetProtoUnit(Unit unit) => + unit switch { Unit.Unspecified => Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit.Unspecified, Unit.Seconds => Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit.Seconds, @@ -168,7 +159,6 @@ private static Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit GetProtoUnit Unit.Nanoseconds => Ydb.Table.ValueSinceUnixEpochModeSettings.Types.Unit.Nanoseconds, _ => throw new ArgumentOutOfRangeException(nameof(unit), unit, null) }; - } } public class TtlSettingsMode @@ -304,10 +294,7 @@ public StoragePool(Ydb.Table.StoragePool? proto) Media = proto?.Media; } - public Ydb.Table.StoragePool GetProto() - { - return new Ydb.Table.StoragePool { Media = Media }; - } + public Ydb.Table.StoragePool GetProto() => new() { Media = Media }; } public class StorageSettings @@ -334,16 +321,14 @@ public StorageSettings(Ydb.Table.StorageSettings proto) StoreExternalBlobs = proto.StoreExternalBlobs.FromProto(); } - public Ydb.Table.StorageSettings GetProto() - { - return new Ydb.Table.StorageSettings + public Ydb.Table.StorageSettings GetProto() => + new() { TabletCommitLog0 = TabletCommitLog0.GetProto(), TabletCommitLog1 = TabletCommitLog1.GetProto(), External = External.GetProto(), StoreExternalBlobs = StoreExternalBlobs.GetProto() }; - } } public class PartitioningSettings @@ -376,18 +361,15 @@ public PartitioningSettings(Ydb.Table.PartitioningSettings proto) MaxPartitionsCount = proto.MaxPartitionsCount; } - public Ydb.Table.PartitioningSettings GetProto() + public Ydb.Table.PartitioningSettings GetProto() => new() { - return new Ydb.Table.PartitioningSettings - { - PartitionBy = { PartitionBy }, - PartitioningBySize = PartitioningBySize.GetProto(), - PartitionSizeMb = PartitionSizeMb, - PartitioningByLoad = PartitioningByLoad.GetProto(), - MinPartitionsCount = MinPartitionsCount, - MaxPartitionsCount = MaxPartitionsCount - }; - } + PartitionBy = { PartitionBy }, + PartitioningBySize = PartitioningBySize.GetProto(), + PartitionSizeMb = PartitionSizeMb, + PartitioningByLoad = PartitioningByLoad.GetProto(), + MinPartitionsCount = MinPartitionsCount, + MaxPartitionsCount = MaxPartitionsCount + }; } public class ReadReplicasSettings @@ -402,7 +384,6 @@ public enum SettingsType public SettingsType Type { get; } public ulong Settings { get; } - public ReadReplicasSettings(SettingsType type, ulong settings) { Type = type; @@ -435,18 +416,15 @@ public ReadReplicasSettings(Ydb.Table.ReadReplicasSettings? proto) } } - public Ydb.Table.ReadReplicasSettings GetProto() + public Ydb.Table.ReadReplicasSettings GetProto() => Type switch { - return Type switch - { - SettingsType.None => new Ydb.Table.ReadReplicasSettings(), - SettingsType.PerAzReadReplicasCount => new Ydb.Table.ReadReplicasSettings - { PerAzReadReplicasCount = Settings }, - SettingsType.AnyAzReadReplicasCount => new Ydb.Table.ReadReplicasSettings - { AnyAzReadReplicasCount = Settings }, - _ => throw new ArgumentOutOfRangeException() - }; - } + SettingsType.None => new Ydb.Table.ReadReplicasSettings(), + SettingsType.PerAzReadReplicasCount => new Ydb.Table.ReadReplicasSettings + { PerAzReadReplicasCount = Settings }, + SettingsType.AnyAzReadReplicasCount => new Ydb.Table.ReadReplicasSettings + { AnyAzReadReplicasCount = Settings }, + _ => throw new ArgumentOutOfRangeException() + }; } public class DescribeTableSettings : OperationSettings @@ -518,9 +496,8 @@ public ResultData(Entry self, IReadOnlyList columns, IReadOnlyList + new( self: resultProto.Self, columns: resultProto.Columns.Select(proto => new ColumnMeta(proto)).ToList(), primaryKey: resultProto.PrimaryKey.ToList(), @@ -536,7 +513,6 @@ internal static ResultData FromProto(DescribeTableResult resultProto) keyBloomFilter: resultProto.KeyBloomFilter.FromProto(), readReplicasSettings: new ReadReplicasSettings(resultProto.ReadReplicasSettings) ); - } } } diff --git a/src/Ydb.Sdk/src/Services/Table/ExecuteDataQuery.cs b/src/Ydb.Sdk/src/Services/Table/ExecuteDataQuery.cs index be766576..b775b4dd 100644 --- a/src/Ydb.Sdk/src/Services/Table/ExecuteDataQuery.cs +++ b/src/Ydb.Sdk/src/Services/Table/ExecuteDataQuery.cs @@ -122,10 +122,8 @@ public async Task ExecuteDataQuery( public async Task ExecuteDataQuery( string query, TxControl txControl, - ExecuteDataQuerySettings? settings = null) - { - return await ExecuteDataQuery(query, txControl, new Dictionary(), settings); - } + ExecuteDataQuerySettings? settings = null + ) => await ExecuteDataQuery(query, txControl, new Dictionary(), settings); } public class TruncateException : Exception diff --git a/src/Ydb.Sdk/src/Services/Table/ExecuteScanQuery.cs b/src/Ydb.Sdk/src/Services/Table/ExecuteScanQuery.cs index eaf07294..a9ce437a 100644 --- a/src/Ydb.Sdk/src/Services/Table/ExecuteScanQuery.cs +++ b/src/Ydb.Sdk/src/Services/Table/ExecuteScanQuery.cs @@ -18,17 +18,15 @@ internal ExecuteScanQueryPart(Status status, ResultData? result = null) public class ResultData { - internal ResultData(Value.ResultSet? resultSetPart) + private ResultData(Value.ResultSet? resultSetPart) { ResultSetPart = resultSetPart; } public Value.ResultSet? ResultSetPart { get; } - internal static ResultData FromProto(ExecuteScanQueryPartialResult resultProto) - { - return new ResultData(resultProto.ResultSet?.FromProto()); - } + internal static ResultData FromProto(ExecuteScanQueryPartialResult resultProto) => + new(resultProto.ResultSet?.FromProto()); } } @@ -39,10 +37,7 @@ internal ExecuteScanQueryStream(ServerStream it { } - protected override ExecuteScanQueryPart MakeResponse(Status status) - { - return new ExecuteScanQueryPart(status); - } + protected override ExecuteScanQueryPart MakeResponse(Status status) => new(status); protected override ExecuteScanQueryPart MakeResponse(ExecuteScanQueryPartialResponse protoResponse) { @@ -86,8 +81,6 @@ public async ValueTask ExecuteScanQuery( public ValueTask ExecuteScanQuery( string query, - ExecuteScanQuerySettings? settings = null) - { - return ExecuteScanQuery(query, new Dictionary(), settings); - } + ExecuteScanQuerySettings? settings = null) => + ExecuteScanQuery(query, new Dictionary(), settings); } diff --git a/src/Ydb.Sdk/src/Services/Table/KeepAlive.cs b/src/Ydb.Sdk/src/Services/Table/KeepAlive.cs index 957befec..a760feaa 100644 --- a/src/Ydb.Sdk/src/Services/Table/KeepAlive.cs +++ b/src/Ydb.Sdk/src/Services/Table/KeepAlive.cs @@ -31,12 +31,10 @@ private ResultData(SessionStatus sessionStatus) public SessionStatus SessionStatus { get; } - internal static ResultData FromProto(KeepAliveResult resultProto) - { - return new ResultData( + internal static ResultData FromProto(KeepAliveResult resultProto) => + new( sessionStatus: SessionStatusFromProto(resultProto.SessionStatus) ); - } } private static SessionStatus SessionStatusFromProto(KeepAliveResult.Types.SessionStatus proto) diff --git a/src/Ydb.Sdk/src/Services/Table/ReadTable.cs b/src/Ydb.Sdk/src/Services/Table/ReadTable.cs index 155e6189..39a58f29 100644 --- a/src/Ydb.Sdk/src/Services/Table/ReadTable.cs +++ b/src/Ydb.Sdk/src/Services/Table/ReadTable.cs @@ -30,10 +30,7 @@ internal ResultData(Value.ResultSet resultSet) public Value.ResultSet ResultSet { get; } - internal static ResultData FromProto(ReadTableResult resultProto) - { - return new ResultData(resultProto.ResultSet.FromProto()); - } + internal static ResultData FromProto(ReadTableResult resultProto) => new(resultProto.ResultSet.FromProto()); } } @@ -44,10 +41,7 @@ internal ReadTableStream(ServerStream iterator) { } - protected override ReadTablePart MakeResponse(Status status) - { - return new ReadTablePart(status); - } + protected override ReadTablePart MakeResponse(Status status) => new(status); protected override ReadTablePart MakeResponse(ReadTableResponse protoResponse) { diff --git a/src/Ydb.Sdk/src/Services/Table/RenameTables.cs b/src/Ydb.Sdk/src/Services/Table/RenameTables.cs index 966c16e2..5a074666 100644 --- a/src/Ydb.Sdk/src/Services/Table/RenameTables.cs +++ b/src/Ydb.Sdk/src/Services/Table/RenameTables.cs @@ -18,15 +18,13 @@ public RenameTableItem(string sourcePath, string destinationPath, bool replaceDe ReplaceDestination = replaceDestination; } - public Ydb.Table.RenameTableItem GetProto(TableClient tableClient) - { - return new Ydb.Table.RenameTableItem + public Ydb.Table.RenameTableItem GetProto(TableClient tableClient) => + new() { SourcePath = tableClient.MakeTablePath(SourcePath), DestinationPath = tableClient.MakeTablePath(DestinationPath), ReplaceDestination = ReplaceDestination }; - } } public class RenameTablesSettings : OperationSettings diff --git a/src/Ydb.Sdk/src/Services/Table/SessionPool.cs b/src/Ydb.Sdk/src/Services/Table/SessionPool.cs index 9d1f921b..ff9129a0 100644 --- a/src/Ydb.Sdk/src/Services/Table/SessionPool.cs +++ b/src/Ydb.Sdk/src/Services/Table/SessionPool.cs @@ -54,14 +54,12 @@ private protected override async Task CreateSession() return new GetSessionResponse(createSessionResponse.Status); } - private protected override Session CopySession(Session other) - { - return new Session( - driver: Driver, - sessionPool: this, - id: other.Id, - nodeId: other.NodeId); - } + private protected override Session CopySession(Session other) => new( + driver: Driver, + sessionPool: this, + id: other.Id, + nodeId: other.NodeId + ); private async Task PeriodicCheck() { @@ -143,11 +141,9 @@ private async Task CheckSessions() } } - private protected override async Task DeleteSession(string id) - { + private protected override async Task DeleteSession(string id) => await _tableClient.DeleteSession(id, new DeleteSessionSettings { TransportTimeout = SessionBase.DeleteSessionTimeout }); - } } diff --git a/src/Ydb.Sdk/src/Services/Table/TableClient.cs b/src/Ydb.Sdk/src/Services/Table/TableClient.cs index a6e6b3b0..7b7b5198 100644 --- a/src/Ydb.Sdk/src/Services/Table/TableClient.cs +++ b/src/Ydb.Sdk/src/Services/Table/TableClient.cs @@ -55,8 +55,5 @@ private void Dispose(bool disposing) _disposed = true; } - internal string MakeTablePath(string path) - { - return path.StartsWith('/') ? path : $"{_driver.Database}/{path}"; - } + internal string MakeTablePath(string path) => path.StartsWith('/') ? path : $"{_driver.Database}/{path}"; } diff --git a/src/Ydb.Sdk/src/Services/Table/Transaction.cs b/src/Ydb.Sdk/src/Services/Table/Transaction.cs index f04c4390..19a38320 100644 --- a/src/Ydb.Sdk/src/Services/Table/Transaction.cs +++ b/src/Ydb.Sdk/src/Services/Table/Transaction.cs @@ -7,7 +7,7 @@ public class Transaction { private static int _txCounter; - internal Transaction(string txId) + private Transaction(string txId) { TxId = txId; } @@ -34,10 +34,7 @@ internal Transaction(string txId) return tx; } - private static int IncTxCounter() - { - return Interlocked.Increment(ref _txCounter); - } + private static int IncTxCounter() => Interlocked.Increment(ref _txCounter); } public enum TransactionState @@ -59,20 +56,17 @@ private TxControl(TransactionControl proto, int? txNum = null) _txNum = txNum; } - public static TxControl BeginSerializableRW() - { - return new TxControl(new TransactionControl + public static TxControl BeginSerializableRW() => + new(new TransactionControl { BeginTx = new TransactionSettings { SerializableReadWrite = new SerializableModeSettings() } }); - } - public static TxControl BeginOnlineRO(bool allowInconsistentReads = false) - { - return new TxControl(new TransactionControl + public static TxControl BeginOnlineRO(bool allowInconsistentReads = false) => + new(new TransactionControl { BeginTx = new TransactionSettings { @@ -82,26 +76,21 @@ public static TxControl BeginOnlineRO(bool allowInconsistentReads = false) } } }); - } - public static TxControl BeginStaleRO() - { - return new TxControl(new TransactionControl + public static TxControl BeginStaleRO() => + new(new TransactionControl { BeginTx = new TransactionSettings { StaleReadOnly = new StaleModeSettings() } }); - } - public static TxControl Tx(Transaction tx) - { - return new TxControl(new TransactionControl + public static TxControl Tx(Transaction tx) => + new(new TransactionControl { TxId = tx.TxId }, tx.TxNum); - } public TxControl Commit() { diff --git a/src/Ydb.Sdk/src/Services/Topic/Deserializer.cs b/src/Ydb.Sdk/src/Services/Topic/Deserializer.cs index 5d4b3515..dd1ef324 100644 --- a/src/Ydb.Sdk/src/Services/Topic/Deserializer.cs +++ b/src/Ydb.Sdk/src/Services/Topic/Deserializer.cs @@ -15,17 +15,17 @@ public static class Deserializers /// /// String (UTF8 encoded) deserializer. /// - public static IDeserializer Utf8 = new Utf8Deserializer(); + public static readonly IDeserializer Utf8 = new Utf8Deserializer(); /// /// System.Int64 (big endian encoded, network byte ordered) deserializer. /// - public static IDeserializer Int64 = new Int64Deserializer(); + public static readonly IDeserializer Int64 = new Int64Deserializer(); /// /// System.Int32 (big endian encoded, network byte ordered) deserializer. /// - public static IDeserializer Int32 = new Int32Deserializer(); + public static readonly IDeserializer Int32 = new Int32Deserializer(); /// /// System.Byte[] deserializer. @@ -33,7 +33,7 @@ public static class Deserializers /// /// Byte ordering is original order. /// - public static IDeserializer ByteArray = new ByteArrayDeserializer(); + public static readonly IDeserializer ByteArray = new ByteArrayDeserializer(); internal static readonly Dictionary DefaultDeserializers = new() { @@ -45,33 +45,21 @@ public static class Deserializers private class Utf8Deserializer : IDeserializer { - public string Deserialize(byte[] data) - { - return Encoding.UTF8.GetString(data); - } + public string Deserialize(byte[] data) => Encoding.UTF8.GetString(data); } private class Int64Deserializer : IDeserializer { - public long Deserialize(byte[] data) - { - return BitConverter.ToInt64(data); - } + public long Deserialize(byte[] data) => BitConverter.ToInt64(data); } private class Int32Deserializer : IDeserializer { - public int Deserialize(byte[] data) - { - return BitConverter.ToInt32(data); - } + public int Deserialize(byte[] data) => BitConverter.ToInt32(data); } private class ByteArrayDeserializer : IDeserializer { - public byte[] Deserialize(byte[] data) - { - return data; - } + public byte[] Deserialize(byte[] data) => data; } } diff --git a/src/Ydb.Sdk/src/Services/Topic/Reader/Message.cs b/src/Ydb.Sdk/src/Services/Topic/Reader/Message.cs index f01940db..e8e0bab7 100644 --- a/src/Ydb.Sdk/src/Services/Topic/Reader/Message.cs +++ b/src/Ydb.Sdk/src/Services/Topic/Reader/Message.cs @@ -51,10 +51,7 @@ internal Message( public long SeqNo { get; } - public Task CommitAsync() - { - return _readerSession.CommitOffsetRange(_offsetsRange, _partitionSessionId); - } + public Task CommitAsync() => _readerSession.CommitOffsetRange(_offsetsRange, _partitionSessionId); } public class BatchMessages @@ -81,10 +78,7 @@ internal BatchMessages( ProducerId = producerId; } - public Task CommitBatchAsync() - { - return Batch.Count == 0 - ? Task.CompletedTask - : _readerSession.CommitOffsetRange(_offsetsRange, _partitionSessionId); - } + public Task CommitBatchAsync() => Batch.Count == 0 + ? Task.CompletedTask + : _readerSession.CommitOffsetRange(_offsetsRange, _partitionSessionId); } diff --git a/src/Ydb.Sdk/src/Services/Topic/Reader/Reader.cs b/src/Ydb.Sdk/src/Services/Topic/Reader/Reader.cs index 74769cac..07d419c5 100644 --- a/src/Ydb.Sdk/src/Services/Topic/Reader/Reader.cs +++ b/src/Ydb.Sdk/src/Services/Topic/Reader/Reader.cs @@ -560,16 +560,14 @@ await _channelWriter.WriteAsync( } } - protected override MessageFromClient GetSendUpdateTokenRequest(string token) - { - return new MessageFromClient + protected override MessageFromClient GetSendUpdateTokenRequest(string token) => + new() { UpdateTokenRequest = new UpdateTokenRequest { Token = token } }; - } public override async ValueTask DisposeAsync() { diff --git a/src/Ydb.Sdk/src/Services/Topic/Reader/Utils.cs b/src/Ydb.Sdk/src/Services/Topic/Reader/Utils.cs index f0cb6a47..60e3454f 100644 --- a/src/Ydb.Sdk/src/Services/Topic/Reader/Utils.cs +++ b/src/Ydb.Sdk/src/Services/Topic/Reader/Utils.cs @@ -2,14 +2,11 @@ namespace Ydb.Sdk.Services.Topic.Reader; internal static class Utils { - internal static long CalculateApproximatelyBytesSize(long bytesSize, int countParts, int currentIndex) - { - return bytesSize / countParts + (currentIndex == countParts - 1 ? bytesSize % countParts : 0); - } + internal static long CalculateApproximatelyBytesSize(long bytesSize, int countParts, int currentIndex) => + bytesSize / countParts + (currentIndex == countParts - 1 ? bytesSize % countParts : 0); - internal static void SetPartitionClosedException(CommitSending commitSending, long partitionSessionId) - { + internal static void SetPartitionClosedException(CommitSending commitSending, long partitionSessionId) => commitSending.TcsCommit.TrySetException( - new ReaderException($"PartitionSession[{partitionSessionId}] was closed by server.")); - } + new ReaderException($"PartitionSession[{partitionSessionId}] was closed by server.") + ); } diff --git a/src/Ydb.Sdk/src/Services/Topic/Serializer.cs b/src/Ydb.Sdk/src/Services/Topic/Serializer.cs index 184f911b..ad9d7650 100644 --- a/src/Ydb.Sdk/src/Services/Topic/Serializer.cs +++ b/src/Ydb.Sdk/src/Services/Topic/Serializer.cs @@ -39,33 +39,21 @@ public static class Serializers private class Utf8Serializer : ISerializer { - public byte[] Serialize(string data) - { - return Encoding.UTF8.GetBytes(data); - } + public byte[] Serialize(string data) => Encoding.UTF8.GetBytes(data); } private class Int64Serializer : ISerializer { - public byte[] Serialize(long data) - { - return BitConverter.GetBytes(data); - } + public byte[] Serialize(long data) => BitConverter.GetBytes(data); } private class Int32Serializer : ISerializer { - public byte[] Serialize(int data) - { - return BitConverter.GetBytes(data); - } + public byte[] Serialize(int data) => BitConverter.GetBytes(data); } private class ByteArraySerializer : ISerializer { - public byte[] Serialize(byte[] data) - { - return data; - } + public byte[] Serialize(byte[] data) => data; } } diff --git a/src/Ydb.Sdk/src/Services/Topic/Writer/Writer.cs b/src/Ydb.Sdk/src/Services/Topic/Writer/Writer.cs index 78889dad..c37486c8 100644 --- a/src/Ydb.Sdk/src/Services/Topic/Writer/Writer.cs +++ b/src/Ydb.Sdk/src/Services/Topic/Writer/Writer.cs @@ -44,10 +44,8 @@ internal Writer(IDriver driver, WriterConfig config, ISerializer seriali StartWriteWorker(); } - public Task WriteAsync(TValue data, CancellationToken cancellationToken) - { - return WriteAsync(new Message(data), cancellationToken); - } + public Task WriteAsync(TValue data, CancellationToken cancellationToken) => + WriteAsync(new Message(data), cancellationToken); public async Task WriteAsync(Message message, CancellationToken cancellationToken) { @@ -182,10 +180,7 @@ private async void StartWriteWorker() } } - private void WakeUpWorker() - { - _tcsWakeUp.TrySetResult(); - } + private void WakeUpWorker() => _tcsWakeUp.TrySetResult(); private async Task Initialize() { @@ -412,10 +407,7 @@ public Task Write(ConcurrentQueue toSendBuffer) public bool IsActive => true; - public ValueTask DisposeAsync() - { - return ValueTask.CompletedTask; - } + public ValueTask DisposeAsync() => ValueTask.CompletedTask; } internal class DummyWriterSession : IWriteSession @@ -426,17 +418,11 @@ private DummyWriterSession() { } - public Task Write(ConcurrentQueue toSendBuffer) - { - return Task.CompletedTask; - } + public Task Write(ConcurrentQueue toSendBuffer) => Task.CompletedTask; public bool IsActive => false; - public ValueTask DisposeAsync() - { - return ValueTask.CompletedTask; - } + public ValueTask DisposeAsync() => ValueTask.CompletedTask; } internal class WriterSession : TopicSession, IWriteSession @@ -588,16 +574,14 @@ Completing task on exception... } } - protected override MessageFromClient GetSendUpdateTokenRequest(string token) - { - return new MessageFromClient + protected override MessageFromClient GetSendUpdateTokenRequest(string token) => + new() { UpdateTokenRequest = new UpdateTokenRequest { Token = token } }; - } public override async ValueTask DisposeAsync() { diff --git a/src/Ydb.Sdk/src/Status.cs b/src/Ydb.Sdk/src/Status.cs index 6cd45cb1..4d9ba932 100644 --- a/src/Ydb.Sdk/src/Status.cs +++ b/src/Ydb.Sdk/src/Status.cs @@ -120,10 +120,7 @@ public Issue(string message) Message = message; } - public override string ToString() - { - return ToString(0, 4); - } + public override string ToString() => ToString(0, 4); private string ToString(int currentIndent, int indent) { @@ -142,10 +139,7 @@ private string ToString(int currentIndent, int indent) return sb.ToString(); } - internal static string IssuesToString(IReadOnlyList issues) - { - return IssuesToString(issues, 0, 4); - } + internal static string IssuesToString(IReadOnlyList issues) => IssuesToString(issues, 0, 4); private static string IssuesToString(IReadOnlyList issues, int currentIndent, int indent) { @@ -221,10 +215,8 @@ private static StatusCode ConvertStatusCode(StatusIds.Types.StatusCode statusCod return StatusCode.Unspecified; } - public static Status FromProto(StatusIds.Types.StatusCode statusCode, RepeatedField issues) - { - return new Status(ConvertStatusCode(statusCode), issues.Select(i => new Issue(i)).ToList()); - } + public static Status FromProto(StatusIds.Types.StatusCode statusCode, RepeatedField issues) => + new(ConvertStatusCode(statusCode), issues.Select(i => new Issue(i)).ToList()); } public class StatusUnsuccessfulException : Exception @@ -239,9 +231,8 @@ public StatusUnsuccessfulException(Status status) : base(status.ToString()) internal static class StatusExtensions { - internal static Status ConvertStatus(this Grpc.Core.Status rpcStatus) - { - return new Status( + internal static Status ConvertStatus(this Grpc.Core.Status rpcStatus) => + new( rpcStatus.StatusCode switch { Grpc.Core.StatusCode.Unavailable => StatusCode.ClientTransportUnavailable, @@ -253,5 +244,4 @@ internal static Status ConvertStatus(this Grpc.Core.Status rpcStatus) }, new List { new(rpcStatus.Detail) } ); - } } diff --git a/src/Ydb.Sdk/src/Transport/AuthGrpcChannelDriver.cs b/src/Ydb.Sdk/src/Transport/AuthGrpcChannelDriver.cs index bdb95e2f..135b3b3b 100644 --- a/src/Ydb.Sdk/src/Transport/AuthGrpcChannelDriver.cs +++ b/src/Ydb.Sdk/src/Transport/AuthGrpcChannelDriver.cs @@ -23,10 +23,7 @@ ILoggerFactory loggerFactory _channel = grpcChannelFactory.CreateChannel(Config.Endpoint); } - protected override (string, GrpcChannel) GetChannel(long nodeId) - { - return (Config.Endpoint, _channel); - } + protected override (string, GrpcChannel) GetChannel(long nodeId) => (Config.Endpoint, _channel); protected override void OnRpcError(string endpoint, RpcException e) { diff --git a/src/Ydb.Sdk/src/Value/ResultSet.cs b/src/Ydb.Sdk/src/Value/ResultSet.cs index 226d52ba..108ab630 100644 --- a/src/Ydb.Sdk/src/Value/ResultSet.cs +++ b/src/Ydb.Sdk/src/Value/ResultSet.cs @@ -6,10 +6,7 @@ namespace Ydb.Sdk.Value; public static class ResultSetExtension { - internal static ResultSet FromProto(this Ydb.ResultSet resultSetProto) - { - return new ResultSet(resultSetProto); - } + internal static ResultSet FromProto(this Ydb.ResultSet resultSetProto) => new(resultSetProto); } public class ResultSet @@ -64,20 +61,11 @@ internal RowsList( public Row this[int index] => new(_rows[index], _columns, _columnsMap); - private IEnumerator GetRowsEnumerator() - { - return new Enumerator(_rows.GetEnumerator(), _columns, _columnsMap); - } + private IEnumerator GetRowsEnumerator() => new Enumerator(_rows.GetEnumerator(), _columns, _columnsMap); - public IEnumerator GetEnumerator() - { - return GetRowsEnumerator(); - } + public IEnumerator GetEnumerator() => GetRowsEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - { - return GetRowsEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetRowsEnumerator(); private class Enumerator : IEnumerator { @@ -101,20 +89,11 @@ internal Enumerator( object IEnumerator.Current => CurrentRow; - public void Dispose() - { - _protoEnumerator.Dispose(); - } + public void Dispose() => _protoEnumerator.Dispose(); - public bool MoveNext() - { - return _protoEnumerator.MoveNext(); - } + public bool MoveNext() => _protoEnumerator.MoveNext(); - public void Reset() - { - _protoEnumerator.Reset(); - } + public void Reset() => _protoEnumerator.Reset(); } } diff --git a/src/Ydb.Sdk/src/Value/YdbValue.cs b/src/Ydb.Sdk/src/Value/YdbValue.cs index de63ed36..1b0a923b 100644 --- a/src/Ydb.Sdk/src/Value/YdbValue.cs +++ b/src/Ydb.Sdk/src/Value/YdbValue.cs @@ -61,28 +61,18 @@ internal YdbValue(Type type, Ydb.Value value) public YdbTypeId TypeId => GetYdbTypeId(_protoType); - public TypedValue GetProto() + public TypedValue GetProto() => new() { - return new TypedValue - { - Type = _protoType, - Value = _protoValue - }; - } + Type = _protoType, + Value = _protoValue + }; - public override string ToString() - { - return _protoValue.ToString() ?? ""; - } + public override string ToString() => _protoValue.ToString() ?? ""; - internal string ToYql() - { - return ToYql(_protoType); - } + internal string ToYql() => ToYql(_protoType); - private static string ToYql(Type type) - { - return type.TypeCase switch + private static string ToYql(Type type) => + type.TypeCase switch { Type.TypeOneofCase.TypeId => type.TypeId.ToString(), Type.TypeOneofCase.DecimalType => "Decimal(22, 9)", @@ -91,11 +81,9 @@ private static string ToYql(Type type) Type.TypeOneofCase.VoidType => "Void", _ => "Unknown" }; - } - internal static YdbTypeId GetYdbTypeId(Type protoType) - { - return protoType.TypeCase switch + internal static YdbTypeId GetYdbTypeId(Type protoType) => + protoType.TypeCase switch { Type.TypeOneofCase.TypeId => Enum.IsDefined(typeof(YdbTypeId), (uint)protoType.TypeId) ? (YdbTypeId)protoType.TypeId @@ -111,5 +99,4 @@ internal static YdbTypeId GetYdbTypeId(Type protoType) Type.TypeOneofCase.NullType => YdbTypeId.Null, _ => YdbTypeId.Unknown }; - } } diff --git a/src/Ydb.Sdk/src/Value/YdbValueBuilder.cs b/src/Ydb.Sdk/src/Value/YdbValueBuilder.cs index 5fa4687d..71a1dfce 100644 --- a/src/Ydb.Sdk/src/Value/YdbValueBuilder.cs +++ b/src/Ydb.Sdk/src/Value/YdbValueBuilder.cs @@ -5,122 +5,75 @@ namespace Ydb.Sdk.Value; public partial class YdbValue { - public static YdbValue MakeBool(bool value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Bool), new Ydb.Value { BoolValue = value }); - } + public static YdbValue MakeBool(bool value) => new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Bool), + new Ydb.Value { BoolValue = value }); - public static YdbValue MakeInt8(sbyte value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Int8), new Ydb.Value { Int32Value = value }); - } + public static YdbValue MakeInt8(sbyte value) => new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Int8), + new Ydb.Value { Int32Value = value }); - public static YdbValue MakeUint8(byte value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint8), + public static YdbValue MakeUint8(byte value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint8), new Ydb.Value { Uint32Value = value }); - } - public static YdbValue MakeInt16(short value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Int16), new Ydb.Value { Int32Value = value }); - } + public static YdbValue MakeInt16(short value) => new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Int16), + new Ydb.Value { Int32Value = value }); - public static YdbValue MakeUint16(ushort value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint16), - new Ydb.Value { Uint32Value = value }); - } + public static YdbValue MakeUint16(ushort value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint16), new Ydb.Value { Uint32Value = value }); - public static YdbValue MakeInt32(int value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Int32), new Ydb.Value { Int32Value = value }); - } + public static YdbValue MakeInt32(int value) => new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Int32), + new Ydb.Value { Int32Value = value }); - public static YdbValue MakeUint32(uint value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint32), - new Ydb.Value { Uint32Value = value }); - } + public static YdbValue MakeUint32(uint value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint32), new Ydb.Value { Uint32Value = value }); - public static YdbValue MakeInt64(long value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Int64), - new Ydb.Value { Int64Value = value }); - } + public static YdbValue MakeInt64(long value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Int64), new Ydb.Value { Int64Value = value }); - public static YdbValue MakeUint64(ulong value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint64), - new Ydb.Value { Uint64Value = value }); - } + public static YdbValue MakeUint64(ulong value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Uint64), new Ydb.Value { Uint64Value = value }); - public static YdbValue MakeFloat(float value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Float), - new Ydb.Value { FloatValue = value }); - } + public static YdbValue MakeFloat(float value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Float), new Ydb.Value { FloatValue = value }); - public static YdbValue MakeDouble(double value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Double), - new Ydb.Value { DoubleValue = value }); - } + public static YdbValue MakeDouble(double value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Double), new Ydb.Value { DoubleValue = value }); - public static YdbValue MakeDate(DateTime value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Date), new Ydb.Value + public static YdbValue MakeDate(DateTime value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Date), new Ydb.Value { Uint32Value = (uint)value.Subtract(DateTime.UnixEpoch).TotalDays }); - } - public static YdbValue MakeDatetime(DateTime value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Datetime), new Ydb.Value + public static YdbValue MakeDatetime(DateTime value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Datetime), new Ydb.Value { Uint32Value = (uint)((value.Ticks - DateTime.UnixEpoch.Ticks) * Duration.NanosecondsPerTick / Duration.NanosecondsPerSecond) }); - } - public static YdbValue MakeTimestamp(DateTime value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Timestamp), new Ydb.Value + public static YdbValue MakeTimestamp(DateTime value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Timestamp), new Ydb.Value { Uint64Value = (ulong)(value.Ticks - DateTime.UnixEpoch.Ticks) * Duration.NanosecondsPerTick / 1000 }); - } - public static YdbValue MakeInterval(TimeSpan value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Interval), new Ydb.Value + public static YdbValue MakeInterval(TimeSpan value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Interval), new Ydb.Value { Int64Value = value.Ticks * Duration.NanosecondsPerTick / 1000 }); - } - public static YdbValue MakeString(byte[] value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.String), new Ydb.Value + public static YdbValue MakeString(byte[] value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.String), new Ydb.Value { BytesValue = ByteString.CopyFrom(value) }); - } - public static YdbValue MakeUtf8(string value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Utf8), new Ydb.Value { TextValue = value }); - } + public static YdbValue MakeUtf8(string value) => new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Utf8), + new Ydb.Value { TextValue = value }); - public static YdbValue MakeYson(byte[] value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Yson), + public static YdbValue MakeYson(byte[] value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Yson), new Ydb.Value { BytesValue = ByteString.CopyFrom(value) }); - } - public static YdbValue MakeJson(string value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.Json), new Ydb.Value { TextValue = value }); - } + public static YdbValue MakeJson(string value) => new(MakePrimitiveType(Type.Types.PrimitiveTypeId.Json), + new Ydb.Value { TextValue = value }); - public static YdbValue MakeJsonDocument(string value) - { - return new YdbValue(MakePrimitiveType(Type.Types.PrimitiveTypeId.JsonDocument), - new Ydb.Value { TextValue = value }); - } + public static YdbValue MakeJsonDocument(string value) => + new(MakePrimitiveType(Type.Types.PrimitiveTypeId.JsonDocument), new Ydb.Value { TextValue = value }); public static YdbValue MakeUuid(Guid guid) { @@ -215,34 +168,27 @@ public static YdbValue MakeDecimalWithPrecision(decimal value, uint? precision = return new YdbValue(type, ydbValue); } - public static YdbValue MakeDecimal(decimal value) - { - return MakeDecimalWithPrecision(value, 22, 9); - } + public static YdbValue MakeDecimal(decimal value) => MakeDecimalWithPrecision(value, 22, 9); - private static YdbValue MakeOptional(YdbValue value) - { - return new YdbValue( + private static YdbValue MakeOptional(YdbValue value) => + new( new Type { OptionalType = new OptionalType { Item = value._protoType } }, value.TypeId != YdbTypeId.OptionalType ? value._protoValue : new Ydb.Value { NestedValue = value._protoValue }); - } // TODO: MakeEmptyList with complex types - public static YdbValue MakeEmptyList(YdbTypeId typeId) - { - return new YdbValue( + public static YdbValue MakeEmptyList(YdbTypeId typeId) => + new( new Type { ListType = new ListType { Item = MakePrimitiveType(typeId) } }, new Ydb.Value()); - } // TODO: Check items type public static YdbValue MakeList(IReadOnlyList values) { if (values.Count == 0) { - throw new ArgumentOutOfRangeException("values"); + throw new ArgumentOutOfRangeException(nameof(values)); } var value = new Ydb.Value(); @@ -282,10 +228,8 @@ public static YdbValue MakeStruct(IReadOnlyDictionary members) return new YdbValue(type, value); } - private static Type MakePrimitiveType(Type.Types.PrimitiveTypeId primitiveTypeId) - { - return new Type { TypeId = primitiveTypeId }; - } + private static Type MakePrimitiveType(Type.Types.PrimitiveTypeId primitiveTypeId) => + new() { TypeId = primitiveTypeId }; private static Type MakePrimitiveType(YdbTypeId typeId) { @@ -293,10 +237,7 @@ private static Type MakePrimitiveType(YdbTypeId typeId) return new Type { TypeId = (Type.Types.PrimitiveTypeId)typeId }; } - private static bool IsPrimitiveTypeId(YdbTypeId typeId) - { - return (uint)typeId < YdbTypeIdRanges.ComplexTypesFirst; - } + private static bool IsPrimitiveTypeId(YdbTypeId typeId) => (uint)typeId < YdbTypeIdRanges.ComplexTypesFirst; private static void EnsurePrimitiveTypeId(YdbTypeId typeId) { @@ -306,125 +247,65 @@ private static void EnsurePrimitiveTypeId(YdbTypeId typeId) } } - public static YdbValue MakeOptionalBool(bool? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Bool, MakeBool); - } + public static YdbValue MakeOptionalBool(bool? value = null) => MakeOptionalOf(value, YdbTypeId.Bool, MakeBool); - public static YdbValue MakeOptionalInt8(sbyte? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Int8, MakeInt8); - } + public static YdbValue MakeOptionalInt8(sbyte? value = null) => MakeOptionalOf(value, YdbTypeId.Int8, MakeInt8); - public static YdbValue MakeOptionalUint8(byte? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Uint8, MakeUint8); - } + public static YdbValue MakeOptionalUint8(byte? value = null) => MakeOptionalOf(value, YdbTypeId.Uint8, MakeUint8); - public static YdbValue MakeOptionalInt16(short? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Int16, MakeInt16); - } + public static YdbValue MakeOptionalInt16(short? value = null) => MakeOptionalOf(value, YdbTypeId.Int16, MakeInt16); - public static YdbValue MakeOptionalUint16(ushort? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Uint16, MakeUint16); - } + public static YdbValue MakeOptionalUint16(ushort? value = null) => + MakeOptionalOf(value, YdbTypeId.Uint16, MakeUint16); - public static YdbValue MakeOptionalInt32(int? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Int32, MakeInt32); - } + public static YdbValue MakeOptionalInt32(int? value = null) => MakeOptionalOf(value, YdbTypeId.Int32, MakeInt32); - public static YdbValue MakeOptionalUint32(uint? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Uint32, MakeUint32); - } + public static YdbValue MakeOptionalUint32(uint? value = null) => + MakeOptionalOf(value, YdbTypeId.Uint32, MakeUint32); - public static YdbValue MakeOptionalInt64(long? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Int64, MakeInt64); - } + public static YdbValue MakeOptionalInt64(long? value = null) => MakeOptionalOf(value, YdbTypeId.Int64, MakeInt64); - public static YdbValue MakeOptionalUint64(ulong? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Uint64, MakeUint64); - } + public static YdbValue MakeOptionalUint64(ulong? value = null) => + MakeOptionalOf(value, YdbTypeId.Uint64, MakeUint64); - public static YdbValue MakeOptionalFloat(float? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Float, MakeFloat); - } + public static YdbValue MakeOptionalFloat(float? value = null) => MakeOptionalOf(value, YdbTypeId.Float, MakeFloat); - public static YdbValue MakeOptionalDouble(double? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Double, MakeDouble); - } + public static YdbValue MakeOptionalDouble(double? value = null) => + MakeOptionalOf(value, YdbTypeId.Double, MakeDouble); - public static YdbValue MakeOptionalDate(DateTime? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Date, MakeDate); - } + public static YdbValue MakeOptionalDate(DateTime? value = null) => MakeOptionalOf(value, YdbTypeId.Date, MakeDate); - public static YdbValue MakeOptionalDatetime(DateTime? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Datetime, MakeDatetime); - } + public static YdbValue MakeOptionalDatetime(DateTime? value = null) => + MakeOptionalOf(value, YdbTypeId.Datetime, MakeDatetime); - public static YdbValue MakeOptionalTimestamp(DateTime? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Timestamp, MakeTimestamp); - } + public static YdbValue MakeOptionalTimestamp(DateTime? value = null) => + MakeOptionalOf(value, YdbTypeId.Timestamp, MakeTimestamp); - public static YdbValue MakeOptionalInterval(TimeSpan? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Interval, MakeInterval); - } + public static YdbValue MakeOptionalInterval(TimeSpan? value = null) => + MakeOptionalOf(value, YdbTypeId.Interval, MakeInterval); - public static YdbValue MakeOptionalString(byte[]? value = null) - { - return MakeOptionalOf(value, YdbTypeId.String, MakeString); - } + public static YdbValue MakeOptionalString(byte[]? value = null) => + MakeOptionalOf(value, YdbTypeId.String, MakeString); - public static YdbValue MakeOptionalUtf8(string? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Utf8, MakeUtf8); - } + public static YdbValue MakeOptionalUtf8(string? value = null) => MakeOptionalOf(value, YdbTypeId.Utf8, MakeUtf8); - public static YdbValue MakeOptionalYson(byte[]? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Yson, MakeYson); - } + public static YdbValue MakeOptionalYson(byte[]? value = null) => MakeOptionalOf(value, YdbTypeId.Yson, MakeYson); - public static YdbValue MakeOptionalJson(string? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Json, MakeJson); - } + public static YdbValue MakeOptionalJson(string? value = null) => MakeOptionalOf(value, YdbTypeId.Json, MakeJson); - public static YdbValue MakeOptionalJsonDocument(string? value = null) - { - return MakeOptionalOf(value, YdbTypeId.JsonDocument, MakeJsonDocument); - } + public static YdbValue MakeOptionalJsonDocument(string? value = null) => + MakeOptionalOf(value, YdbTypeId.JsonDocument, MakeJsonDocument); - public static YdbValue MakeOptionalUuid(Guid? value = null) - { - return MakeOptionalOf(value, YdbTypeId.Uuid, MakeUuid); - } + public static YdbValue MakeOptionalUuid(Guid? value = null) => MakeOptionalOf(value, YdbTypeId.Uuid, MakeUuid); - public static YdbValue MakeOptionalDecimal(decimal? value = null) - { - return MakeOptionalOf(value, YdbTypeId.DecimalType, MakeDecimal); - } + public static YdbValue MakeOptionalDecimal(decimal? value = null) => + MakeOptionalOf(value, YdbTypeId.DecimalType, MakeDecimal); - private static YdbValue MakeOptionalOf(T? value, YdbTypeId type, Func func) where T : struct - { - return value is null ? MakeEmptyOptional(type) : MakeOptional(func((T)value)); - } + private static YdbValue MakeOptionalOf(T? value, YdbTypeId type, Func func) where T : struct => + value is null ? MakeEmptyOptional(type) : MakeOptional(func((T)value)); - private static YdbValue MakeOptionalOf(T? value, YdbTypeId type, Func func) where T : class - { - return value is null ? MakeEmptyOptional(type) : MakeOptional(func(value)); - } + private static YdbValue MakeOptionalOf(T? value, YdbTypeId type, Func func) where T : class => + value is null ? MakeEmptyOptional(type) : MakeOptional(func(value)); private static YdbValue MakeEmptyOptional(YdbTypeId typeId) { diff --git a/src/Ydb.Sdk/src/Value/YdbValueCast.cs b/src/Ydb.Sdk/src/Value/YdbValueCast.cs index 22ebcee9..f73f90b3 100644 --- a/src/Ydb.Sdk/src/Value/YdbValueCast.cs +++ b/src/Ydb.Sdk/src/Value/YdbValueCast.cs @@ -2,178 +2,80 @@ public partial class YdbValue { - public static explicit operator bool(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator bool?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator sbyte(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator sbyte?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator byte(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator byte?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator short(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator short?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator ushort(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator ushort?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator int(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator int?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator uint(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator uint?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator long(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator long?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator ulong(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator ulong?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator float(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator float?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator double(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator double?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator DateTime(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator DateTime?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator TimeSpan(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator TimeSpan?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator string?(YdbValue value) - { - return GetOptionalObject(value); - } - - public static explicit operator byte[]?(YdbValue value) - { - return GetOptionalObject(value); - } - - public static explicit operator decimal(YdbValue value) - { - return GetObject(value); - } - - public static explicit operator decimal?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - public static explicit operator Guid?(YdbValue value) - { - return GetOptionalPrimitive(value); - } - - private static T? GetOptionalPrimitive(YdbValue value) where T : struct - { - return value.TypeId == YdbTypeId.OptionalType + public static explicit operator bool(YdbValue value) => GetObject(value); + + public static explicit operator bool?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator sbyte(YdbValue value) => GetObject(value); + + public static explicit operator sbyte?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator byte(YdbValue value) => GetObject(value); + + public static explicit operator byte?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator short(YdbValue value) => GetObject(value); + + public static explicit operator short?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator ushort(YdbValue value) => GetObject(value); + + public static explicit operator ushort?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator int(YdbValue value) => GetObject(value); + + public static explicit operator int?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator uint(YdbValue value) => GetObject(value); + + public static explicit operator uint?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator long(YdbValue value) => GetObject(value); + + public static explicit operator long?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator ulong(YdbValue value) => GetObject(value); + + public static explicit operator ulong?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator float(YdbValue value) => GetObject(value); + + public static explicit operator float?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator double(YdbValue value) => GetObject(value); + + public static explicit operator double?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator DateTime(YdbValue value) => GetObject(value); + + public static explicit operator DateTime?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator TimeSpan(YdbValue value) => GetObject(value); + + public static explicit operator TimeSpan?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator string?(YdbValue value) => GetOptionalObject(value); + + public static explicit operator byte[]?(YdbValue value) => GetOptionalObject(value); + + public static explicit operator decimal(YdbValue value) => GetObject(value); + + public static explicit operator decimal?(YdbValue value) => GetOptionalPrimitive(value); + + public static explicit operator Guid?(YdbValue value) => GetOptionalPrimitive(value); + + private static T? GetOptionalPrimitive(YdbValue value) where T : struct => + value.TypeId == YdbTypeId.OptionalType ? value.GetOptional() is not null ? GetObject(value.GetOptional()!) : null : GetObject(value); - } - private static T? GetOptionalObject(YdbValue value) where T : class - { - return value.TypeId == YdbTypeId.OptionalType + private static T? GetOptionalObject(YdbValue value) where T : class => + value.TypeId == YdbTypeId.OptionalType ? value.GetOptional() is not null ? GetObject(value.GetOptional()!) : null : GetObject(value); - } - private static T GetObject(YdbValue value) - { - return (T)(object)(value.TypeId switch + private static T GetObject(YdbValue value) => + (T)(object)(value.TypeId switch { YdbTypeId.Bool => value.GetBool(), YdbTypeId.Int8 => value.GetInt8(), @@ -199,135 +101,56 @@ private static T GetObject(YdbValue value) YdbTypeId.Uuid => value.GetUuid(), _ => throw new InvalidCastException($"Cannot cast YDB type {value.TypeId} to {typeof(T).Name}.") }); - } - - public static explicit operator YdbValue(bool value) - { - return MakeBool(value); - } - - public static explicit operator YdbValue(bool? value) - { - return MakeOptionalBool(value); - } - - public static explicit operator YdbValue(sbyte value) - { - return MakeInt8(value); - } - - public static explicit operator YdbValue(sbyte? value) - { - return MakeOptionalInt8(value); - } - - public static explicit operator YdbValue(byte value) - { - return MakeUint8(value); - } - - public static explicit operator YdbValue(byte? value) - { - return MakeOptionalUint8(value); - } - - public static explicit operator YdbValue(short value) - { - return MakeInt16(value); - } - - public static explicit operator YdbValue(short? value) - { - return MakeOptionalInt16(value); - } - - public static explicit operator YdbValue(ushort value) - { - return MakeUint16(value); - } - - public static explicit operator YdbValue(ushort? value) - { - return MakeOptionalUint16(value); - } - - public static explicit operator YdbValue(int value) - { - return MakeInt32(value); - } - - public static explicit operator YdbValue(int? value) - { - return MakeOptionalInt32(value); - } - - public static explicit operator YdbValue(uint value) - { - return MakeUint32(value); - } - - public static explicit operator YdbValue(uint? value) - { - return MakeOptionalUint32(value); - } - - public static explicit operator YdbValue(long value) - { - return MakeInt64(value); - } - - public static explicit operator YdbValue(long? value) - { - return MakeOptionalInt64(value); - } - - public static explicit operator YdbValue(ulong value) - { - return MakeUint64(value); - } - - public static explicit operator YdbValue(ulong? value) - { - return MakeOptionalUint64(value); - } - - public static explicit operator YdbValue(float value) - { - return MakeFloat(value); - } - - public static explicit operator YdbValue(float? value) - { - return MakeOptionalFloat(value); - } - - public static explicit operator YdbValue(double value) - { - return MakeDouble(value); - } - - public static explicit operator YdbValue(double? value) - { - return MakeOptionalDouble(value); - } - - public static explicit operator YdbValue(TimeSpan value) - { - return MakeInterval(value); - } - - public static explicit operator YdbValue(TimeSpan? value) - { - return MakeOptionalInterval(value); - } - - public static explicit operator YdbValue(decimal value) - { - return MakeDecimal(value); - } - - public static explicit operator YdbValue(decimal? value) - { - return MakeOptionalDecimal(value); - } + + public static explicit operator YdbValue(bool value) => MakeBool(value); + + public static explicit operator YdbValue(bool? value) => MakeOptionalBool(value); + + public static explicit operator YdbValue(sbyte value) => MakeInt8(value); + + public static explicit operator YdbValue(sbyte? value) => MakeOptionalInt8(value); + + public static explicit operator YdbValue(byte value) => MakeUint8(value); + + public static explicit operator YdbValue(byte? value) => MakeOptionalUint8(value); + + public static explicit operator YdbValue(short value) => MakeInt16(value); + + public static explicit operator YdbValue(short? value) => MakeOptionalInt16(value); + + public static explicit operator YdbValue(ushort value) => MakeUint16(value); + + public static explicit operator YdbValue(ushort? value) => MakeOptionalUint16(value); + + public static explicit operator YdbValue(int value) => MakeInt32(value); + + public static explicit operator YdbValue(int? value) => MakeOptionalInt32(value); + + public static explicit operator YdbValue(uint value) => MakeUint32(value); + + public static explicit operator YdbValue(uint? value) => MakeOptionalUint32(value); + + public static explicit operator YdbValue(long value) => MakeInt64(value); + + public static explicit operator YdbValue(long? value) => MakeOptionalInt64(value); + + public static explicit operator YdbValue(ulong value) => MakeUint64(value); + + public static explicit operator YdbValue(ulong? value) => MakeOptionalUint64(value); + + public static explicit operator YdbValue(float value) => MakeFloat(value); + + public static explicit operator YdbValue(float? value) => MakeOptionalFloat(value); + + public static explicit operator YdbValue(double value) => MakeDouble(value); + + public static explicit operator YdbValue(double? value) => MakeOptionalDouble(value); + + public static explicit operator YdbValue(TimeSpan value) => MakeInterval(value); + + public static explicit operator YdbValue(TimeSpan? value) => MakeOptionalInterval(value); + + public static explicit operator YdbValue(decimal value) => MakeDecimal(value); + + public static explicit operator YdbValue(decimal? value) => MakeOptionalDecimal(value); } diff --git a/src/Ydb.Sdk/src/Value/YdbValueParser.cs b/src/Ydb.Sdk/src/Value/YdbValueParser.cs index 228bae00..8892af26 100644 --- a/src/Ydb.Sdk/src/Value/YdbValueParser.cs +++ b/src/Ydb.Sdk/src/Value/YdbValueParser.cs @@ -176,116 +176,50 @@ public decimal GetDecimal() return new decimal((int)low64, (int)(low64 >> 32), (int)high64, isNegative, (byte)scale); } - public bool? GetOptionalBool() - { - return GetOptional()?.GetBool(); - } + public bool? GetOptionalBool() => GetOptional()?.GetBool(); - public sbyte? GetOptionalInt8() - { - return GetOptional()?.GetInt8(); - } + public sbyte? GetOptionalInt8() => GetOptional()?.GetInt8(); - public byte? GetOptionalUint8() - { - return GetOptional()?.GetUint8(); - } + public byte? GetOptionalUint8() => GetOptional()?.GetUint8(); - public short? GetOptionalInt16() - { - return GetOptional()?.GetInt16(); - } + public short? GetOptionalInt16() => GetOptional()?.GetInt16(); - public ushort? GetOptionalUint16() - { - return GetOptional()?.GetUint16(); - } + public ushort? GetOptionalUint16() => GetOptional()?.GetUint16(); - public int? GetOptionalInt32() - { - return GetOptional()?.GetInt32(); - } + public int? GetOptionalInt32() => GetOptional()?.GetInt32(); - public uint? GetOptionalUint32() - { - return GetOptional()?.GetUint32(); - } + public uint? GetOptionalUint32() => GetOptional()?.GetUint32(); - public long? GetOptionalInt64() - { - return GetOptional()?.GetInt64(); - } + public long? GetOptionalInt64() => GetOptional()?.GetInt64(); - public ulong? GetOptionalUint64() - { - return GetOptional()?.GetUint64(); - } + public ulong? GetOptionalUint64() => GetOptional()?.GetUint64(); - public float? GetOptionalFloat() - { - return GetOptional()?.GetFloat(); - } + public float? GetOptionalFloat() => GetOptional()?.GetFloat(); - public double? GetOptionalDouble() - { - return GetOptional()?.GetDouble(); - } + public double? GetOptionalDouble() => GetOptional()?.GetDouble(); - public DateTime? GetOptionalDate() - { - return GetOptional()?.GetDate(); - } + public DateTime? GetOptionalDate() => GetOptional()?.GetDate(); - public DateTime? GetOptionalDatetime() - { - return GetOptional()?.GetDatetime(); - } + public DateTime? GetOptionalDatetime() => GetOptional()?.GetDatetime(); - public DateTime? GetOptionalTimestamp() - { - return GetOptional()?.GetTimestamp(); - } + public DateTime? GetOptionalTimestamp() => GetOptional()?.GetTimestamp(); - public TimeSpan? GetOptionalInterval() - { - return GetOptional()?.GetInterval(); - } + public TimeSpan? GetOptionalInterval() => GetOptional()?.GetInterval(); - public byte[]? GetOptionalString() - { - return GetOptional()?.GetString(); - } + public byte[]? GetOptionalString() => GetOptional()?.GetString(); - public string? GetOptionalUtf8() - { - return GetOptional()?.GetUtf8(); - } + public string? GetOptionalUtf8() => GetOptional()?.GetUtf8(); - public byte[]? GetOptionalYson() - { - return GetOptional()?.GetYson(); - } + public byte[]? GetOptionalYson() => GetOptional()?.GetYson(); - public string? GetOptionalJson() - { - return GetOptional()?.GetJson(); - } + public string? GetOptionalJson() => GetOptional()?.GetJson(); - public string? GetOptionalJsonDocument() - { - return GetOptional()?.GetJsonDocument(); - } + public string? GetOptionalJsonDocument() => GetOptional()?.GetJsonDocument(); - public Guid? GetOptionalUuid() - { - return GetOptional()?.GetUuid(); - } + public Guid? GetOptionalUuid() => GetOptional()?.GetUuid(); - public decimal? GetOptionalDecimal() - { - return GetOptional()?.GetDecimal(); - } + public decimal? GetOptionalDecimal() => GetOptional()?.GetDecimal(); public YdbValue? GetOptional() { diff --git a/src/Ydb.Sdk/tests/Ado/Specification/YdbDataReaderTests.cs b/src/Ydb.Sdk/tests/Ado/Specification/YdbDataReaderTests.cs index 6de9e1d9..3aa42aae 100644 --- a/src/Ydb.Sdk/tests/Ado/Specification/YdbDataReaderTests.cs +++ b/src/Ydb.Sdk/tests/Ado/Specification/YdbDataReaderTests.cs @@ -27,71 +27,59 @@ public override void Dispose_command_before_reader() Assert.False(reader.Read()); } - public override void GetChars_reads_nothing_at_end_of_buffer() + public override void GetChars_reads_nothing_at_end_of_buffer() => TestGetChars(reader => { - TestGetChars(reader => { Assert.Equal(0, reader.GetChars(0, 0, new char[4], 4, 0)); }); - } + Assert.Equal(0, reader.GetChars(0, 0, new char[4], 4, 0)); + }); - public override void GetChars_reads_nothing_when_dataOffset_is_too_large() + public override void GetChars_reads_nothing_when_dataOffset_is_too_large() => TestGetChars(reader => { - TestGetChars(reader => { Assert.Equal(0, reader.GetChars(0, 6, new char[4], 0, 4)); }); - } + Assert.Equal(0, reader.GetChars(0, 6, new char[4], 0, 4)); + }); - public override void GetChars_reads_part_of_string() - { + public override void GetChars_reads_part_of_string() => TestGetChars(reader => { var buffer = new char[5]; Assert.Equal(2, reader.GetChars(0, 1, buffer, 2, 2)); Assert.Equal(new[] { '\0', '\0', 'b', '¢', '\0' }, buffer); }); - } - public override void GetChars_returns_length_when_buffer_is_null() + public override void GetChars_returns_length_when_buffer_is_null() => TestGetChars(reader => { - TestGetChars(reader => { Assert.Equal(4, reader.GetChars(0, 0, null, 0, 0)); }); - } + Assert.Equal(4, reader.GetChars(0, 0, null, 0, 0)); + }); - public override void GetChars_returns_length_when_buffer_is_null_and_dataOffset_is_specified() - { + public override void GetChars_returns_length_when_buffer_is_null_and_dataOffset_is_specified() => TestGetChars(reader => { Assert.Equal(4, reader.GetChars(0, 1, null, 0, 0)); }); - } - public override void GetChars_throws_when_bufferOffset_is_negative() - { + public override void GetChars_throws_when_bufferOffset_is_negative() => TestGetChars(reader => { AssertThrowsAny(() => reader.GetChars(0, 0, new char[4], -1, 4)); }); - } - public override void GetChars_throws_when_bufferOffset_is_too_large() - { + public override void GetChars_throws_when_bufferOffset_is_too_large() => TestGetChars(reader => { AssertThrowsAny(() => reader.GetChars(0, 0, new char[4], 5, 0)); }); - } - public override void GetChars_throws_when_bufferOffset_plus_length_is_too_long() - { + public override void GetChars_throws_when_bufferOffset_plus_length_is_too_long() => TestGetChars(reader => { AssertThrowsAny(() => reader.GetChars(0, 0, new char[4], 2, 3)); }); - } - public override void GetChars_throws_when_dataOffset_is_negative() - { + public override void GetChars_throws_when_dataOffset_is_negative() => TestGetChars(reader => { AssertThrowsAny(() => reader.GetChars(0, -1, new char[4], 0, 4)); }); - } public override void GetChars_works() { @@ -107,15 +95,13 @@ public override void GetChars_works() Assert.Equal(new[] { 't', 'e', 's', 't' }, buffer); } - public override void GetChars_works_when_buffer_is_large() - { + public override void GetChars_works_when_buffer_is_large() => TestGetChars(reader => { var buffer = new char[6]; Assert.Equal(4, reader.GetChars(0, 0, buffer, 0, 6)); Assert.Equal(new[] { 'a', 'b', '¢', 'd', '\0', '\0' }, buffer); }); - } public override void GetFieldType_works() { @@ -151,22 +137,16 @@ public override void Item_by_name_works() } - public override void GetValue_to_string_works_utf8_two_bytes() - { + public override void GetValue_to_string_works_utf8_two_bytes() => GetX_works("SELECT 'Ä'u;", r => r.GetValue(0) as string, "Ä"); - } - public override void GetValue_to_string_works_utf8_three_bytes() - { + public override void GetValue_to_string_works_utf8_three_bytes() => GetX_works("SELECT 'Ḁ'u;", r => r.GetValue(0) as string, "Ḁ"); - } - public override void GetValue_to_string_works_utf8_four_bytes() - { + public override void GetValue_to_string_works_utf8_four_bytes() => GetX_works("SELECT '😀'u;", r => r.GetValue(0) as string, "😀"); - } public override void GetValues_works() { @@ -186,25 +166,13 @@ public override void GetValues_works() Assert.Same(DBNull.Value, values[1]); } - public override void GetString_works() - { - GetX_works("SELECT 'test'u;", r => r.GetString(0), "test"); - } + public override void GetString_works() => GetX_works("SELECT 'test'u;", r => r.GetString(0), "test"); - public override void GetString_works_utf8_two_bytes() - { - GetX_works("SELECT 'Ä'u;", r => r.GetString(0), "Ä"); - } + public override void GetString_works_utf8_two_bytes() => GetX_works("SELECT 'Ä'u;", r => r.GetString(0), "Ä"); - public override void GetString_works_utf8_three_bytes() - { - GetX_works("SELECT 'Ḁ'u;", r => r.GetString(0), "Ḁ"); - } + public override void GetString_works_utf8_three_bytes() => GetX_works("SELECT 'Ḁ'u;", r => r.GetString(0), "Ḁ"); - public override void GetString_works_utf8_four_bytes() - { - GetX_works("SELECT '😀'u;", r => r.GetString(0), "😀"); - } + public override void GetString_works_utf8_four_bytes() => GetX_works("SELECT '😀'u;", r => r.GetString(0), "😀"); // UNION does not guarantee order public override void Read_works() @@ -225,20 +193,14 @@ public override void Read_works() Assert.False(hasData); } - public override void GetFieldValue_works_utf8_two_bytes() - { + public override void GetFieldValue_works_utf8_two_bytes() => GetX_works("SELECT 'Ä'u;", r => r.GetFieldValue(0), "Ä"); - } - public override void GetFieldValue_works_utf8_three_bytes() - { + public override void GetFieldValue_works_utf8_three_bytes() => GetX_works("SELECT 'Ḁ'u;", r => r.GetFieldValue(0), "Ḁ"); - } - public override void GetFieldValue_works_utf8_four_bytes() - { + public override void GetFieldValue_works_utf8_four_bytes() => GetX_works("SELECT '😀'u;", r => r.GetFieldValue(0), "😀"); - } #pragma warning disable xUnit1004 [Fact(Skip = "Don't supported CommandBehavior")] diff --git a/src/Ydb.Sdk/tests/Ado/Specification/YdbGetValueConversionTests.cs b/src/Ydb.Sdk/tests/Ado/Specification/YdbGetValueConversionTests.cs index 78d64ffa..325ec823 100644 --- a/src/Ydb.Sdk/tests/Ado/Specification/YdbGetValueConversionTests.cs +++ b/src/Ydb.Sdk/tests/Ado/Specification/YdbGetValueConversionTests.cs @@ -14,723 +14,463 @@ public YdbGetValueConversionTests(YdbSelectValueFixture fixture) : base(fixture) #pragma warning disable xUnit1004 [Fact(Skip = "Uint16 >> Int16")] - public override void GetInt16_for_minimum_UInt16() - { - base.GetInt16_for_minimum_UInt16(); - } + public override void GetInt16_for_minimum_UInt16() => base.GetInt16_for_minimum_UInt16(); [Fact(Skip = "Uint16 >> Int16")] - public override void GetInt16_for_minimum_UInt16_with_GetFieldValue() - { + public override void GetInt16_for_minimum_UInt16_with_GetFieldValue() => base.GetInt16_for_minimum_UInt16_with_GetFieldValue(); - } [Fact(Skip = "Uint16 >> Int16")] - public override Task GetInt16_for_minimum_UInt16_with_GetFieldValueAsync() - { - return base.GetInt16_for_minimum_UInt16_with_GetFieldValueAsync(); - } + public override Task GetInt16_for_minimum_UInt16_with_GetFieldValueAsync() => + base.GetInt16_for_minimum_UInt16_with_GetFieldValueAsync(); [Fact(Skip = "Int32 >> Int16")] - public override void GetInt16_for_one_Int32() - { - base.GetInt16_for_one_Int32(); - } + public override void GetInt16_for_one_Int32() => base.GetInt16_for_one_Int32(); [Fact(Skip = "Int32 >> Int16")] - public override void GetInt16_for_one_Int32_with_GetFieldValue() - { + public override void GetInt16_for_one_Int32_with_GetFieldValue() => base.GetInt16_for_one_Int32_with_GetFieldValue(); - } [Fact(Skip = "Int32 >> Int16")] - public override Task GetInt16_for_one_Int32_with_GetFieldValueAsync() - { - return base.GetInt16_for_one_Int32_with_GetFieldValueAsync(); - } + public override Task GetInt16_for_one_Int32_with_GetFieldValueAsync() => + base.GetInt16_for_one_Int32_with_GetFieldValueAsync(); [Fact(Skip = "Int64 >> Int16")] - public override void GetInt16_for_one_Int64() - { - base.GetInt16_for_one_Int64(); - } + public override void GetInt16_for_one_Int64() => base.GetInt16_for_one_Int64(); [Fact(Skip = "Int64 >> Int16")] - public override void GetInt16_for_one_Int64_with_GetFieldValue() - { + public override void GetInt16_for_one_Int64_with_GetFieldValue() => base.GetInt16_for_one_Int64_with_GetFieldValue(); - } [Fact(Skip = "Int64 >> Int16")] - public override Task GetInt16_for_one_Int64_with_GetFieldValueAsync() - { - return base.GetInt16_for_one_Int64_with_GetFieldValueAsync(); - } + public override Task GetInt16_for_one_Int64_with_GetFieldValueAsync() => + base.GetInt16_for_one_Int64_with_GetFieldValueAsync(); [Fact(Skip = "Uint16 >> Int16")] - public override void GetInt16_for_one_UInt16() - { - base.GetInt16_for_one_UInt16(); - } + public override void GetInt16_for_one_UInt16() => base.GetInt16_for_one_UInt16(); [Fact(Skip = "Uint16 >> Int16")] - public override void GetInt16_for_one_UInt16_with_GetFieldValue() - { + public override void GetInt16_for_one_UInt16_with_GetFieldValue() => base.GetInt16_for_one_UInt16_with_GetFieldValue(); - } [Fact(Skip = "Uint16 >> Int16")] - public override Task GetInt16_for_one_UInt16_with_GetFieldValueAsync() - { - return base.GetInt16_for_one_UInt16_with_GetFieldValueAsync(); - } + public override Task GetInt16_for_one_UInt16_with_GetFieldValueAsync() => + base.GetInt16_for_one_UInt16_with_GetFieldValueAsync(); [Fact(Skip = "Int32 >> Int16")] - public override void GetInt16_for_zero_Int32() - { - base.GetInt16_for_zero_Int32(); - } + public override void GetInt16_for_zero_Int32() => base.GetInt16_for_zero_Int32(); [Fact(Skip = "Int32 >> Int16")] - public override void GetInt16_for_zero_Int32_with_GetFieldValue() - { + public override void GetInt16_for_zero_Int32_with_GetFieldValue() => base.GetInt16_for_zero_Int32_with_GetFieldValue(); - } [Fact(Skip = "Int32 >> Int16")] - public override Task GetInt16_for_zero_Int32_with_GetFieldValueAsync() - { - return base.GetInt16_for_zero_Int32_with_GetFieldValueAsync(); - } + public override Task GetInt16_for_zero_Int32_with_GetFieldValueAsync() => + base.GetInt16_for_zero_Int32_with_GetFieldValueAsync(); [Fact(Skip = "Int64 >> Int16")] - public override void GetInt16_for_zero_Int64() - { - base.GetInt16_for_zero_Int64(); - } + public override void GetInt16_for_zero_Int64() => base.GetInt16_for_zero_Int64(); [Fact(Skip = "Int64 >> Int16")] - public override void GetInt16_for_zero_Int64_with_GetFieldValue() - { + public override void GetInt16_for_zero_Int64_with_GetFieldValue() => base.GetInt16_for_zero_Int64_with_GetFieldValue(); - } [Fact(Skip = "Int64 >> Int16")] - public override Task GetInt16_for_zero_Int64_with_GetFieldValueAsync() - { - return base.GetInt16_for_zero_Int64_with_GetFieldValueAsync(); - } + public override Task GetInt16_for_zero_Int64_with_GetFieldValueAsync() => + base.GetInt16_for_zero_Int64_with_GetFieldValueAsync(); [Fact(Skip = "Uint16 >> Int16")] - public override void GetInt16_for_zero_UInt16() - { - base.GetInt16_for_zero_UInt16(); - } + public override void GetInt16_for_zero_UInt16() => base.GetInt16_for_zero_UInt16(); [Fact(Skip = "Uint16 >> Int16")] - public override void GetInt16_for_zero_UInt16_with_GetFieldValue() - { + public override void GetInt16_for_zero_UInt16_with_GetFieldValue() => base.GetInt16_for_zero_UInt16_with_GetFieldValue(); - } [Fact(Skip = "Uint16 >> Int16")] - public override Task GetInt16_for_zero_UInt16_with_GetFieldValueAsync() - { - return base.GetInt16_for_zero_UInt16_with_GetFieldValueAsync(); - } + public override Task GetInt16_for_zero_UInt16_with_GetFieldValueAsync() => + base.GetInt16_for_zero_UInt16_with_GetFieldValueAsync(); [Fact(Skip = "Int32 >> Int16")] - public override void GetInt16_throws_for_maximum_Int32() - { - base.GetInt16_throws_for_maximum_Int32(); - } + public override void GetInt16_throws_for_maximum_Int32() => base.GetInt16_throws_for_maximum_Int32(); [Fact(Skip = "Int32 >> Int16")] - public override void GetInt16_throws_for_maximum_Int32_with_GetFieldValue() - { + public override void GetInt16_throws_for_maximum_Int32_with_GetFieldValue() => base.GetInt16_throws_for_maximum_Int32_with_GetFieldValue(); - } [Fact(Skip = "Int32 >> Int16")] - public override Task GetInt16_throws_for_maximum_Int32_with_GetFieldValueAsync() - { - return base.GetInt16_throws_for_maximum_Int32_with_GetFieldValueAsync(); - } + public override Task GetInt16_throws_for_maximum_Int32_with_GetFieldValueAsync() => + base.GetInt16_throws_for_maximum_Int32_with_GetFieldValueAsync(); [Fact(Skip = "Int64 >> Int16")] - public override void GetInt16_throws_for_maximum_Int64() - { - base.GetInt16_throws_for_maximum_Int64(); - } + public override void GetInt16_throws_for_maximum_Int64() => base.GetInt16_throws_for_maximum_Int64(); [Fact(Skip = "Int64 >> Int16")] - public override void GetInt16_throws_for_maximum_Int64_with_GetFieldValue() - { + public override void GetInt16_throws_for_maximum_Int64_with_GetFieldValue() => base.GetInt16_throws_for_maximum_Int64_with_GetFieldValue(); - } [Fact(Skip = "Int64 >> Int16")] - public override Task GetInt16_throws_for_maximum_Int64_with_GetFieldValueAsync() - { - return base.GetInt16_throws_for_maximum_Int64_with_GetFieldValueAsync(); - } + public override Task GetInt16_throws_for_maximum_Int64_with_GetFieldValueAsync() => + base.GetInt16_throws_for_maximum_Int64_with_GetFieldValueAsync(); [Fact(Skip = "Uint16 >> Int16")] - public override void GetInt16_throws_for_maximum_UInt16() - { - base.GetInt16_throws_for_maximum_UInt16(); - } + public override void GetInt16_throws_for_maximum_UInt16() => base.GetInt16_throws_for_maximum_UInt16(); [Fact(Skip = "Uint16 >> Int16")] - public override void GetInt16_throws_for_maximum_UInt16_with_GetFieldValue() - { + public override void GetInt16_throws_for_maximum_UInt16_with_GetFieldValue() => base.GetInt16_throws_for_maximum_UInt16_with_GetFieldValue(); - } [Fact(Skip = "Uint16 >> Int16")] - public override Task GetInt16_throws_for_maximum_UInt16_with_GetFieldValueAsync() - { - return base.GetInt16_throws_for_maximum_UInt16_with_GetFieldValueAsync(); - } + public override Task GetInt16_throws_for_maximum_UInt16_with_GetFieldValueAsync() => + base.GetInt16_throws_for_maximum_UInt16_with_GetFieldValueAsync(); [Fact(Skip = "Int32 >> Int16")] - public override void GetInt16_throws_for_minimum_Int32() - { - base.GetInt16_throws_for_minimum_Int32(); - } + public override void GetInt16_throws_for_minimum_Int32() => base.GetInt16_throws_for_minimum_Int32(); [Fact(Skip = "Int32 >> Int16")] - public override void GetInt16_throws_for_minimum_Int32_with_GetFieldValue() - { + public override void GetInt16_throws_for_minimum_Int32_with_GetFieldValue() => base.GetInt16_throws_for_minimum_Int32_with_GetFieldValue(); - } [Fact(Skip = "Int32 >> Int16")] - public override Task GetInt16_throws_for_minimum_Int32_with_GetFieldValueAsync() - { - return base.GetInt16_throws_for_minimum_Int32_with_GetFieldValueAsync(); - } + public override Task GetInt16_throws_for_minimum_Int32_with_GetFieldValueAsync() => + base.GetInt16_throws_for_minimum_Int32_with_GetFieldValueAsync(); [Fact(Skip = "Int64 >> Int16")] - public override void GetInt16_throws_for_minimum_Int64() - { - base.GetInt16_throws_for_minimum_Int64(); - } + public override void GetInt16_throws_for_minimum_Int64() => base.GetInt16_throws_for_minimum_Int64(); [Fact(Skip = "Int64 >> Int16")] - public override void GetInt16_throws_for_minimum_Int64_with_GetFieldValue() - { + public override void GetInt16_throws_for_minimum_Int64_with_GetFieldValue() => base.GetInt16_throws_for_minimum_Int64_with_GetFieldValue(); - } [Fact(Skip = "Int64 >> Int16")] - public override Task GetInt16_throws_for_minimum_Int64_with_GetFieldValueAsync() - { - return base.GetInt16_throws_for_minimum_Int64_with_GetFieldValueAsync(); - } + public override Task GetInt16_throws_for_minimum_Int64_with_GetFieldValueAsync() => + base.GetInt16_throws_for_minimum_Int64_with_GetFieldValueAsync(); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt32_for_maximum_Int16_with_GetFieldValue() - { + public override void GetInt32_for_maximum_Int16_with_GetFieldValue() => base.GetInt32_for_maximum_Int16_with_GetFieldValue(); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt32_for_maximum_Int16_with_GetFieldValueAsync() - { - return base.GetInt32_for_maximum_Int16_with_GetFieldValueAsync(); - } + public override Task GetInt32_for_maximum_Int16_with_GetFieldValueAsync() => + base.GetInt32_for_maximum_Int16_with_GetFieldValueAsync(); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt32_for_maximum_UInt16_with_GetFieldValue() - { + public override void GetInt32_for_maximum_UInt16_with_GetFieldValue() => base.GetInt32_for_maximum_UInt16_with_GetFieldValue(); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt32_for_maximum_UInt16_with_GetFieldValueAsync() - { - return base.GetInt32_for_maximum_UInt16_with_GetFieldValueAsync(); - } + public override Task GetInt32_for_maximum_UInt16_with_GetFieldValueAsync() => + base.GetInt32_for_maximum_UInt16_with_GetFieldValueAsync(); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt32_for_minimum_Int16_with_GetFieldValue() - { + public override void GetInt32_for_minimum_Int16_with_GetFieldValue() => base.GetInt32_for_minimum_Int16_with_GetFieldValue(); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt32_for_minimum_Int16_with_GetFieldValueAsync() - { - return base.GetInt32_for_minimum_Int16_with_GetFieldValueAsync(); - } + public override Task GetInt32_for_minimum_Int16_with_GetFieldValueAsync() => + base.GetInt32_for_minimum_Int16_with_GetFieldValueAsync(); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt32_for_minimum_UInt16_with_GetFieldValue() - { + public override void GetInt32_for_minimum_UInt16_with_GetFieldValue() => base.GetInt32_for_minimum_Int16_with_GetFieldValue(); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt32_for_minimum_UInt16_with_GetFieldValueAsync() - { - return base.GetInt32_for_minimum_UInt16_with_GetFieldValueAsync(); - } + public override Task GetInt32_for_minimum_UInt16_with_GetFieldValueAsync() => + base.GetInt32_for_minimum_UInt16_with_GetFieldValueAsync(); [Fact(Skip = "Uint32 >> Int32")] - public override void GetInt32_for_minimum_UInt32() - { - base.GetInt32_for_minimum_UInt32(); - } + public override void GetInt32_for_minimum_UInt32() => base.GetInt32_for_minimum_UInt32(); [Fact(Skip = "Int64 >> Int16")] - public override void GetInt32_for_minimum_UInt32_with_GetFieldValue() - { + public override void GetInt32_for_minimum_UInt32_with_GetFieldValue() => base.GetInt32_for_minimum_UInt32_with_GetFieldValue(); - } [Fact(Skip = "Int64 >> Int16")] - public override Task GetInt32_for_minimum_UInt32_with_GetFieldValueAsync() - { - return base.GetInt32_for_minimum_UInt32_with_GetFieldValueAsync(); - } + public override Task GetInt32_for_minimum_UInt32_with_GetFieldValueAsync() => + base.GetInt32_for_minimum_UInt32_with_GetFieldValueAsync(); [Fact(Skip = "Int64 >> Int32")] - public override void GetInt32_for_one_Int64() - { - base.GetInt16_for_one_Int64(); - } + public override void GetInt32_for_one_Int64() => base.GetInt16_for_one_Int64(); [Fact(Skip = "Int64 >> Int32")] - public override void GetInt32_for_one_Int64_with_GetFieldValue() - { + public override void GetInt32_for_one_Int64_with_GetFieldValue() => base.GetInt32_for_one_Int64_with_GetFieldValue(); - } [Fact(Skip = "Int64 >> Int32")] - public override Task GetInt32_for_one_Int64_with_GetFieldValueAsync() - { - return base.GetInt32_for_one_Int64_with_GetFieldValueAsync(); - } + public override Task GetInt32_for_one_Int64_with_GetFieldValueAsync() => + base.GetInt32_for_one_Int64_with_GetFieldValueAsync(); [Fact(Skip = "Uint32 >> Int32")] - public override void GetInt32_for_one_UInt32() - { - base.GetInt32_for_one_UInt32(); - } + public override void GetInt32_for_one_UInt32() => base.GetInt32_for_one_UInt32(); [Fact(Skip = "Uint32 >> Int32")] - public override void GetInt32_for_one_UInt32_with_GetFieldValue() - { + public override void GetInt32_for_one_UInt32_with_GetFieldValue() => base.GetInt32_for_one_UInt32_with_GetFieldValue(); - } [Fact(Skip = "Uint32 >> Int32")] - public override Task GetInt32_for_one_UInt32_with_GetFieldValueAsync() - { - return base.GetInt32_for_one_UInt32_with_GetFieldValueAsync(); - } + public override Task GetInt32_for_one_UInt32_with_GetFieldValueAsync() => + base.GetInt32_for_one_UInt32_with_GetFieldValueAsync(); [Fact(Skip = "UInt64 >> Int64")] - public override void GetInt64_throws_for_maximum_UInt64() - { - base.GetInt64_throws_for_maximum_UInt64(); - } + public override void GetInt64_throws_for_maximum_UInt64() => base.GetInt64_throws_for_maximum_UInt64(); [Fact(Skip = "UInt64 >> Int64")] - public override void GetInt64_throws_for_maximum_UInt64_with_GetFieldValue() - { + public override void GetInt64_throws_for_maximum_UInt64_with_GetFieldValue() => base.GetInt64_throws_for_maximum_UInt64_with_GetFieldValue(); - } [Fact(Skip = "UInt64 >> Int64")] - public override Task GetInt64_throws_for_maximum_UInt64_with_GetFieldValueAsync() - { - return base.GetInt64_throws_for_maximum_UInt64_with_GetFieldValueAsync(); - } + public override Task GetInt64_throws_for_maximum_UInt64_with_GetFieldValueAsync() => + base.GetInt64_throws_for_maximum_UInt64_with_GetFieldValueAsync(); [Fact(Skip = "UInt64 >> Int64")] - public override void GetInt64_for_zero_UInt64() - { - base.GetInt64_for_zero_UInt64(); - } + public override void GetInt64_for_zero_UInt64() => base.GetInt64_for_zero_UInt64(); [Fact(Skip = "UInt64 >> Int64")] - public override void GetInt64_for_zero_UInt64_with_GetFieldValue() - { + public override void GetInt64_for_zero_UInt64_with_GetFieldValue() => base.GetInt64_for_zero_UInt64_with_GetFieldValue(); - } [Fact(Skip = "UInt64 >> Int64")] - public override Task GetInt64_for_zero_UInt64_with_GetFieldValueAsync() - { - return base.GetInt64_for_zero_UInt64_with_GetFieldValueAsync(); - } + public override Task GetInt64_for_zero_UInt64_with_GetFieldValueAsync() => + base.GetInt64_for_zero_UInt64_with_GetFieldValueAsync(); [Fact(Skip = "UInt64 >> Int64")] - public override void GetInt64_for_one_UInt64() - { - base.GetInt64_for_one_UInt64(); - } + public override void GetInt64_for_one_UInt64() => base.GetInt64_for_one_UInt64(); [Fact(Skip = "UInt64 >> Int64")] - public override void GetInt64_for_one_UInt64_with_GetFieldValue() - { + public override void GetInt64_for_one_UInt64_with_GetFieldValue() => base.GetInt64_for_one_UInt64_with_GetFieldValue(); - } [Fact(Skip = "UInt64 >> Int64")] - public override Task GetInt64_for_one_UInt64_with_GetFieldValueAsync() - { - return base.GetInt64_for_one_UInt64_with_GetFieldValueAsync(); - } + public override Task GetInt64_for_one_UInt64_with_GetFieldValueAsync() => + base.GetInt64_for_one_UInt64_with_GetFieldValueAsync(); [Fact(Skip = "UInt64 >> Int64")] - public override void GetInt64_for_minimum_UInt64() - { - base.GetInt64_for_minimum_UInt64(); - } + public override void GetInt64_for_minimum_UInt64() => base.GetInt64_for_minimum_UInt64(); [Fact(Skip = "UInt64 >> Int64")] - public override void GetInt64_for_minimum_UInt64_with_GetFieldValue() - { + public override void GetInt64_for_minimum_UInt64_with_GetFieldValue() => base.GetInt64_for_minimum_UInt64_with_GetFieldValue(); - } [Fact(Skip = "UInt64 >> Int64")] - public override Task GetInt64_for_minimum_UInt64_with_GetFieldValueAsync() - { - return base.GetInt64_for_minimum_UInt64_with_GetFieldValueAsync(); - } + public override Task GetInt64_for_minimum_UInt64_with_GetFieldValueAsync() => + base.GetInt64_for_minimum_UInt64_with_GetFieldValueAsync(); - public override void GetInt32_throws_for_maximum_Int64() - { - TestException(DbType.Int64, ValueKind.Maximum, x => x.GetInt32(0), typeof(InvalidCastException)); - } + public override void GetInt32_throws_for_maximum_Int64() => TestException(DbType.Int64, ValueKind.Maximum, + x => x.GetInt32(0), typeof(InvalidCastException)); - public override void GetInt32_for_zero_Int64() - { - TestException(DbType.Int64, ValueKind.Zero, x => x.GetInt32(0), typeof(InvalidCastException)); - } + public override void GetInt32_for_zero_Int64() => TestException(DbType.Int64, ValueKind.Zero, x => x.GetInt32(0), + typeof(InvalidCastException)); [Fact(Skip = "Uint32 >> Int32")] - public override void GetInt32_for_zero_UInt32() - { - base.GetInt32_for_zero_UInt32(); - } + public override void GetInt32_for_zero_UInt32() => base.GetInt32_for_zero_UInt32(); [Fact(Skip = "Uint32 >> Int32")] - public override void GetInt32_for_zero_UInt32_with_GetFieldValue() - { + public override void GetInt32_for_zero_UInt32_with_GetFieldValue() => base.GetInt32_for_zero_UInt32_with_GetFieldValue(); - } [Fact(Skip = "Uint32 >> Int32")] - public override Task GetInt32_for_zero_UInt32_with_GetFieldValueAsync() - { - return base.GetInt32_for_zero_UInt32_with_GetFieldValueAsync(); - } + public override Task GetInt32_for_zero_UInt32_with_GetFieldValueAsync() => + base.GetInt32_for_zero_UInt32_with_GetFieldValueAsync(); - public override void GetInt32_throws_for_maximum_UInt32() - { - TestException(DbType.UInt32, ValueKind.Maximum, x => x.GetInt32(0), typeof(InvalidCastException)); - } + public override void GetInt32_throws_for_maximum_UInt32() => TestException(DbType.UInt32, ValueKind.Maximum, + x => x.GetInt32(0), typeof(InvalidCastException)); - public override void GetInt32_throws_for_maximum_UInt32_with_GetFieldValue() - { - TestException(DbType.UInt32, ValueKind.Maximum, x => x.GetFieldValue(0), typeof(InvalidCastException)); - } + public override void GetInt32_throws_for_maximum_UInt32_with_GetFieldValue() => TestException(DbType.UInt32, + ValueKind.Maximum, x => x.GetFieldValue(0), typeof(InvalidCastException)); - public override async Task GetInt32_throws_for_maximum_UInt32_with_GetFieldValueAsync() - { + public override async Task GetInt32_throws_for_maximum_UInt32_with_GetFieldValueAsync() => await TestExceptionAsync(DbType.UInt32, ValueKind.Maximum, async x => await x.GetFieldValueAsync(0), typeof(InvalidCastException)); - } - public override Task GetInt32_throws_for_maximum_Int64_with_GetFieldValueAsync() - { - return TestExceptionAsync(DbType.Int64, ValueKind.Maximum, async x => await x.GetFieldValueAsync(0), + public override Task GetInt32_throws_for_maximum_Int64_with_GetFieldValueAsync() => + TestExceptionAsync(DbType.Int64, ValueKind.Maximum, async x => await x.GetFieldValueAsync(0), typeof(InvalidCastException)); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt32_for_one_Int16_with_GetFieldValue() - { + public override void GetInt32_for_one_Int16_with_GetFieldValue() => TestGetValue(DbType.Int16, ValueKind.One, x => x.GetFieldValue(0), 1); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt32_for_one_Int16_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.Int16, ValueKind.One, async x => await x.GetFieldValueAsync(0), 1); - } + public override Task GetInt32_for_one_Int16_with_GetFieldValueAsync() => TestGetValueAsync(DbType.Int16, + ValueKind.One, async x => await x.GetFieldValueAsync(0), 1); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt32_for_one_UInt16_with_GetFieldValue() - { + public override void GetInt32_for_one_UInt16_with_GetFieldValue() => TestGetValue(DbType.UInt16, ValueKind.One, x => x.GetFieldValue(0), 1); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt32_for_one_UInt16_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.UInt16, ValueKind.One, async x => await x.GetFieldValueAsync(0), 1); - } + public override Task GetInt32_for_one_UInt16_with_GetFieldValueAsync() => TestGetValueAsync(DbType.UInt16, + ValueKind.One, async x => await x.GetFieldValueAsync(0), 1); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt32_for_zero_Int16_with_GetFieldValue() - { + public override void GetInt32_for_zero_Int16_with_GetFieldValue() => base.GetInt32_for_zero_Int16_with_GetFieldValue(); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt32_for_zero_Int16_with_GetFieldValueAsync() - { - return base.GetInt32_for_zero_Int16_with_GetFieldValueAsync(); - } + public override Task GetInt32_for_zero_Int16_with_GetFieldValueAsync() => + base.GetInt32_for_zero_Int16_with_GetFieldValueAsync(); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt32_for_zero_Int64_with_GetFieldValue() - { + public override void GetInt32_for_zero_Int64_with_GetFieldValue() => base.GetInt32_for_zero_Int64_with_GetFieldValue(); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt32_for_zero_Int64_with_GetFieldValueAsync() - { - return base.GetInt32_for_zero_Int64_with_GetFieldValueAsync(); - } + public override Task GetInt32_for_zero_Int64_with_GetFieldValueAsync() => + base.GetInt32_for_zero_Int64_with_GetFieldValueAsync(); - public override void GetInt32_throws_for_minimum_Int64() - { - TestException(DbType.Int64, ValueKind.Minimum, x => x.GetInt32(0), typeof(InvalidCastException)); - } + public override void GetInt32_throws_for_minimum_Int64() => TestException(DbType.Int64, ValueKind.Minimum, + x => x.GetInt32(0), typeof(InvalidCastException)); - public override void GetInt32_throws_for_minimum_Int64_with_GetFieldValue() - { - TestException(DbType.Int64, ValueKind.Minimum, x => x.GetFieldValue(0), typeof(InvalidCastException)); - } + public override void GetInt32_throws_for_minimum_Int64_with_GetFieldValue() => TestException(DbType.Int64, + ValueKind.Minimum, x => x.GetFieldValue(0), typeof(InvalidCastException)); - public override Task GetInt32_throws_for_minimum_Int64_with_GetFieldValueAsync() - { - return TestExceptionAsync(DbType.Int64, ValueKind.Minimum, async x => await x.GetFieldValueAsync(0), + public override Task GetInt32_throws_for_minimum_Int64_with_GetFieldValueAsync() => + TestExceptionAsync(DbType.Int64, ValueKind.Minimum, async x => await x.GetFieldValueAsync(0), typeof(InvalidCastException)); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt32_for_zero_UInt16_with_GetFieldValue() - { + public override void GetInt32_for_zero_UInt16_with_GetFieldValue() => TestGetValue(DbType.UInt16, ValueKind.Zero, x => x.GetFieldValue(0), 0); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt32_for_zero_UInt16_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.UInt16, ValueKind.Zero, async x => await x.GetFieldValueAsync(0), 0); - } + public override Task GetInt32_for_zero_UInt16_with_GetFieldValueAsync() => TestGetValueAsync(DbType.UInt16, + ValueKind.Zero, async x => await x.GetFieldValueAsync(0), 0); - public override void GetInt32_throws_for_maximum_Int64_with_GetFieldValue() - { - TestException(DbType.Int64, ValueKind.Maximum, x => x.GetFieldValue(0), typeof(InvalidCastException)); - } + public override void GetInt32_throws_for_maximum_Int64_with_GetFieldValue() => TestException(DbType.Int64, + ValueKind.Maximum, x => x.GetFieldValue(0), typeof(InvalidCastException)); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt64_for_maximum_Int16_with_GetFieldValue() - { + public override void GetInt64_for_maximum_Int16_with_GetFieldValue() => base.GetInt64_for_maximum_Int16_with_GetFieldValue(); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt64_for_maximum_Int16_with_GetFieldValueAsync() - { - return base.GetInt64_for_maximum_Int16_with_GetFieldValueAsync(); - } + public override Task GetInt64_for_maximum_Int16_with_GetFieldValueAsync() => + base.GetInt64_for_maximum_Int16_with_GetFieldValueAsync(); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt64_for_maximum_Int32_with_GetFieldValue() - { - TestGetValue(DbType.Int32, ValueKind.Maximum, x => x.GetFieldValue(0), 2147483647L); - } + public override void GetInt64_for_maximum_Int32_with_GetFieldValue() => TestGetValue(DbType.Int32, + ValueKind.Maximum, x => x.GetFieldValue(0), 2147483647L); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt64_for_maximum_Int32_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.Int32, ValueKind.Maximum, async x => await x.GetFieldValueAsync(0), + public override Task GetInt64_for_maximum_Int32_with_GetFieldValueAsync() => + TestGetValueAsync(DbType.Int32, ValueKind.Maximum, async x => await x.GetFieldValueAsync(0), 2147483647L); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt64_for_maximum_UInt16_with_GetFieldValue() - { + public override void GetInt64_for_maximum_UInt16_with_GetFieldValue() => TestGetValue(DbType.UInt16, ValueKind.Maximum, x => x.GetFieldValue(0), 65535L); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt64_for_maximum_UInt16_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.UInt16, ValueKind.Maximum, async x => await x.GetFieldValueAsync(0), + public override Task GetInt64_for_maximum_UInt16_with_GetFieldValueAsync() => + TestGetValueAsync(DbType.UInt16, ValueKind.Maximum, async x => await x.GetFieldValueAsync(0), 65535L); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt64_for_minimum_Int16_with_GetFieldValue() - { + public override void GetInt64_for_minimum_Int16_with_GetFieldValue() => TestGetValue(DbType.Int16, ValueKind.Minimum, x => x.GetFieldValue(0), -32768L); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt64_for_minimum_Int16_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.Int16, ValueKind.Minimum, async x => await x.GetFieldValueAsync(0), + public override Task GetInt64_for_minimum_Int16_with_GetFieldValueAsync() => + TestGetValueAsync(DbType.Int16, ValueKind.Minimum, async x => await x.GetFieldValueAsync(0), -32768L); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt64_for_minimum_Int32_with_GetFieldValue() - { - TestGetValue(DbType.Int32, ValueKind.Minimum, x => x.GetFieldValue(0), -2147483648L); - } + public override void GetInt64_for_minimum_Int32_with_GetFieldValue() => TestGetValue(DbType.Int32, + ValueKind.Minimum, x => x.GetFieldValue(0), -2147483648L); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt64_for_minimum_Int32_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.Int32, ValueKind.Minimum, async x => await x.GetFieldValueAsync(0), + public override Task GetInt64_for_minimum_Int32_with_GetFieldValueAsync() => + TestGetValueAsync(DbType.Int32, ValueKind.Minimum, async x => await x.GetFieldValueAsync(0), -2147483648L); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt64_for_minimum_UInt16_with_GetFieldValue() - { + public override void GetInt64_for_minimum_UInt16_with_GetFieldValue() => TestGetValue(DbType.UInt16, ValueKind.Minimum, x => x.GetFieldValue(0), 0L); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt64_for_minimum_UInt16_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.UInt16, ValueKind.Minimum, async x => await x.GetFieldValueAsync(0), 0L); - } + public override Task GetInt64_for_minimum_UInt16_with_GetFieldValueAsync() => TestGetValueAsync(DbType.UInt16, + ValueKind.Minimum, async x => await x.GetFieldValueAsync(0), 0L); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt64_for_one_Int16_with_GetFieldValue() - { + public override void GetInt64_for_one_Int16_with_GetFieldValue() => TestGetValue(DbType.Int16, ValueKind.One, x => x.GetFieldValue(0), 1L); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt64_for_one_Int16_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.Int16, ValueKind.One, async x => await x.GetFieldValueAsync(0), 1L); - } + public override Task GetInt64_for_one_Int16_with_GetFieldValueAsync() => TestGetValueAsync(DbType.Int16, + ValueKind.One, async x => await x.GetFieldValueAsync(0), 1L); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt64_for_one_Int32_with_GetFieldValue() - { + public override void GetInt64_for_one_Int32_with_GetFieldValue() => TestGetValue(DbType.Int32, ValueKind.One, x => x.GetFieldValue(0), 1L); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt64_for_one_Int32_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.Int32, ValueKind.One, async x => await x.GetFieldValueAsync(0), 1L); - } + public override Task GetInt64_for_one_Int32_with_GetFieldValueAsync() => TestGetValueAsync(DbType.Int32, + ValueKind.One, async x => await x.GetFieldValueAsync(0), 1L); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt64_for_one_UInt16_with_GetFieldValue() - { + public override void GetInt64_for_one_UInt16_with_GetFieldValue() => TestGetValue(DbType.UInt16, ValueKind.One, x => x.GetFieldValue(0), 1L); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt64_for_one_UInt16_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.UInt16, ValueKind.One, async x => await x.GetFieldValueAsync(0), 1L); - } + public override Task GetInt64_for_one_UInt16_with_GetFieldValueAsync() => TestGetValueAsync(DbType.UInt16, + ValueKind.One, async x => await x.GetFieldValueAsync(0), 1L); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt64_for_zero_Int16_with_GetFieldValue() - { + public override void GetInt64_for_zero_Int16_with_GetFieldValue() => TestGetValue(DbType.Int16, ValueKind.Zero, x => x.GetFieldValue(0), 0L); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt64_for_zero_Int16_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.Int16, ValueKind.Zero, async x => await x.GetFieldValueAsync(0), 0L); - } + public override Task GetInt64_for_zero_Int16_with_GetFieldValueAsync() => TestGetValueAsync(DbType.Int16, + ValueKind.Zero, async x => await x.GetFieldValueAsync(0), 0L); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt64_for_zero_Int32_with_GetFieldValue() - { + public override void GetInt64_for_zero_Int32_with_GetFieldValue() => TestGetValue(DbType.Int32, ValueKind.Zero, x => x.GetFieldValue(0), 0L); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt64_for_zero_Int32_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.Int32, ValueKind.Zero, async x => await x.GetFieldValueAsync(0), 0L); - } + public override Task GetInt64_for_zero_Int32_with_GetFieldValueAsync() => TestGetValueAsync(DbType.Int32, + ValueKind.Zero, async x => await x.GetFieldValueAsync(0), 0L); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetInt64_for_zero_UInt16_with_GetFieldValue() - { + public override void GetInt64_for_zero_UInt16_with_GetFieldValue() => TestGetValue(DbType.UInt16, ValueKind.Zero, x => x.GetFieldValue(0), 0L); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetInt64_for_zero_UInt16_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.UInt16, ValueKind.Zero, async x => await x.GetFieldValueAsync(0), 0L); - } + public override Task GetInt64_for_zero_UInt16_with_GetFieldValueAsync() => TestGetValueAsync(DbType.UInt16, + ValueKind.Zero, async x => await x.GetFieldValueAsync(0), 0L); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetDouble_for_zero_Single_with_GetFieldValueAsync() - { - return base.GetDouble_for_zero_Single_with_GetFieldValueAsync(); - } + public override Task GetDouble_for_zero_Single_with_GetFieldValueAsync() => + base.GetDouble_for_zero_Single_with_GetFieldValueAsync(); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetDouble_for_zero_Single_with_GetFieldValue() - { + public override void GetDouble_for_zero_Single_with_GetFieldValue() => base.GetDouble_for_zero_Single_with_GetFieldValue(); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetDouble_for_maximum_Single_with_GetFieldValue() - { - TestGetValue(DbType.Single, ValueKind.Maximum, x => x.GetFieldValue(0), 3.3999999521443642E+38); - } + public override void GetDouble_for_maximum_Single_with_GetFieldValue() => TestGetValue(DbType.Single, + ValueKind.Maximum, x => x.GetFieldValue(0), 3.3999999521443642E+38); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetDouble_for_maximum_Single_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.Single, ValueKind.Maximum, async x => await x.GetFieldValueAsync(0), + public override Task GetDouble_for_maximum_Single_with_GetFieldValueAsync() => + TestGetValueAsync(DbType.Single, ValueKind.Maximum, async x => await x.GetFieldValueAsync(0), 3.3999999521443642E+38); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetDouble_for_one_Single_with_GetFieldValue() - { + public override void GetDouble_for_one_Single_with_GetFieldValue() => TestGetValue(DbType.Single, ValueKind.One, x => x.GetFieldValue(0), 1.0); - } [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetDouble_for_one_Single_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.Single, ValueKind.One, async x => await x.GetFieldValueAsync(0), 1.0); - } + public override Task GetDouble_for_one_Single_with_GetFieldValueAsync() => TestGetValueAsync(DbType.Single, + ValueKind.One, async x => await x.GetFieldValueAsync(0), 1.0); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override void GetDouble_for_minimum_Single_with_GetFieldValue() - { - TestGetValue(DbType.Single, ValueKind.Minimum, x => x.GetFieldValue(0), 1.1799999457746311E-38); - } + public override void GetDouble_for_minimum_Single_with_GetFieldValue() => TestGetValue(DbType.Single, + ValueKind.Minimum, x => x.GetFieldValue(0), 1.1799999457746311E-38); [Fact(Skip = "Method GetFieldValue is not fully supported")] - public override Task GetDouble_for_minimum_Single_with_GetFieldValueAsync() - { - return TestGetValueAsync(DbType.Single, ValueKind.Minimum, async x => await x.GetFieldValueAsync(0), + public override Task GetDouble_for_minimum_Single_with_GetFieldValueAsync() => + TestGetValueAsync(DbType.Single, ValueKind.Minimum, async x => await x.GetFieldValueAsync(0), 1.1799999457746311E-38); - } #pragma warning restore xUnit1004 protected override async Task OnInitializeAsync() diff --git a/src/Ydb.Sdk/tests/Ado/Specification/YdbSelectValueFixture.cs b/src/Ydb.Sdk/tests/Ado/Specification/YdbSelectValueFixture.cs index 964de6ef..00fb5993 100644 --- a/src/Ydb.Sdk/tests/Ado/Specification/YdbSelectValueFixture.cs +++ b/src/Ydb.Sdk/tests/Ado/Specification/YdbSelectValueFixture.cs @@ -6,15 +6,11 @@ namespace Ydb.Sdk.Tests.Ado.Specification; public class YdbSelectValueFixture : YdbFactoryFixture, ISelectValueFixture, IDeleteFixture { - public string CreateSelectSql(DbType dbType, ValueKind kind) - { - return $"SELECT `{dbType}` FROM `select_value_{Utils.Net}` WHERE Id = {(int)kind}"; - } + public string CreateSelectSql(DbType dbType, ValueKind kind) => + $"SELECT `{dbType}` FROM `select_value_{Utils.Net}` WHERE Id = {(int)kind}"; - public string CreateSelectSql(byte[] value) - { - return $"SELECT String::HexDecode('{BitConverter.ToString(value).Replace("-", string.Empty)}');"; - } + public string CreateSelectSql(byte[] value) => + $"SELECT String::HexDecode('{BitConverter.ToString(value).Replace("-", string.Empty)}');"; public IReadOnlyCollection SupportedDbTypes => new ReadOnlyCollection(new[] { diff --git a/src/Ydb.Sdk/tests/Ado/YdbConnectionTests.cs b/src/Ydb.Sdk/tests/Ado/YdbConnectionTests.cs index 534c8f71..74408265 100644 --- a/src/Ydb.Sdk/tests/Ado/YdbConnectionTests.cs +++ b/src/Ydb.Sdk/tests/Ado/YdbConnectionTests.cs @@ -202,21 +202,16 @@ INSERT INTO {tableName} await ydbCommand.ExecuteNonQueryAsync(); } - private List GenerateTasks() - { - return Enumerable.Range(0, 100).Select(async i => - { - await using var connection = await CreateOpenConnectionAsync(); - var command = connection.CreateCommand(); - command.CommandText = "SELECT " + i; - var scalar = (int)(await command.ExecuteScalarAsync())!; - Assert.Equal(i, scalar); - Interlocked.Add(ref _counter, scalar); - }).ToList(); - } - - protected override async Task OnDisposeAsync() + private List GenerateTasks() => Enumerable.Range(0, 100).Select(async i => { + await using var connection = await CreateOpenConnectionAsync(); + var command = connection.CreateCommand(); + command.CommandText = "SELECT " + i; + var scalar = (int)(await command.ExecuteScalarAsync())!; + Assert.Equal(i, scalar); + Interlocked.Add(ref _counter, scalar); + }).ToList(); + + protected override async Task OnDisposeAsync() => await YdbConnection.ClearPool(new YdbConnection(_connectionString)); - } } diff --git a/src/Ydb.Sdk/tests/Ado/YdbParameterTests.cs b/src/Ydb.Sdk/tests/Ado/YdbParameterTests.cs index 97d86e26..af383866 100644 --- a/src/Ydb.Sdk/tests/Ado/YdbParameterTests.cs +++ b/src/Ydb.Sdk/tests/Ado/YdbParameterTests.cs @@ -55,12 +55,10 @@ public void YdbValue_WhenDateTimeOffset_ReturnTimestamp() } [Fact] - public void YdbValue_WhenYdbValueIsSet_ReturnThis() - { + public void YdbValue_WhenYdbValueIsSet_ReturnThis() => Assert.Equal("{\"type\": \"jsondoc\"}", new YdbParameter("$parameter", YdbValue.MakeJsonDocument("{\"type\": \"jsondoc\"}")).YdbValue .GetJsonDocument()); - } [Fact] public void YdbValue_WhenUnCastTypes_ThrowInvalidCastException() @@ -82,12 +80,10 @@ public void YdbValue_WhenUnCastTypes_ThrowInvalidCastException() [InlineData(DbType.VarNumeric, "VarNumeric")] [InlineData(DbType.Xml, "Xml")] [InlineData(DbType.Time, "Time")] - public void YdbValue_WhenNoSupportedDbType_ThrowException(DbType dbType, string name) - { + public void YdbValue_WhenNoSupportedDbType_ThrowException(DbType dbType, string name) => Assert.Equal("Ydb don't supported this DbType: " + name, Assert.Throws(() => new YdbParameter("$parameter", dbType) { IsNullable = true }.YdbValue).Message); - } [Fact] public void Parameter_WhenSetAndNoSet_ReturnValueOrException() @@ -248,14 +244,8 @@ public class TestDataGenerator : IEnumerable new object[] { new Data(DbType.Decimal, null, value => value.GetOptionalDecimal()) } }; - public IEnumerator GetEnumerator() - { - return _data.GetEnumerator(); - } + public IEnumerator GetEnumerator() => _data.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } diff --git a/src/Ydb.Sdk/tests/Auth/StaticAuthTests.cs b/src/Ydb.Sdk/tests/Auth/StaticAuthTests.cs index 67c2b808..0ab51424 100644 --- a/src/Ydb.Sdk/tests/Auth/StaticAuthTests.cs +++ b/src/Ydb.Sdk/tests/Auth/StaticAuthTests.cs @@ -22,10 +22,7 @@ public StaticAuthTests(ITestOutputHelper output) _logger = _loggerFactory.CreateLogger(); } - public void Dispose() - { - GC.SuppressFinalize(this); - } + public void Dispose() => GC.SuppressFinalize(this); private async Task CreateUser(TableClient tableClient, string user, string? password) { @@ -89,23 +86,14 @@ private async Task CheckAuth(string? passwordCreate, string? passwordAuth, int m [Fact(Timeout = 5_000)] - public async Task GoodAuth() - { - await CheckAuth("test_password", "test_password"); - } + public async Task GoodAuth() => await CheckAuth("test_password", "test_password"); [Fact(Timeout = 5_000)] - public async Task NoPasswordAuth() - { - await CheckAuth(null, null); - } + public async Task NoPasswordAuth() => await CheckAuth(null, null); [Fact(Timeout = 5_000)] - public async Task WrongPassword() - { - await Assert.ThrowsAsync( - async () => await CheckAuth("good_password", "wrong_password", maxRetries: 1)); - } + public async Task WrongPassword() => await Assert.ThrowsAsync( + async () => await CheckAuth("good_password", "wrong_password", maxRetries: 1)); [Fact(Timeout = 5_000)] public async Task NotExistAuth() diff --git a/src/Ydb.Sdk/tests/Fixture/DriverFixture.cs b/src/Ydb.Sdk/tests/Fixture/DriverFixture.cs index 450de26d..4ea78b5b 100644 --- a/src/Ydb.Sdk/tests/Fixture/DriverFixture.cs +++ b/src/Ydb.Sdk/tests/Fixture/DriverFixture.cs @@ -20,10 +20,7 @@ protected virtual void ClientDispose() { } - public Task InitializeAsync() - { - return Driver.Initialize(); - } + public Task InitializeAsync() => Driver.Initialize(); public Task DisposeAsync() { diff --git a/src/Ydb.Sdk/tests/Fixture/QueryClientFixture.cs b/src/Ydb.Sdk/tests/Fixture/QueryClientFixture.cs index a50488bd..b5b07742 100644 --- a/src/Ydb.Sdk/tests/Fixture/QueryClientFixture.cs +++ b/src/Ydb.Sdk/tests/Fixture/QueryClientFixture.cs @@ -12,8 +12,5 @@ public QueryClientFixture() QueryClient = new QueryClient(Driver); } - protected override void ClientDispose() - { - QueryClient.DisposeAsync().AsTask().Wait(); - } + protected override void ClientDispose() => QueryClient.DisposeAsync().AsTask().Wait(); } diff --git a/src/Ydb.Sdk/tests/Fixture/TableClientFixture.cs b/src/Ydb.Sdk/tests/Fixture/TableClientFixture.cs index 1620c204..1fac1e36 100644 --- a/src/Ydb.Sdk/tests/Fixture/TableClientFixture.cs +++ b/src/Ydb.Sdk/tests/Fixture/TableClientFixture.cs @@ -12,8 +12,5 @@ public TableClientFixture() TableClient = new TableClient(Driver); } - protected override void ClientDispose() - { - TableClient.Dispose(); - } + protected override void ClientDispose() => TableClient.Dispose(); } diff --git a/src/Ydb.Sdk/tests/Fixture/YdbAdoNetFixture.cs b/src/Ydb.Sdk/tests/Fixture/YdbAdoNetFixture.cs index 550ca74d..acb50aeb 100644 --- a/src/Ydb.Sdk/tests/Fixture/YdbAdoNetFixture.cs +++ b/src/Ydb.Sdk/tests/Fixture/YdbAdoNetFixture.cs @@ -10,15 +10,9 @@ protected YdbAdoNetFixture(YdbFactoryFixture fixture) : base(fixture) { } - protected override YdbConnection CreateConnection() - { - return (YdbConnection)base.CreateConnection(); - } + protected override YdbConnection CreateConnection() => (YdbConnection)base.CreateConnection(); - protected override YdbConnection CreateOpenConnection() - { - return (YdbConnection)base.CreateOpenConnection(); - } + protected override YdbConnection CreateOpenConnection() => (YdbConnection)base.CreateOpenConnection(); protected async Task CreateOpenConnectionAsync() { diff --git a/src/Ydb.Sdk/tests/Pool/EndpointPoolTests.cs b/src/Ydb.Sdk/tests/Pool/EndpointPoolTests.cs index bce9a3c2..cad6ff08 100644 --- a/src/Ydb.Sdk/tests/Pool/EndpointPoolTests.cs +++ b/src/Ydb.Sdk/tests/Pool/EndpointPoolTests.cs @@ -34,10 +34,8 @@ public MockRandomUnitTests() [InlineData(3, "n3.ydb.tech")] [InlineData(4, "n4.ydb.tech")] [InlineData(5, "n5.ydb.tech")] - public void GetEndpoint_WhenResetNewState_ReturnEndpointByNodeId(int nodeId, string endpoint) - { + public void GetEndpoint_WhenResetNewState_ReturnEndpointByNodeId(int nodeId, string endpoint) => Assert.Equal(endpoint, _endpointPool.GetEndpoint(nodeId)); - } [Theory] [InlineData(1, "n1.ydb.tech")] diff --git a/src/Ydb.Sdk/tests/Pool/SessionPoolTests.cs b/src/Ydb.Sdk/tests/Pool/SessionPoolTests.cs index df351aa6..c9ee5f6e 100644 --- a/src/Ydb.Sdk/tests/Pool/SessionPoolTests.cs +++ b/src/Ydb.Sdk/tests/Pool/SessionPoolTests.cs @@ -15,10 +15,8 @@ public class SessionPoolTests private readonly TestSessionPool _testSessionPool = new(); [Fact] - public void GetSession_WhenRaceConditionThenRelease_CreateSuccessSessionIsCalledWithSizeLimit() - { + public void GetSession_WhenRaceConditionThenRelease_CreateSuccessSessionIsCalledWithSizeLimit() => StressTestSessionPoolAndCheckCreatedSessions(10_000, TestSessionPoolSize); - } [Fact] public async Task GetSession_WhenCreateSessionReturnUnavailable_ExpectedStatusAndReleaseSessionInPool() @@ -107,8 +105,5 @@ internal TestSession(SessionPool sessionPool) { } - internal override Task DeleteSession() - { - return Task.FromResult(new Status(StatusCode.Success)); - } + internal override Task DeleteSession() => Task.FromResult(new Status(StatusCode.Success)); } diff --git a/src/Ydb.Sdk/tests/Query/QueryIntegrationTests.cs b/src/Ydb.Sdk/tests/Query/QueryIntegrationTests.cs index 169b3436..75eb2423 100644 --- a/src/Ydb.Sdk/tests/Query/QueryIntegrationTests.cs +++ b/src/Ydb.Sdk/tests/Query/QueryIntegrationTests.cs @@ -236,8 +236,5 @@ public async Task InitializeAsync() await _queryClient.Exec(Tables.UpsertData); } - public async Task DisposeAsync() - { - await _queryClient.Exec(Tables.DeleteTables); - } + public async Task DisposeAsync() => await _queryClient.Exec(Tables.DeleteTables); } diff --git a/src/Ydb.Sdk/tests/Table/TruncatedTests.cs b/src/Ydb.Sdk/tests/Table/TruncatedTests.cs index bbeb616e..82f740ce 100644 --- a/src/Ydb.Sdk/tests/Table/TruncatedTests.cs +++ b/src/Ydb.Sdk/tests/Table/TruncatedTests.cs @@ -49,17 +49,14 @@ await session.ExecuteDataQuery( Assert.True(response.Status.IsSuccess); } - private static YdbValue MakeData(int n) - { - return YdbValue.MakeList( - Enumerable.Range(0, n) - .Select(i => YdbValue.MakeStruct( - new Dictionary - { - { "id", (YdbValue)i } - } - )) - .ToList() - ); - } + private static YdbValue MakeData(int n) => YdbValue.MakeList( + Enumerable.Range(0, n) + .Select(i => YdbValue.MakeStruct( + new Dictionary + { + { "id", (YdbValue)i } + } + )) + .ToList() + ); } diff --git a/src/Ydb.Sdk/tests/Topic/ReaderUnitTests.cs b/src/Ydb.Sdk/tests/Topic/ReaderUnitTests.cs index 495c3ff9..81175ce4 100644 --- a/src/Ydb.Sdk/tests/Topic/ReaderUnitTests.cs +++ b/src/Ydb.Sdk/tests/Topic/ReaderUnitTests.cs @@ -1581,26 +1581,20 @@ public async Task DisposeAsync_WhenCommitMessagesInFlight_CompleteThisCommits() private class FailDeserializer : IDeserializer { - public int Deserialize(byte[] data) - { - throw new Exception("Some serialize exception"); - } + public int Deserialize(byte[] data) => throw new Exception("Some serialize exception"); } - private static FromServer StartPartitionSessionRequest(int commitedOffset = 0) + private static FromServer StartPartitionSessionRequest(int commitedOffset = 0) => new() { - return new FromServer + Status = StatusIds.Types.StatusCode.Success, + StartPartitionSessionRequest = new StreamReadMessage.Types.StartPartitionSessionRequest { - Status = StatusIds.Types.StatusCode.Success, - StartPartitionSessionRequest = new StreamReadMessage.Types.StartPartitionSessionRequest - { - CommittedOffset = commitedOffset, - PartitionOffsets = new OffsetsRange { Start = commitedOffset, End = commitedOffset + 1000 }, - PartitionSession = new StreamReadMessage.Types.PartitionSession - { Path = "/topic", PartitionId = 1, PartitionSessionId = 1 } - } - }; - } + CommittedOffset = commitedOffset, + PartitionOffsets = new OffsetsRange { Start = commitedOffset, End = commitedOffset + 1000 }, + PartitionSession = new StreamReadMessage.Types.PartitionSession + { Path = "/topic", PartitionId = 1, PartitionSessionId = 1 } + } + }; private static FromServer ReadResponse(int commitedOffset = 0, params byte[][] args) { @@ -1638,19 +1632,16 @@ private static FromServer ReadResponse(int commitedOffset = 0, params byte[][] a }; } - private static FromServer CommitOffsetResponse(int committedOffset = 1) + private static FromServer CommitOffsetResponse(int committedOffset = 1) => new() { - return new FromServer + Status = StatusIds.Types.StatusCode.Success, + CommitOffsetResponse = new StreamReadMessage.Types.CommitOffsetResponse { - Status = StatusIds.Types.StatusCode.Success, - CommitOffsetResponse = new StreamReadMessage.Types.CommitOffsetResponse + PartitionsCommittedOffsets = { - PartitionsCommittedOffsets = - { - new StreamReadMessage.Types.CommitOffsetResponse.Types.PartitionCommittedOffset - { PartitionSessionId = 1, CommittedOffset = committedOffset } - } + new StreamReadMessage.Types.CommitOffsetResponse.Types.PartitionCommittedOffset + { PartitionSessionId = 1, CommittedOffset = committedOffset } } - }; - } + } + }; } diff --git a/src/Ydb.Sdk/tests/Topic/SerializerDeserializerUnitTests.cs b/src/Ydb.Sdk/tests/Topic/SerializerDeserializerUnitTests.cs index 11d8517b..9127bfbf 100644 --- a/src/Ydb.Sdk/tests/Topic/SerializerDeserializerUnitTests.cs +++ b/src/Ydb.Sdk/tests/Topic/SerializerDeserializerUnitTests.cs @@ -6,22 +6,15 @@ namespace Ydb.Sdk.Tests.Topic; public class SerializerDeserializerUnitTests { [Fact] - public void SerializeDeserialize_WhenSerializer64Deserializer32_ReturnInt32() - { + public void SerializeDeserialize_WhenSerializer64Deserializer32_ReturnInt32() => Assert.Equal(32, Deserializers.Int32.Deserialize(Serializers.Int32.Serialize(32))); - } [Fact] - public void SerializeDeserialize_WhenSerializer64Deserializer64_ReturnInt64() - { + public void SerializeDeserialize_WhenSerializer64Deserializer64_ReturnInt64() => Assert.Equal(32 * 1_000_000_000L, Deserializers.Int64.Deserialize(Serializers.Int64.Serialize(32 * 1_000_000_000L))); - } [Fact] - public void SerializeDeserialize_WhenSerializerUtf8DeserializerUtf8_ReturnString() - { - Assert.Equal("abacaba", - Deserializers.Utf8.Deserialize(Serializers.Utf8.Serialize("abacaba"))); - } + public void SerializeDeserialize_WhenSerializerUtf8DeserializerUtf8_ReturnString() => + Assert.Equal("abacaba", Deserializers.Utf8.Deserialize(Serializers.Utf8.Serialize("abacaba"))); } diff --git a/src/Ydb.Sdk/tests/Topic/WriterUnitTests.cs b/src/Ydb.Sdk/tests/Topic/WriterUnitTests.cs index 217aec5b..131f8bf5 100644 --- a/src/Ydb.Sdk/tests/Topic/WriterUnitTests.cs +++ b/src/Ydb.Sdk/tests/Topic/WriterUnitTests.cs @@ -42,10 +42,7 @@ public WriterUnitTests() private class FailSerializer : ISerializer { - public byte[] Serialize(int data) - { - throw new Exception("Some serialize exception"); - } + public byte[] Serialize(int data) => throw new Exception("Some serialize exception"); } [Fact] @@ -949,9 +946,8 @@ public async Task DisposeAsync_WhenInFlightMessages_WaitingInFlightMessages() await writer.DisposeAsync(); } - private ISetupSequentialResult SetupReadOneWriteAckMessage() - { - return _mockStream.SetupSequence(stream => stream.Current) + private ISetupSequentialResult SetupReadOneWriteAckMessage() => + _mockStream.SetupSequence(stream => stream.Current) .Returns(new StreamWriteMessage.Types.FromServer { InitResponse = new StreamWriteMessage.Types.InitResponse @@ -975,5 +971,4 @@ public async Task DisposeAsync_WhenInFlightMessages_WaitingInFlightMessages() }, Status = StatusIds.Types.StatusCode.Success }); - } } diff --git a/src/Ydb.Sdk/tests/Utils.cs b/src/Ydb.Sdk/tests/Utils.cs index dd914563..a7099917 100644 --- a/src/Ydb.Sdk/tests/Utils.cs +++ b/src/Ydb.Sdk/tests/Utils.cs @@ -44,9 +44,8 @@ public static async Task ExecuteSchemeQuery( return (ExecuteSchemeQueryResponse)response; } - internal static ILoggerFactory GetLoggerFactory() - { - return new ServiceCollection() + internal static ILoggerFactory GetLoggerFactory() => + new ServiceCollection() .AddLogging(configure => { configure.AddConsole().SetMinimumLevel(LogLevel.Information); @@ -56,19 +55,14 @@ internal static ILoggerFactory GetLoggerFactory() }) .BuildServiceProvider() .GetService() ?? NullLoggerFactory.Instance; - } - internal static async Task CreateSimpleTable(TableClient tableClient, string tableName, string columnName = "key") - { - await ExecuteSchemeQuery( + internal static Task CreateSimpleTable(TableClient tableClient, string tableName, string columnName = "key") => + ExecuteSchemeQuery( tableClient, query: $"CREATE TABLE {tableName} ({columnName} Uint64, PRIMARY KEY ({columnName}))"); - } - internal static async Task DropTable(TableClient tableClient, string tableName) - { - await ExecuteSchemeQuery( + internal static Task DropTable(TableClient tableClient, string tableName) => + ExecuteSchemeQuery( tableClient, query: $"DROP TABLE {tableName}"); - } } diff --git a/src/Ydb.Sdk/tests/Value/YdbValueTests.cs b/src/Ydb.Sdk/tests/Value/YdbValueTests.cs index 8c23eb35..8c235db7 100644 --- a/src/Ydb.Sdk/tests/Value/YdbValueTests.cs +++ b/src/Ydb.Sdk/tests/Value/YdbValueTests.cs @@ -190,15 +190,9 @@ private class TestDataGenerator : IEnumerable { new Data(null, YdbValue.MakeOptionalJsonDocument, value => value.GetOptionalJsonDocument()) } }; - public IEnumerator GetEnumerator() - { - return _data.GetEnumerator(); - } + public IEnumerator GetEnumerator() => _data.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); }