Browse Source

add logic to clean TestSaveAea in tests and script.

master
Craig Oates 6 years ago
parent
commit
29e8f46cb2
  1. 2
      SmoulderingBeachBall/ScratchPad.fsx
  2. 23
      TestCentre/LibraryTests.fs
  3. 42
      TestCentre/Script.fsx

2
SmoulderingBeachBall/ScratchPad.fsx

@ -34,7 +34,7 @@ let imageSpec =
{ width = 500;
height = 500;
colour = Brushes.Yellow;
filePath = "C:/users/craig/desktop/test.png";
filePath = "C:/users/craig/desktop/";
// Change this to flip between border/full overlay or None.
overlay = Some fullOverlay }

23
TestCentre/LibraryTests.fs

@ -2,6 +2,7 @@
module PropertyTests =
open Xunit
open FsCheck.Xunit
open System
open System.Drawing
@ -10,8 +11,6 @@
open SmoulderingBeachBall.Services
open System.IO
let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea/"
(* '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.
@ -25,6 +24,8 @@
*)
let randomInt () = Random().Next(3000)
let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea/"
let allColours =
let properties =
typeof<Brushes>.GetProperties(BindingFlags.Public ||| BindingFlags.Static)
@ -38,14 +39,24 @@
item.GetValue(null, null)
let fileSaved width height =
let path = saveLocation + width + "x" + height + ".png"
File.Exists path
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`` () =
// See note accompanying 'randomInt' function for constraints information.
resetSavingTestArea ()
let spec =
{ width = randomInt ()
{ // See note accompanying 'randomInt' function for constraints information.
width = randomInt ()
height = randomInt ()
colour = randomColour () :?> Brush
filePath = saveLocation

42
TestCentre/Script.fsx

@ -1,37 +1,15 @@
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
open System.IO
#load "ConsoleTests.fs"
#load "LibraryTests.fs"
let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea/"
open ConsoleTests
open LibraryTests
open System.Drawing
open System.Reflection
open System
let resetSavingTestArea () =
let files = Directory.GetFileSystemEntries(saveLocation)
match files.Length with
| 0 -> ()
| _ ->
files
|> Array.iter (fun f -> File.Delete(f))
// Define your library scripting code here
let allBrushColours =
let properties =
Color().GetType().GetProperties()
let names =
seq { for prop in properties do
yield prop.Name }
|> Seq.toList
names
let allBrushes =
let properties =
typeof<Brushes>.GetProperties(BindingFlags.Public|||BindingFlags.Static)
let colours =
seq { for prop in properties -> prop}
|> Seq.toArray
colours
let randomColour () =
let item = allBrushes.[Random().Next (allBrushes.Length)]
item.GetValue(null, null)
printfn "%A" allBrushes
printfn "%A" (randomColour ())
resetSavingTestArea ()
Loading…
Cancel
Save