-
Notifications
You must be signed in to change notification settings - Fork 367
/
SQLiteKernelExtensionTests.cs
103 lines (78 loc) · 3.18 KB
/
SQLiteKernelExtensionTests.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// 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;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Assent;
using Microsoft.DotNet.Interactive.CSharp;
using Microsoft.DotNet.Interactive.Events;
using Microsoft.DotNet.Interactive.Formatting;
using Microsoft.DotNet.Interactive.Tests.Utility;
using Xunit;
namespace Microsoft.DotNet.Interactive.ExtensionLab.Tests
{
public class SQLiteKernelExtensionTests : IDisposable
{
private readonly Configuration _configuration;
public SQLiteKernelExtensionTests()
{
_configuration = new Configuration()
.SetInteractive(Debugger.IsAttached)
.UsingExtension("json");
}
[Fact]
public async Task can_generate_tabular_json_from_database_table_result()
{
using var kernel = new CompositeKernel
{
new CSharpKernel().UseNugetDirective(),
new KeyValueStoreKernel()
};
var extension = new SQLiteKernelExtension();
await extension.OnLoadAsync(kernel);
using var _ = SQLiteConnectionTests.CreateInMemorySQLiteDb(out var connectionString);
await kernel.SubmitCodeAsync(
$"#!connect --kernel-name mydb sqlite \"{connectionString}\"");
var result = await kernel.SubmitCodeAsync(@"
#!sql-mydb
SELECT * FROM fruit
");
var events = result.KernelEvents.ToSubscribedList();
var formattedData = events.OfType<DisplayedValueProduced>().Single()
.FormattedValues.Single(fm => fm.MimeType == HtmlFormatter.MimeType)
.Value;
this.Assent(formattedData.FixedGuid(), _configuration);
}
[Fact]
public async Task can_handle_duplicate_columns_in_query_results()
{
using var kernel = new CompositeKernel
{
new CSharpKernel().UseNugetDirective(),
new KeyValueStoreKernel()
};
var extension = new SQLiteKernelExtension();
await extension.OnLoadAsync(kernel);
using var _ = SQLiteConnectionTests.CreateInMemorySQLiteDb(out var connectionString);
await kernel.SubmitCodeAsync(
$"#!connect --kernel-name mydb sqlite \"{connectionString}\"");
var result = await kernel.SubmitCodeAsync(@"
#!sql-mydb
SELECT 1 AS Apples, 2 AS Bananas, 3 AS Apples, 4 AS BANANAS, 5 AS Apples, 6 AS BaNaNaS
");
var events = result.KernelEvents.ToSubscribedList();
var formattedData = events
.OfType<DisplayedValueProduced>()
.Single()
.FormattedValues
.Single(fm => fm.MimeType == HtmlFormatter.MimeType)
.Value;
this.Assent(formattedData.FixedGuid(), _configuration);
}
public void Dispose()
{
Formatter.ResetToDefault();
}
}
}