-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
103 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Tests.Interactive.Formatting | ||
|
||
open Expecto | ||
|
||
open System | ||
open System.IO | ||
|
||
open Microsoft.DotNet.Interactive | ||
open Microsoft.DotNet.Interactive.Formatting | ||
|
||
module ConventionBased = | ||
|
||
[<AttributeUsage(AttributeTargets.Class)>] | ||
type internal TypeFormatterSourceAttribute(formatterSourceType: Type) = | ||
inherit Attribute() | ||
let mutable preferredMimeTypes : string[] = [||] | ||
member this.TypeFormatterSourceType = formatterSourceType | ||
member this.PreferredMimeTypes | ||
with get() = preferredMimeTypes | ||
and set(v) = preferredMimeTypes <- v | ||
|
||
[<TypeFormatterSourceAttribute(typeof<CustomFormatterSource>)>] | ||
type TypeWithCustomFormatter() = class end | ||
|
||
and CustomFormatter() = | ||
let mutable mimeType = "text/html" | ||
member this.MimeType | ||
with get() = mimeType | ||
and set(v) = mimeType <- v | ||
member this.Format(instance:obj, writer:TextWriter) = | ||
match instance with | ||
| :? TypeWithCustomFormatter as c -> | ||
writer.Write("Formatting successfull!") | ||
true | ||
| _ -> false | ||
|
||
and CustomFormatterSource = | ||
member this.CreateTypeFormatters() : seq<obj> = | ||
seq { | ||
yield CustomFormatter() | ||
} | ||
|
||
[<Tests>] | ||
let ``Convention-based Formatting`` = | ||
testList "Convention-based Formatting" [ | ||
testCase "Convention based formatter sources can provide lazy registration of custom formatters" <| fun _ -> | ||
let o = ConventionBased.TypeWithCustomFormatter() | ||
let formatted = o.ToDisplayString() | ||
Expect.equal formatted "Formatting successfull!" "Formatting failed" | ||
|
||
] |
27 changes: 27 additions & 0 deletions
27
tests/ExtensionLibsTests/InteractiveTests/InteractiveTests.fsproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<GenerateProgramFile>false</GenerateProgramFile> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Formatting.fs" /> | ||
<Compile Include="Main.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.DotNet.Interactive" Version="1.0.0-beta.25070.1" /> | ||
<PackageReference Include="Microsoft.DotNet.Interactive.Formatting" Version="1.0.0-beta.25070.1" /> | ||
<!--<PackageReference Include="Microsoft.DotNet.Interactive.FSharp" Version="1.0.0-beta.25070.1" />--> | ||
<PackageReference Include="Expecto" Version="10.*" /> | ||
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\Plotly.NET.ImageExport\Plotly.NET.ImageExport.fsproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Plotly.NET.Tests | ||
open Expecto | ||
|
||
[<EntryPoint>] | ||
let main argv = | ||
Tests.runTestsInAssemblyWithCLIArgs [] argv |