The purpose of this repository is to provide a way for people to create placeholder images quickly.
https://www.craigoates.net/Software/project/11
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.6 KiB
65 lines
2.6 KiB
namespace LibraryTests |
|
|
|
module PropertyTests = |
|
|
|
open Xunit |
|
open FsCheck.Xunit |
|
open System |
|
open System.Drawing |
|
open SmoulderingBeachBall.Domain.DomainTypes |
|
open System.Reflection |
|
open SmoulderingBeachBall.Services |
|
open System.IO |
|
|
|
(* '3000' is an arbitary value. It is used to keep the testing times sane. |
|
This function is used to randomly generate image sizes but you do not need to use it. |
|
The project can handle larger numbers than '3000' but processing takes longer. |
|
If you decide to change it, please keep an eye on the saving time. |
|
When a image is too big, the project cannot write it to disc fast enough -- |
|
sometimes it is because of IO constraints. |
|
This means the tests checking for this fail/error will think the image does not exist. |
|
To resolved this, add a Thread.Sleep call to the affected tests. |
|
Just be aware, the length of sleep-time depends on the size of the image. |
|
Also, problems tends to arise around the 15,000 mark. |
|
*) |
|
let randomInt () = Random().Next(3000) |
|
|
|
let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea/" |
|
|
|
let allColours = |
|
let properties = |
|
typeof<Brushes>.GetProperties(BindingFlags.Public ||| BindingFlags.Static) |
|
let colours = |
|
seq { for prop in properties -> prop} |
|
|> Seq.toArray |
|
colours |
|
|
|
let randomColour () = |
|
let item = allColours.[Random().Next(allColours.Length)] |
|
item.GetValue(null, null) |
|
|
|
let fileSaved width height = |
|
saveLocation + width + "x" + height + ".png" |
|
|> File.Exists |
|
|
|
// To manually clear out the SavingTestArea folder, use this function in script.fsx. |
|
let resetSavingTestArea () = |
|
let files = Directory.GetFileSystemEntries(saveLocation) |
|
match files.Length with |
|
| 0 -> () |
|
| _ -> |
|
files |
|
|> Array.iter (fun f -> File.Delete(f)) |
|
|
|
[<Property>] |
|
let ``can create an image with no overlay`` () = |
|
resetSavingTestArea () |
|
let spec = |
|
{ // See note accompanying 'randomInt' function for constraints information. |
|
width = randomInt () |
|
height = randomInt () |
|
colour = randomColour () :?> Brush |
|
filePath = saveLocation |
|
overlay = None } |
|
makeImage spec |> Async.RunSynchronously |
|
fileSaved (spec.width.ToString()) (spec.height.ToString()) = true
|
|
|