Skip to content

Commit e94ed0b

Browse files
committed
Increase coverage
1 parent 0a61d0b commit e94ed0b

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

PSql.Tests/Tests.Integration/InvokeSqlCommandTests.cs renamed to PSql.Tests/Tests.Integration/InvokeSqlCommandIntegrationTests.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace PSql.Tests.Integration;
1313

1414
[TestFixture]
1515
[Parallelizable(ParallelScope.All)]
16-
public class InvokeSqlCommandTests
16+
public class InvokeSqlCommandIntegrationTests
1717
{
1818
[OneTimeSetUp]
1919
public static void SetUpOnce()
@@ -22,6 +22,54 @@ public static void SetUpOnce()
2222
_ = Prelude;
2323
}
2424

25+
[Test]
26+
public void Invoke_Default()
27+
{
28+
var (output, exception) = Execute(
29+
"""
30+
PSql\Invoke-Sql "PRINT 'a';"
31+
""");
32+
33+
exception.ShouldBeNull();
34+
35+
output.ShouldHaveSingleItem().ShouldNotBeNull()
36+
.BaseObject.ShouldBe(new PSInformation("a"));
37+
}
38+
39+
[Test]
40+
public void Invoke_Context()
41+
{
42+
var (output, exception) = Execute(
43+
"""
44+
PSql\Invoke-Sql -Context $Context "PRINT 'a';"
45+
""");
46+
47+
exception.ShouldBeNull();
48+
49+
output.ShouldHaveSingleItem().ShouldNotBeNull()
50+
.BaseObject.ShouldBe(new PSInformation("a"));
51+
}
52+
53+
[Test]
54+
public void Invoke_Connection()
55+
{
56+
var (output, exception) = Execute(
57+
"""
58+
$Connection = PSql\Connect-Sql
59+
try {
60+
PSql\Invoke-Sql -Connection $Connection "PRINT 'a';"
61+
}
62+
finally {
63+
PSql\Disconnect-Sql $Connection
64+
}
65+
""");
66+
67+
exception.ShouldBeNull();
68+
69+
output.ShouldHaveSingleItem().ShouldNotBeNull()
70+
.BaseObject.ShouldBe(new PSInformation("a"));
71+
}
72+
2573
[Test]
2674
public void ProjectBit_ToClrBoolean()
2775
{
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright Subatomix Research Inc.
2+
// SPDX-License-Identifier: MIT
3+
4+
using PSql.Commands;
5+
6+
namespace PSql.Tests;
7+
8+
[TestFixture]
9+
public class ConnectedCmdletTests
10+
{
11+
[Test]
12+
public void Dispose_NotInvoked()
13+
{
14+
var cmdlet = new TestCmdletA();
15+
16+
cmdlet.Dispose();
17+
cmdlet.Dispose(); // To test multiple disposal
18+
}
19+
20+
[Test]
21+
public void Dispose_ConnectionNullified()
22+
{
23+
var cmdlet = new TestCmdletB();
24+
25+
cmdlet.Dispose();
26+
cmdlet.Dispose(); // To test multiple disposal
27+
}
28+
29+
private class TestCmdletA : ConnectedCmdlet { }
30+
31+
private class TestCmdletB : ConnectedCmdlet
32+
{
33+
// This class does several things wrongly in order to test an edge
34+
// case: where _ownsConnection is true but Connection is null.
35+
36+
public TestCmdletB()
37+
{
38+
// This here to set _ownsConnection to true
39+
Context = new();
40+
BeginProcessing();
41+
}
42+
43+
public override void Dispose()
44+
{
45+
// This here to set Connection to null
46+
Connection?.Dispose();
47+
Connection = null;
48+
49+
base.Dispose();
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)