namespace LibraryTests module TestingHelpers = open System open System.Drawing open System.Reflection open System.IO let loadLocation = __SOURCE_DIRECTORY__ + "/LoadingTestArea" let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea" 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 imagesInLoadingTestArea = Directory.GetFileSystemEntries (loadLocation, "*.png") let generateLoadPath () = let rand = Random () let files = imagesInLoadingTestArea files.[rand.Next(files.Length)] let generateSavePath originalFilePath = let fileName = Path.GetFileName originalFilePath saveLocation + "/" + fileName let fileSaved path = File.Exists path module PropertyTests = open FsCheck.Xunit open DeathSocket open System.Drawing open DeathSocket.GridPainter open TestingHelpers open System.IO [] let ``Can apply grid to image and save it`` () = let oPath = generateLoadPath () let sPath = generateSavePath oPath let spec = { originalPath = oPath savePath = sPath colour = randomBrush () :?> Brush penWidth = float32 0.1 rows = 10 columns = 10 } applyGrid spec |> Async.RunSynchronously (File.Exists sPath) = 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 length = imagesInLoadingTestArea.Length let imagesAreThere = if length < 100 then false else true Assert.True imagesAreThere