Browse Source

add UnitTests module and initial tests for console project.

master
Craig Oates 6 years ago
parent
commit
d05e56c913
  1. 12
      SmoulderingBeachBallCLI/Validation.fs
  2. 41
      TestCentre/ConsoleTests.fs
  3. 5
      TestCentre/Script.fsx
  4. 3
      TestCentre/TestCentre.fsproj
  5. 1
      TestCentre/packages.config

12
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;

41
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
[<Property>]
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`` ())
Check.Quick (``buildDefaultSpec creates intended type`` ())
module UnitTests =
open Xunit
open Validation
open System
[<Fact>]
let ``Colour map is not empty`` () =
Assert.NotEmpty colourList
[<Fact>]
let ``getDesktopPath returns desktop path`` () =
let expectedPath =
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
Assert.Equal (expectedPath, getDesktopPath)

5
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

3
TestCentre/TestCentre.fsproj

@ -64,6 +64,9 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Drawing.Common">
<HintPath>..\packages\System.Drawing.Common.4.5.0\lib\net461\System.Drawing.Common.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.ValueTuple">
<Private>True</Private>

1
TestCentre/packages.config

@ -3,6 +3,7 @@
<package id="FsCheck" version="2.11.0" targetFramework="net471" />
<package id="FsCheck.Xunit" version="2.11.0" targetFramework="net471" />
<package id="FSharp.Core" version="4.5.2" targetFramework="net471" />
<package id="System.Drawing.Common" version="4.5.0" targetFramework="net471" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net471" />
<package id="xunit" version="2.4.0" targetFramework="net471" />
<package id="xunit.abstractions" version="2.0.3" targetFramework="net471" />

Loading…
Cancel
Save