Skip to content

Commit 1697813

Browse files
committed
optimized unit tests
1 parent 0754516 commit 1697813

File tree

3 files changed

+596
-36
lines changed

3 files changed

+596
-36
lines changed

src/SuperSocket.MySQL/Packets/QueryResultPacket.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class QueryResultPacket : MySQLPacket
4444
/// <summary>
4545
/// Gets the number of columns in the result set.
4646
/// </summary>
47-
public int ColumnCount { get; set; }
47+
public int ColumnCount => Columns?.Count ?? 0;
4848

4949
/// <summary>
5050
/// Initializes a new instance of the QueryResultPacket class.
@@ -81,8 +81,8 @@ public static QueryResultPacket FromResultSet(IReadOnlyList<ColumnDefinitionPack
8181
return new QueryResultPacket
8282
{
8383
ErrorCode = 0,
84-
Columns = columns,
85-
Rows = rows
84+
Columns = columns ?? Array.Empty<ColumnDefinitionPacket>(),
85+
Rows = rows ?? Array.Empty<IReadOnlyList<string>>()
8686
};
8787
}
8888

tests/SuperSocket.MySQL.Test/MainTest.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,22 @@ public async Task ExecuteQueryAsync_WithAuthentication_ShouldNotThrow()
191191

192192
// Assert
193193
Assert.NotNull(result);
194-
// Note: Since ExecuteQueryAsync is a placeholder implementation,
195-
// we're just verifying it doesn't throw when authenticated
194+
// Verify that the result has a proper structure
195+
Assert.True(result.IsSuccess || result.ErrorCode != 0,
196+
"Result should either be successful or have a proper error code");
197+
198+
if (result.IsSuccess)
199+
{
200+
Assert.Equal(0, result.ErrorCode);
201+
Assert.Null(result.ErrorMessage);
202+
Assert.True(result.ColumnCount >= 0, "Column count should be non-negative");
203+
Assert.True(result.RowCount >= 0, "Row count should be non-negative");
204+
}
205+
else
206+
{
207+
Assert.NotEqual(0, result.ErrorCode);
208+
Assert.NotNull(result.ErrorMessage);
209+
}
196210
}
197211
finally
198212
{

0 commit comments

Comments
 (0)