@@ -7,31 +7,20 @@ namespace Ydb.Sdk.Tests.Ado;
77
88public class YdbAdoUserPasswordTests : YdbAdoNetFixture
99{
10+ private readonly string _user = "kurdyukovkirya" + Random . Shared . Next ( ) ;
11+
1012 public YdbAdoUserPasswordTests ( YdbFactoryFixture fixture ) : base ( fixture )
1113 {
1214 }
1315
1416 [ Fact ]
1517 public async Task Authentication_WhenUserAndPassword_ReturnValidConnection ( )
1618 {
17- await using var connection = await CreateOpenConnectionAsync ( ) ;
18- var ydbCommand = connection . CreateCommand ( ) ;
19- var kurdyukovkirya = "kurdyukovkirya" + Random . Shared . Next ( ) ;
20- ydbCommand . CommandText = $ "CREATE USER { kurdyukovkirya } PASSWORD 'password'";
21- await ydbCommand . ExecuteNonQueryAsync ( ) ;
22- await connection . CloseAsync ( ) ;
23-
24- await using var userPasswordConnection =
25- new YdbConnection ( $ "{ ConnectionString } ;User={ kurdyukovkirya } ;Password=password;") ;
19+ await using var userPasswordConnection = new YdbConnection (
20+ $ "{ ConnectionString } ;User={ _user } ;Password=password;") ;
2621 await userPasswordConnection . OpenAsync ( ) ;
27- ydbCommand = userPasswordConnection . CreateCommand ( ) ;
28- ydbCommand . CommandText = "SELECT 1 + 2" ;
29- Assert . Equal ( 3 , await ydbCommand . ExecuteScalarAsync ( ) ) ;
30-
31- await using var newConnection = await CreateOpenConnectionAsync ( ) ;
32- ydbCommand = newConnection . CreateCommand ( ) ;
33- ydbCommand . CommandText = $ "DROP USER { kurdyukovkirya } ;";
34- await ydbCommand . ExecuteNonQueryAsync ( ) ;
22+ Assert . Equal ( 3 , await new YdbCommand ( userPasswordConnection )
23+ { CommandText = "SELECT 1 + 2" } . ExecuteScalarAsync ( ) ) ;
3524 }
3625
3726 [ Fact ]
@@ -45,4 +34,31 @@ public async Task ExecuteNonQueryAsync_WhenCreateUser_ReturnEmptyResultSet()
4534 dbCommand . CommandText = $ "DROP USER { user } ;";
4635 await dbCommand . ExecuteNonQueryAsync ( ) ;
4736 }
37+
38+ [ Fact ]
39+ public async Task DisableDiscovery_WhenUserIsCreatedAndPropertyIsTrue_SimpleWorking ( )
40+ {
41+ await using var userPasswordConnection = new YdbConnection (
42+ $ "{ ConnectionString } ;User={ _user } ;Password=password;DisableDiscovery=true") ;
43+ await userPasswordConnection . OpenAsync ( ) ;
44+ var ydbCommand = userPasswordConnection . CreateCommand ( ) ;
45+ ydbCommand . CommandText = "SELECT 1 + 2" ;
46+ Assert . Equal ( 3 , await ydbCommand . ExecuteScalarAsync ( ) ) ;
47+ }
48+
49+ protected override async Task OnInitializeAsync ( )
50+ {
51+ await using var connection = await CreateOpenConnectionAsync ( ) ;
52+ var ydbCommand = connection . CreateCommand ( ) ;
53+ ydbCommand . CommandText = $ "CREATE USER { _user } PASSWORD 'password'";
54+ await ydbCommand . ExecuteNonQueryAsync ( ) ;
55+ }
56+
57+ protected override async Task OnDisposeAsync ( )
58+ {
59+ await using var ydbConnection = await CreateOpenConnectionAsync ( ) ;
60+ var ydbCommand = ydbConnection . CreateCommand ( ) ;
61+ ydbCommand . CommandText = $ "DROP USER { _user } ;";
62+ await ydbCommand . ExecuteNonQueryAsync ( ) ;
63+ }
4864}
0 commit comments