|
| 1 | +// Copyright Subatomix Research Inc. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +namespace PSql.Tests.Integration; |
| 5 | + |
| 6 | +[TestFixture] |
| 7 | +public class ConnectSqlCommandIntegrationTests |
| 8 | +{ |
| 9 | + [Test] |
| 10 | + public void Invoke_Default() |
| 11 | + { |
| 12 | + Execute( |
| 13 | + "Connect-Sql" |
| 14 | + ) |
| 15 | + .ShouldBe( |
| 16 | + "Data Source=.;Integrated Security=true;" + |
| 17 | + "Encrypt=false;Trust Server Certificate=true;Pooling=false" |
| 18 | + ); |
| 19 | + } |
| 20 | + |
| 21 | + [Test] |
| 22 | + public void Invoke_Pipeline() |
| 23 | + { |
| 24 | + Execute( |
| 25 | + "New-SqlContext -ReadOnlyIntent | Connect-Sql" |
| 26 | + ) |
| 27 | + .ShouldBe( |
| 28 | + "Data Source=.;Integrated Security=true;" + |
| 29 | + "Encrypt=false;Trust Server Certificate=true;" + |
| 30 | + "Application Intent=ReadOnly;Pooling=false" |
| 31 | + ); |
| 32 | + } |
| 33 | + |
| 34 | + [Test] |
| 35 | + public void Invoke_Context() |
| 36 | + { |
| 37 | + Execute( |
| 38 | + "Connect-Sql -Context (New-SqlContext -ReadOnlyIntent)" |
| 39 | + ) |
| 40 | + .ShouldBe( |
| 41 | + "Data Source=.;Integrated Security=true;" + |
| 42 | + "Encrypt=false;Trust Server Certificate=true;" + |
| 43 | + "Application Intent=ReadOnly;Pooling=false" |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + [Test] |
| 48 | + public void Invoke_DatabaseName() |
| 49 | + { |
| 50 | + Execute( |
| 51 | + "New-SqlContext -ReadOnlyIntent | Connect-Sql -DatabaseName master" |
| 52 | + ) |
| 53 | + .ShouldBe( |
| 54 | + "Data Source=.;Initial Catalog=master;Integrated Security=true;" + |
| 55 | + "Encrypt=false;Trust Server Certificate=true;" + |
| 56 | + "Application Intent=ReadOnly;Pooling=false" |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + private static string Execute(string script) |
| 61 | + { |
| 62 | + var (output, exception) = ScriptExecutor.Execute(script); |
| 63 | + |
| 64 | + exception.ShouldBeNull(); |
| 65 | + |
| 66 | + output.ShouldHaveSingleItem().ShouldBeOfType<PSObject>() |
| 67 | + .BaseObject.ShouldBeOfType<SqlConnection>().AssignTo(out var connection); |
| 68 | + |
| 69 | + try |
| 70 | + { |
| 71 | + return connection.InnerConnection.ConnectionString; |
| 72 | + } |
| 73 | + finally |
| 74 | + { |
| 75 | + connection.Dispose(); |
| 76 | + } |
| 77 | + } |
| 78 | +} |
0 commit comments