-
Notifications
You must be signed in to change notification settings - Fork 367
/
SqlDiscoverabilityKernelTests.cs
89 lines (65 loc) · 2.6 KB
/
SqlDiscoverabilityKernelTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.DotNet.Interactive.Commands;
using Microsoft.DotNet.Interactive.Events;
using Microsoft.DotNet.Interactive.Tests.Utility;
using Xunit;
namespace Microsoft.DotNet.Interactive.Tests;
public class SqlDiscoverabilityKernelTests
{
[Fact]
public async Task sql_kernel_does_not_execute_query()
{
using var kernel = new CompositeKernel
{
new SqlDiscoverabilityKernel()
};
using var events = kernel.KernelEvents.ToSubscribedList();
var query = "select * from sys.databases";
await kernel.SendAsync(new SubmitCode($"#!sql\n\n{query}"));
var commandFailed = events.Should()
.ContainSingle<CommandFailed>()
.Which;
var message = commandFailed.Message;
message.Should()
.Be("SQL statements cannot be executed in this kernel.");
}
[Fact]
public async Task sql_kernel_suggest_how_to_submit_query()
{
using var kernel = new CompositeKernel
{
new SqlDiscoverabilityKernel()
};
using var events = kernel.KernelEvents.ToSubscribedList();
var query = "select * from sys.databases";
await kernel.SendAsync(new SubmitCode($"#!sql\n\n{query}"));
var displayValue = events.Should()
.ContainSingle<DisplayedValueProduced>()
.Which;
var message = displayValue.Value.ToString();
message.Should()
.Contain(query);
}
[Fact]
public async Task sql_kernel_emits_help_message_without_sql_server_extension_installed()
{
using var kernel = new CompositeKernel
{
new SqlDiscoverabilityKernel()
};
using var events = kernel.KernelEvents.ToSubscribedList();
var query = "select * from sys.databases";
await kernel.SendAsync(new SubmitCode($"#!sql\n\n{query}"));
var displayValue = events.Should()
.ContainSingle<DisplayedValueProduced>()
.Which;
var message = displayValue.Value.ToString();
// Should contain instructions for how to install SqlServer extension package
message.Should().Contain(@"#r ""nuget:Microsoft.DotNet.Interactive.SqlServer,*-*""");
// Should contain instructions for how to get help message for MSSQL kernel
message.Should().Contain("#!connect mssql --kernel-name");
}
}