forked from dotnet/interactive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLiteKernelExtensionTests.cs
More file actions
90 lines (70 loc) · 2.71 KB
/
Copy pathSQLiteKernelExtensionTests.cs
File metadata and controls
90 lines (70 loc) · 2.71 KB
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
// 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.App;
using Microsoft.DotNet.Interactive.CSharp;
using Microsoft.DotNet.Interactive.Events;
using Microsoft.DotNet.Interactive.Formatting;
using Microsoft.DotNet.Interactive.Formatting.TabularData;
using Microsoft.DotNet.Interactive.Tests.Utility;
using Xunit;
namespace Microsoft.DotNet.Interactive.SQLite.Tests;
public class SQLiteKernelExtensionTests : IDisposable
{
private readonly Configuration _configuration;
public SQLiteKernelExtensionTests()
{
_configuration = new Configuration()
.SetInteractive(Debugger.IsAttached)
.UsingExtension("json");
}
[WindowsFact]
public async Task can_generate_tabular_json_from_database_table_result()
{
using var kernel = new CompositeKernel
{
new CSharpKernel().UseNugetDirective(),
new KeyValueStoreKernel()
};
SQLiteKernel.AddSQLiteKernelConnectorTo(kernel);
using var _ = SQLiteConnectionTests.CreateInMemorySQLiteDb(out var connectionString);
await kernel.SubmitCodeAsync(
$"#!connect sqlite --kernel-name mydb \"{connectionString}\"");
var result = await kernel.SubmitCodeAsync(@"
#!sql-mydb
SELECT * FROM fruit
");
var tabularData = result.Events.OfType<DisplayedValueProduced>().Single()
.Value;
this.Assent(tabularData.ToDisplayString(TabularDataResourceFormatter .MimeType), _configuration);
}
[WindowsFact]
public async Task can_handle_duplicate_columns_in_query_results()
{
using var kernel = new CompositeKernel
{
new CSharpKernel().UseNugetDirective(),
new KeyValueStoreKernel()
};
SQLiteKernel.AddSQLiteKernelConnectorTo(kernel);
using var _ = SQLiteConnectionTests.CreateInMemorySQLiteDb(out var connectionString);
await kernel.SubmitCodeAsync(
$"#!connect sqlite --kernel-name mydb \"{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 tabularData = result.Events.OfType<DisplayedValueProduced>().Single()
.Value;
this.Assent(tabularData.ToDisplayString(TabularDataResourceFormatter.MimeType), _configuration);
}
public void Dispose()
{
Formatter.ResetToDefault();
DataExplorer.ResetToDefault();
}
}