Skip to content

Commit cad6537

Browse files
committed
Add Interactive tests
1 parent 787cd5b commit cad6537

File tree

5 files changed

+103
-6
lines changed

5 files changed

+103
-6
lines changed

Diff for: .github/workflows/build-and-test.yml

+10-6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1717
- name: Setup .NET
18-
uses: actions/setup-dotnet@v3
18+
uses: actions/setup-dotnet@v4
1919
with:
20-
dotnet-version: 8.x.x
20+
dotnet-version: |
21+
8.x.x
22+
# 9.x.x
2123
- name: make script executable
2224
run: chmod u+x build.sh
2325
- name: Build and test
@@ -29,11 +31,13 @@ jobs:
2931
runs-on: windows-latest
3032

3133
steps:
32-
- uses: actions/checkout@v3
34+
- uses: actions/checkout@v4
3335
- name: Setup .NET
34-
uses: actions/setup-dotnet@v3
36+
uses: actions/setup-dotnet@v4
3537
with:
36-
dotnet-version: 8.x.x
38+
dotnet-version: |
39+
8.x.x
40+
# 9.x.x
3741
- name: Build and test (includes netfx)
3842
working-directory: ./
3943
run: ./build.cmd runtestsall

Diff for: Plotly.NET.sln

+9
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "data", "data", "{0D955C86-2
231231
docs\data\volcano.csv = docs\data\volcano.csv
232232
EndProjectSection
233233
EndProject
234+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "InteractiveTests", "tests\ExtensionLibsTests\InteractiveTests\InteractiveTests.fsproj", "{04BC8CE5-B096-46AD-AB1D-674305BAF59A}"
235+
EndProject
234236
Global
235237
GlobalSection(SolutionConfigurationPlatforms) = preSolution
236238
Debug|Any CPU = Debug|Any CPU
@@ -316,6 +318,12 @@ Global
316318
{18F778B2-3409-4309-8C9B-596109072481}.Dotnet|Any CPU.Build.0 = Debug|Any CPU
317319
{18F778B2-3409-4309-8C9B-596109072481}.Release|Any CPU.ActiveCfg = Release|Any CPU
318320
{18F778B2-3409-4309-8C9B-596109072481}.Release|Any CPU.Build.0 = Release|Any CPU
321+
{04BC8CE5-B096-46AD-AB1D-674305BAF59A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
322+
{04BC8CE5-B096-46AD-AB1D-674305BAF59A}.Debug|Any CPU.Build.0 = Debug|Any CPU
323+
{04BC8CE5-B096-46AD-AB1D-674305BAF59A}.Dotnet|Any CPU.ActiveCfg = Debug|Any CPU
324+
{04BC8CE5-B096-46AD-AB1D-674305BAF59A}.Dotnet|Any CPU.Build.0 = Debug|Any CPU
325+
{04BC8CE5-B096-46AD-AB1D-674305BAF59A}.Release|Any CPU.ActiveCfg = Release|Any CPU
326+
{04BC8CE5-B096-46AD-AB1D-674305BAF59A}.Release|Any CPU.Build.0 = Release|Any CPU
319327
EndGlobalSection
320328
GlobalSection(SolutionProperties) = preSolution
321329
HideSolutionNode = FALSE
@@ -357,6 +365,7 @@ Global
357365
{7432D5ED-0D0D-4F15-A3AC-CC2BFA4F211F} = {A9025690-FABC-4BD3-AC94-F31B60A948B4}
358366
{2DF92AB2-7B8C-48D5-B779-26BA1F31BCA1} = {A9025690-FABC-4BD3-AC94-F31B60A948B4}
359367
{0D955C86-2E86-4D50-828A-6CF5AD99A119} = {7B09CC0A-F1E1-4094-9DE4-B047581E01F0}
368+
{04BC8CE5-B096-46AD-AB1D-674305BAF59A} = {02886FBB-DB32-4BBB-A93C-E13EBF453ACC}
360369
EndGlobalSection
361370
GlobalSection(ExtensibilityGlobals) = postSolution
362371
SolutionGuid = {7177F1E1-341C-48AB-9864-6B525FFF7633}
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module Tests.Interactive.Formatting
2+
3+
open Expecto
4+
5+
open System
6+
open System.IO
7+
8+
open Microsoft.DotNet.Interactive
9+
open Microsoft.DotNet.Interactive.Formatting
10+
11+
module ConventionBased =
12+
13+
[<AttributeUsage(AttributeTargets.Class)>]
14+
type internal TypeFormatterSourceAttribute(formatterSourceType: Type) =
15+
inherit Attribute()
16+
let mutable preferredMimeTypes : string[] = [||]
17+
member this.TypeFormatterSourceType = formatterSourceType
18+
member this.PreferredMimeTypes
19+
with get() = preferredMimeTypes
20+
and set(v) = preferredMimeTypes <- v
21+
22+
[<TypeFormatterSourceAttribute(typeof<CustomFormatterSource>)>]
23+
type TypeWithCustomFormatter() = class end
24+
25+
and CustomFormatter() =
26+
let mutable mimeType = "text/html"
27+
member this.MimeType
28+
with get() = mimeType
29+
and set(v) = mimeType <- v
30+
member this.Format(instance:obj, writer:TextWriter) =
31+
match instance with
32+
| :? TypeWithCustomFormatter as c ->
33+
writer.Write("Formatting successfull!")
34+
true
35+
| _ -> false
36+
37+
and CustomFormatterSource =
38+
member this.CreateTypeFormatters() : seq<obj> =
39+
seq {
40+
yield CustomFormatter()
41+
}
42+
43+
[<Tests>]
44+
let ``Convention-based Formatting`` =
45+
testList "Convention-based Formatting" [
46+
testCase "Convention based formatter sources can provide lazy registration of custom formatters" <| fun _ ->
47+
let o = ConventionBased.TypeWithCustomFormatter()
48+
let formatted = o.ToDisplayString()
49+
Expect.equal formatted "Formatting successfull!" "Formatting failed"
50+
51+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<GenerateProgramFile>false</GenerateProgramFile>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<Compile Include="Formatting.fs" />
12+
<Compile Include="Main.fs" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="Microsoft.DotNet.Interactive" Version="1.0.0-beta.25070.1" />
17+
<PackageReference Include="Microsoft.DotNet.Interactive.Formatting" Version="1.0.0-beta.25070.1" />
18+
<!--<PackageReference Include="Microsoft.DotNet.Interactive.FSharp" Version="1.0.0-beta.25070.1" />-->
19+
<PackageReference Include="Expecto" Version="10.*" />
20+
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" />
21+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<ProjectReference Include="..\..\..\src\Plotly.NET.ImageExport\Plotly.NET.ImageExport.fsproj" />
26+
</ItemGroup>
27+
</Project>

Diff for: tests/ExtensionLibsTests/InteractiveTests/Main.fs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Plotly.NET.Tests
2+
open Expecto
3+
4+
[<EntryPoint>]
5+
let main argv =
6+
Tests.runTestsInAssemblyWithCLIArgs [] argv

0 commit comments

Comments
 (0)