11module Tests.ImageExport
22
3+ open System.Runtime .InteropServices
34open Expecto
45open Plotly.NET
56open Plotly.NET .ImageExport
67
78open System
89open System.IO
910
10- let testBase64JPG = File.ReadAllText (__ SOURCE_ DIRECTORY__ + " /data/testBase64JPG.txt" )
11-
12- let testBase64PNG =
13- File.ReadAllBytes(__ SOURCE_ DIRECTORY__ + " /data/testPNG.png" )
14- |> Convert.ToBase64String
11+ let readTestFilePlatformSpecific filePostfix =
12+ if RuntimeInformation.IsOSPlatform( OSPlatform.Linux) then
13+ let content = File.ReadAllText (__ SOURCE_ DIRECTORY__ + $" /data/linux{filePostfix}" )
14+ content.Substring( 0 , content.Length - 1 ) // Because on Linux you're expected to newline terminate the file
15+ else if RuntimeInformation.IsOSPlatform( OSPlatform.Windows) then
16+ File.ReadAllText (__ SOURCE_ DIRECTORY__ + $" /data/win{filePostfix}" )
17+ else
18+ raise ( Exception " Running tests on the current OS is not supported :(" )
1519
1620[<Tests>]
1721let ``Image export tests`` =
@@ -23,21 +27,25 @@ let ``Image export tests`` =
2327 // skipping this for now, cannot make it work atm (pTestAsync -> testAsync for running it)
2428 testList " base64 strings" [
2529 ptestAsync " Chart.toBase64JPGStringAsync" {
30+ let testBase64JPG = readTestFilePlatformSpecific " TestBase64JPG.txt"
31+
2632 let! actual = ( Chart.Point([ 1. , 1. ]) |> Chart.toBase64JPGStringAsync())
2733
2834 return
29- Expect.stringContains
35+ Expect.equal
3036 actual
3137 testBase64JPG
3238 " Invalid base64 string for Chart.toBase64JPGStringAsync"
3339 }
3440 ptestAsync " Chart.toBase64PNGStringAsync" {
41+ let testBase64PNG = readTestFilePlatformSpecific " TestBase64PNG.txt"
42+
3543 let! actual = ( Chart.Point([ 1. , 1. ]) |> Chart.toBase64PNGStringAsync())
3644
3745 return
38- Expect.stringContains
46+ Expect.equal
3947 actual
40- testBase64JPG
48+ testBase64PNG
4149 " Invalid base64 string for Chart.toBase64PNGStringAsync"
4250 }
4351 ]
0 commit comments