From d05e56c91377115281452e56e3b0d85adbd8af1b Mon Sep 17 00:00:00 2001 From: "OPTIMUS-PRIME\\craig" Date: Fri, 7 Sep 2018 17:37:00 +0100 Subject: [PATCH] add UnitTests module and initial tests for console project. --- SmoulderingBeachBallCLI/Validation.fs | 12 ++++---- TestCentre/ConsoleTests.fs | 41 +++++++++++++++++++++++---- TestCentre/Script.fsx | 5 ++-- TestCentre/TestCentre.fsproj | 3 ++ TestCentre/packages.config | 1 + 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/SmoulderingBeachBallCLI/Validation.fs b/SmoulderingBeachBallCLI/Validation.fs index ef7473e..774e384 100644 --- a/SmoulderingBeachBallCLI/Validation.fs +++ b/SmoulderingBeachBallCLI/Validation.fs @@ -16,11 +16,11 @@ "yellow", Brushes.Yellow;] |> Map.ofList - let isColourValid (colour: string) = + let private isColourValid (colour: string) = colourList |> Map.containsKey (colour.ToLower()) - let parseColour colour = + let private parseColour colour = match (isColourValid colour) with | true -> colourList @@ -33,7 +33,7 @@ let getDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) - let parsePath (path: string) = + let private parsePath (path: string) = match path with | path when ((path.ToLower()).Equals "desktop") -> getDesktopPath | path when ((path.ToLower()).Equals "d") -> getDesktopPath @@ -52,7 +52,7 @@ } spec - let parseOverlay (oType: string) = + let private parseOverlay (oType: string) = match oType.ToLower() with | "border" -> Border | "b" -> Border @@ -60,13 +60,13 @@ | "f" -> Full | _ -> invalidArg "Overlay Type" "The overlay type must be either 'border' or 'full'." - let buildOverlaySpec oColour (oType: string) = + let private buildOverlaySpec oColour (oType: string) = let oSpec = { colour = parseColour oColour; overlayType = parseOverlay oType } oSpec - let buildMainSpec iWidth iHeight mainColour path oSpec = + let private buildMainSpec iWidth iHeight mainColour path oSpec = let spec = { width = iWidth; height = iHeight; diff --git a/TestCentre/ConsoleTests.fs b/TestCentre/ConsoleTests.fs index 690021b..5bd7e96 100644 --- a/TestCentre/ConsoleTests.fs +++ b/TestCentre/ConsoleTests.fs @@ -2,15 +2,44 @@ module PropertyTests = - open Xunit open FsCheck open FsCheck.Xunit open Validation - - let config = { FsCheck.Config.Default with MaxTest = 10 } + open System + open SmoulderingBeachBall.Domain.DomainTypes + open System.Drawing [] - let ``colour map is not empty`` () = - (Map.isEmpty colourList) = false + let ``buildDefaultSpec creates intended type`` () = + let width = Random().Next() + let height = Random().Next() + 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 - Check.Quick (``colour map is not empty`` ()) \ No newline at end of file + Check.Quick (``buildDefaultSpec creates intended type`` ()) + + module UnitTests = + + open Xunit + open Validation + open System + + [] + let ``Colour map is not empty`` () = + Assert.NotEmpty colourList + + [] + let ``getDesktopPath returns desktop path`` () = + let expectedPath = + Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Assert.Equal (expectedPath, getDesktopPath) \ No newline at end of file diff --git a/TestCentre/Script.fsx b/TestCentre/Script.fsx index 1845605..c3b5e6c 100644 --- a/TestCentre/Script.fsx +++ b/TestCentre/Script.fsx @@ -1,8 +1,9 @@ // Learn more about F# at http://fsharp.org // See the 'F# Tutorial' project for more help. -#load "Library1.fs" -open TestCentre +#load "ConsoleTests.fs" + +open ConsoleTests // Define your library scripting code here diff --git a/TestCentre/TestCentre.fsproj b/TestCentre/TestCentre.fsproj index 74e7271..b72f52d 100644 --- a/TestCentre/TestCentre.fsproj +++ b/TestCentre/TestCentre.fsproj @@ -64,6 +64,9 @@ + + ..\packages\System.Drawing.Common.4.5.0\lib\net461\System.Drawing.Common.dll + True diff --git a/TestCentre/packages.config b/TestCentre/packages.config index 0e1b818..6de53e1 100644 --- a/TestCentre/packages.config +++ b/TestCentre/packages.config @@ -3,6 +3,7 @@ +