|
|
|
namespace ConsoleTests
|
|
|
|
|
|
|
|
module PropertyTests =
|
|
|
|
|
|
|
|
open FsCheck.Xunit
|
|
|
|
open Validation
|
|
|
|
open System
|
|
|
|
open SmoulderingBeachBall.Domain.DomainTypes
|
|
|
|
open System.Drawing
|
|
|
|
|
|
|
|
(* The functions without the "Property" attribute are not for testing.
|
|
|
|
They generate the test data used in the (property) tests.
|
|
|
|
Please be careful when removing any of these types of functions.
|
|
|
|
They are the ones not marked with the "Property" attribute.
|
|
|
|
Also, the intention is to keep these functions seperate from the tests.
|
|
|
|
Until it is not practical to keep them in this module, the default place to keep them is above the tests. With that said, it is just a guide.
|
|
|
|
Use your best judgement when adding new "helper" functions.
|
|
|
|
This applies to the UnitTests module, thanks. *)
|
|
|
|
|
|
|
|
let randomInt () = Random().Next()
|
|
|
|
|
|
|
|
let randomColour () =
|
|
|
|
colourList
|
|
|
|
|> Map.toList
|
|
|
|
|> List.item (Random().Next(colourList.Count))
|
|
|
|
|
|
|
|
let overlays = [|"none"; "n"; "b"; "border"; "full"; "f"|]
|
|
|
|
|
|
|
|
let noOverlay () = overlays.[Random().Next(0, 1)]
|
|
|
|
|
|
|
|
let borderOverlay () = overlays.[Random().Next(2, 3)]
|
|
|
|
|
|
|
|
let fullOverlay () = overlays.[Random().Next(4, 5)]
|
|
|
|
|
|
|
|
[<Property>]
|
|
|
|
let ``Can create an intended default image spec`` () =
|
|
|
|
let width = randomInt ()
|
|
|
|
let height = randomInt ()
|
|
|
|
let oSpec =
|
|
|
|
{ colour = Brushes.Black
|
|
|
|
overlayType = Full }
|
|
|
|
let defaultSpec =
|
|
|
|
{ width = width
|
|
|
|
height = height
|
|
|
|
colour = Brushes.AntiqueWhite
|
|
|
|
filePath = getDesktopPath
|
|
|
|
overlay = Some oSpec
|
|
|
|
}
|
|
|
|
let spec = buildDefaultSpec width height
|
|
|
|
defaultSpec = spec
|
|
|
|
|
|
|
|
[<Property>]
|
|
|
|
let ``Can create an image spec with border`` () =
|
|
|
|
let width = randomInt ()
|
|
|
|
let height = randomInt ()
|
|
|
|
let mainColour = randomColour ()
|
|
|
|
let overlayColour = randomColour ()
|
|
|
|
let overlay = borderOverlay ()
|
|
|
|
let oSpec =
|
|
|
|
{ colour = (snd) overlayColour
|
|
|
|
overlayType = Border }
|
|
|
|
let expectedSpec =
|
|
|
|
{ width = width
|
|
|
|
height = height
|
|
|
|
colour = (snd) mainColour
|
|
|
|
filePath = getDesktopPath
|
|
|
|
overlay = Some oSpec
|
|
|
|
}
|
|
|
|
let spec =
|
|
|
|
buildSpec width height (fst mainColour) (fst overlayColour) overlay getDesktopPath
|
|
|
|
expectedSpec = spec
|
|
|
|
|
|
|
|
[<Property>]
|
|
|
|
let ``Can create an image spec with full overlay`` () =
|
|
|
|
let width = randomInt ()
|
|
|
|
let height = randomInt ()
|
|
|
|
let mainColour = randomColour ()
|
|
|
|
let overlayColour = randomColour ()
|
|
|
|
let overlay = fullOverlay ()
|
|
|
|
let oSpec =
|
|
|
|
{ colour = snd overlayColour
|
|
|
|
overlayType = Full }
|
|
|
|
let expectedSpec =
|
|
|
|
{ width = width
|
|
|
|
height = height
|
|
|
|
colour = snd mainColour
|
|
|
|
filePath = getDesktopPath
|
|
|
|
overlay = Some oSpec }
|
|
|
|
let spec =
|
|
|
|
buildSpec width height (fst mainColour) (fst overlayColour) overlay getDesktopPath
|
|
|
|
expectedSpec = spec
|
|
|
|
|
|
|
|
[<Property>]
|
|
|
|
let ``Can create an image spec with no overlay`` () =
|
|
|
|
let width = randomInt ()
|
|
|
|
let height = randomInt ()
|
|
|
|
let colour = randomColour ()
|
|
|
|
let overlay = noOverlay ()
|
|
|
|
let expectedSpec =
|
|
|
|
{ width = width
|
|
|
|
height = height
|
|
|
|
colour = snd colour
|
|
|
|
filePath = getDesktopPath
|
|
|
|
overlay = option.None }
|
|
|
|
let spec =
|
|
|
|
buildSpec width height (fst colour) (fst colour) overlay getDesktopPath
|
|
|
|
expectedSpec = spec
|
|
|
|
|
|
|
|
module UnitTests =
|
|
|
|
|
|
|
|
open Xunit
|
|
|
|
open Validation
|
|
|
|
open System
|
|
|
|
|
|
|
|
[<Fact>]
|
|
|
|
let ``Colour map is not empty`` () =
|
|
|
|
Assert.NotEmpty colourList
|
|
|
|
|
|
|
|
[<Fact>]
|
|
|
|
let ``Can retrieve the path to users desktop`` () =
|
|
|
|
let expectedPath =
|
|
|
|
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
|
|
|
|
Assert.Equal (expectedPath, getDesktopPath)
|