Skip to content

Commit 22c6825

Browse files
author
MPCoreDeveloper
committed
codecov update
1 parent bd4114c commit 22c6825

4 files changed

Lines changed: 182 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using Grpc.Core;
2+
using SharpCoreDB.Client;
3+
using SharpCoreDB.Server.Protocol;
4+
5+
namespace SharpCoreDB.Tests.Client;
6+
7+
public sealed class SharpCoreDBDataReaderTests
8+
{
9+
[Fact]
10+
public async Task ReadAsync_WhenReaderIsClosed_ShouldReturnFalse()
11+
{
12+
// Arrange
13+
var stream = new FakeAsyncStreamReader();
14+
await using var reader = new SharpCoreDBDataReader(stream, CancellationToken.None);
15+
reader.Close();
16+
17+
// Act
18+
var result = await reader.ReadAsync();
19+
20+
// Assert
21+
Assert.False(result);
22+
}
23+
24+
[Fact]
25+
public async Task ReadAsync_WhenFirstResponseHasRows_ShouldReturnTrue()
26+
{
27+
// Arrange
28+
var response = new QueryResponse();
29+
response.Columns.Add(new ColumnMetadata { Name = "Id", Type = SharpCoreDB.Server.Protocol.DataType.Integer });
30+
var row = new RowData();
31+
row.Values.Add(new ParameterValue { IntValue = 123 });
32+
response.Rows.Add(row);
33+
34+
var stream = new FakeAsyncStreamReader(response);
35+
await using var reader = new SharpCoreDBDataReader(stream, CancellationToken.None);
36+
37+
// Act
38+
var result = await reader.ReadAsync();
39+
40+
// Assert
41+
Assert.True(result);
42+
Assert.Equal(123, reader.GetInt32(0));
43+
}
44+
45+
[Fact]
46+
public async Task ReadAsync_WhenNoResponses_ShouldReturnFalse()
47+
{
48+
// Arrange
49+
var stream = new FakeAsyncStreamReader();
50+
await using var reader = new SharpCoreDBDataReader(stream, CancellationToken.None);
51+
52+
// Act
53+
var result = await reader.ReadAsync();
54+
55+
// Assert
56+
Assert.False(result);
57+
}
58+
59+
private sealed class FakeAsyncStreamReader : IAsyncStreamReader<QueryResponse>
60+
{
61+
private readonly Queue<QueryResponse> _responses;
62+
63+
public FakeAsyncStreamReader(params QueryResponse[] responses)
64+
{
65+
_responses = new Queue<QueryResponse>(responses);
66+
}
67+
68+
public QueryResponse Current { get; private set; } = new();
69+
70+
public Task<bool> MoveNext(CancellationToken cancellationToken)
71+
{
72+
if (_responses.Count == 0)
73+
{
74+
return Task.FromResult(false);
75+
}
76+
77+
Current = _responses.Dequeue();
78+
return Task.FromResult(true);
79+
}
80+
}
81+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using SharpCoreDB.Data.Provider;
2+
3+
namespace SharpCoreDB.Tests.DataProvider;
4+
5+
public sealed class SharpCoreDBConnectionAndParameterTests
6+
{
7+
[Fact]
8+
public void ConnectionString_WhenSetNull_ShouldBecomeEmptyString()
9+
{
10+
// Arrange
11+
using var connection = new SharpCoreDBConnection();
12+
13+
// Act
14+
connection.ConnectionString = null;
15+
16+
// Assert
17+
Assert.Equal(string.Empty, connection.ConnectionString);
18+
}
19+
20+
[Fact]
21+
public void ParameterName_WhenSetNull_ShouldKeepNullAssignmentSafe()
22+
{
23+
// Arrange
24+
var parameter = new SharpCoreDBParameter();
25+
26+
// Act
27+
parameter.ParameterName = null;
28+
29+
// Assert
30+
Assert.Null(parameter.ParameterName);
31+
}
32+
33+
[Fact]
34+
public void SourceColumn_WhenSetNull_ShouldKeepNullAssignmentSafe()
35+
{
36+
// Arrange
37+
var parameter = new SharpCoreDBParameter();
38+
39+
// Act
40+
parameter.SourceColumn = null;
41+
42+
// Assert
43+
Assert.Null(parameter.SourceColumn);
44+
}
45+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Moq;
2+
using SharpCoreDB.DataStructures;
3+
using SharpCoreDB.Interfaces;
4+
using SharpCoreDB.Services;
5+
6+
namespace SharpCoreDB.Tests.QueryExecution;
7+
8+
public sealed class CompiledQueryExecutorTests
9+
{
10+
[Fact]
11+
public void Execute_WithIndexedProjectionNullValue_ShouldProjectDBNull()
12+
{
13+
// Arrange
14+
var rows = new List<Dictionary<string, object>>
15+
{
16+
new() { ["Name"] = "Alice" }
17+
};
18+
19+
var tableMock = new Mock<ITable>();
20+
tableMock.Setup(t => t.Select(null, null, true)).Returns(rows);
21+
22+
var tables = new Dictionary<string, ITable>(StringComparer.OrdinalIgnoreCase)
23+
{
24+
["Users"] = tableMock.Object,
25+
};
26+
27+
var executor = new CompiledQueryExecutor(tables);
28+
29+
var plan = new CompiledQueryPlan(
30+
sql: "SELECT Missing FROM Users",
31+
tableName: "Users",
32+
selectColumns: ["Missing"],
33+
isSelectAll: false,
34+
whereFilter: null,
35+
whereFilterIndexed: null,
36+
projectionFunc: static row => new Dictionary<string, object>(row),
37+
orderByColumn: null,
38+
orderByAscending: true,
39+
limit: null,
40+
offset: null,
41+
parameterNames: [],
42+
optimizedPlan: null,
43+
optimizedCost: 0,
44+
columnIndices: new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase) { ["Name"] = 0, ["Missing"] = 1 },
45+
useDirectColumnAccess: true);
46+
47+
// Act
48+
var result = executor.Execute(plan);
49+
50+
// Assert
51+
Assert.Single(result);
52+
Assert.True(result[0].ContainsKey("Missing"));
53+
Assert.Equal(DBNull.Value, result[0]["Missing"]);
54+
}
55+
}

tests/SharpCoreDB.Tests/SharpCoreDB.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
<ItemGroup>
4141
<ProjectReference Include="..\..\src\SharpCoreDB\SharpCoreDB.csproj" />
42+
<ProjectReference Include="..\..\src\SharpCoreDB.Client\SharpCoreDB.Client.csproj" />
4243
<ProjectReference Include="..\..\src\SharpCoreDB.Data.Provider\SharpCoreDB.Data.Provider.csproj" />
4344
<ProjectReference Include="..\..\src\SharpCoreDB.Functional\SharpCoreDB.Functional.csproj" />
4445
<ProjectReference Include="..\..\src\SharpCoreDB.Distributed\SharpCoreDB.Distributed.csproj" />

0 commit comments

Comments
 (0)