namespace LibraryTests module TestingHelpers = open System open System.Drawing open System.Reflection open SmoulderingBeachBall.Domain open SmoulderingBeachBall.Services let loadLocation = __SOURCE_DIRECTORY__ + "/LoadingTestArea" let allColours = let properties = typeof.GetProperties(BindingFlags.Public ||| BindingFlags.Static) seq { for prop in properties -> prop} |> Seq.toArray let randomBrush () = let item = allColours.[Random().Next(allColours.Length)] item.GetValue(null, null) let populateSpec () = { width = (Random().Next(3000)) height = (Random().Next(3000)) colour = (randomBrush ()) :?> Brush filePath = loadLocation overlay = None } let generateSpecs amount = [for i in 1 .. amount -> (populateSpec ()) ] let populateLoadingTestArea () = printfn "[INFO.] Populating LoadingTestArea..." generateSpecs 100 |> List.map makeImage |> Async.Parallel |> Async.RunSynchronously |> ignore printfn "[INFO.] Finishing populating Saving Test Area." module PropertyTests = open FsCheck.Xunit open DeathSocket open System.Drawing open DeathSocket.GridPainter open TestingHelpers [] let ``Can apply grid to image and save it`` () = let spec = { originalPath = "tba" savePath = "tba" colour = randomBrush () :?> Brush penWidth = float32 0.002 rows = 10 columns = 10 } applyGrid spec |> Async.RunSynchronously [] let ``Can populate the LoadingTestArea`` () = populateLoadingTestArea () true = true module UnitTests = open System.IO open TestingHelpers open Xunit // This test is just a check to make sure the property tests have what they need to run. [] let ``LoadingTestArea contains at least 100 test images`` () = let files = Directory.GetFileSystemEntries (loadLocation, "*.png") let length = files.Length let result = if length < 100 then false else true Assert.True result