-
Notifications
You must be signed in to change notification settings - Fork 368
/
LanguageKernelScriptReferenceTests.cs
100 lines (80 loc) · 4.03 KB
/
LanguageKernelScriptReferenceTests.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
// 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.IO;
using FluentAssertions;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.DotNet.Interactive.Commands;
using Microsoft.DotNet.Interactive.Events;
using Microsoft.DotNet.Interactive.Tests.Utility;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.DotNet.Interactive.Tests
{
#pragma warning disable 8509
public class LanguageKernelScriptReferenceTests : LanguageKernelTestBase
{
public LanguageKernelScriptReferenceTests(ITestOutputHelper output) : base(output)
{
}
[Theory]
[InlineData(Language.CSharp)]
[InlineData(Language.FSharp)]
public async Task it_can_load_script_files_using_load_directive_with_relative_path(Language language)
{
var kernel = CreateKernel(language);
var code = language switch
{
Language.CSharp => "#load \"RelativeLoadingSample.csx\"",
Language.FSharp => "#load \"RelativeLoadingSample.fsx\""
};
var command = new SubmitCode(code);
await kernel.SendAsync(command);
KernelEvents.Should().NotContainErrors();
KernelEvents.Should()
.ContainSingle<DisplayedValueProduced>(e => e.FormattedValues.Any(v => v.Value.Contains("hello!")));
}
[Theory]
[InlineData(Language.CSharp)]
// [InlineData(Language.FSharp)] Not supported in F#
public async Task it_can_load_script_files_using_load_directive_with_relative_path_after_user_code_changes_current_directory(Language language)
{
var currentDirectory = Directory.GetCurrentDirectory();
DisposeAfterTest(() => Directory.SetCurrentDirectory(currentDirectory));
var kernel = CreateKernel(language);
//Even when a user changes the current directory, loading from a relative path is not affected.
await kernel.SendAsync(new SubmitCode("System.IO.Directory.SetCurrentDirectory(\"..\")"));
var code = language switch
{
Language.CSharp => $"#load \"{Path.Combine(currentDirectory, "RelativeLoadingSample.csx")}\"",
Language.FSharp => $"#load \"{Path.Combine(currentDirectory, "RelativeLoadingSample.fsx")}\""
};
var command = new SubmitCode(code);
await kernel.SendAsync(command);
KernelEvents.Should().NotContainErrors();
KernelEvents.Should()
.ContainSingle<DisplayedValueProduced>(e => e.FormattedValues.Any(v => v.Value.Contains("hello!")));
}
[Theory]
[InlineData(Language.CSharp)]
//Not implemented: [InlineData(Language.FSharp)]
public async Task it_can_load_script_files_using_load_directive_with_relative_path_after_command_changeWorkingDirectory(Language language)
{
var currentDirectory = Directory.GetCurrentDirectory();
DisposeAfterTest(() => Directory.SetCurrentDirectory(currentDirectory));
var kernel = CreateKernel(language);
var absolutePathOneLevelHigher = Directory.GetParent(currentDirectory).FullName;
await kernel.SendAsync(new ChangeWorkingDirectory(absolutePathOneLevelHigher));
var relativePath = Path.GetRelativePath(absolutePathOneLevelHigher, currentDirectory);
var code = language switch
{
Language.CSharp => $"#load \"{Path.Combine(relativePath, "RelativeLoadingSample.csx")}\"",
Language.FSharp => $"#load \"{Path.Combine(relativePath, "RelativeLoadingSample.fsx")}\""
};
var command = new SubmitCode(code);
await kernel.SendAsync(command);
KernelEvents.Should()
.ContainSingle<DisplayedValueProduced>(e => e.FormattedValues.Any(v => v.Value.Contains("hello!")));
}
}
}