namespace ConsoleTests
module TestingHelpers =
open System
open DeathSocketCLI.Validation
let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea"
let loadLocation = __SOURCE_DIRECTORY__ + "/LoadingTestArea"
let testingColourArray =
colourList
|> Map.toSeq
|> Seq.map fst
|> Seq.toArray
let randomColour () =
testingColourArray.[Random().Next(testingColourArray.Length - 1 )]
let randomBrush () =
colourList
|> Map.toSeq
|> Seq.map snd
|> Seq.toArray
|> Array.item (Random().Next(colourList.Count))
module PropertyTests =
open System
open FsCheck.Xunit
open DeathSocketCLI.Validation
open System.Drawing
open TestingHelpers
open DeathSocket.Domain
[<Property>]
let ``Pen width is set greater than 0 `` () =
(setPenWidth (Random().Next()) (Random().Next())) > 0 .0 f
[<Property>]
let ``Parsed colour matches expected colour`` () =
let expectedColour = (randomColour ())
let brush = parseColour (expectedColour)
let convertedBrush = ((brush :?> SolidBrush).Color.Name.ToLower())
convertedBrush = expectedColour
[<Property>]
let ``Can make an intended default image specification`` () =
let loadPath = loadLocation + "/LoadTest.png"
let savePath = saveLocation + "/SaveTest.png"
let defaultSpec =
{ originalPath = loadPath
savePath = savePath
colour = Brushes.White
penWidth = setPenWidth 1000 1000
rows = 10
columns = 10 }
let spec = buildDefaultSpec loadPath savePath
defaultSpec = spec
module UnitTests =
open System.IO
open DeathSocketCLI.Validation
open Xunit
open TestingHelpers
[<Fact>]
let ``Saving Test Area can be located`` () =
Assert.True (Directory.Exists saveLocation)
[<Fact>]
let ``Loading Test Area can be located`` () =
Assert.True (Directory.Exists loadLocation)
[<Fact>]
let ``Colour list is not empty`` () =
Assert.False (colourList.IsEmpty)
[<Fact>]
let ``Exception thrown when invalid colour is used`` () =
Assert.Throws<System.ArgumentException>
(fun () -> parseColour "not a valid colour" |> ignore)