Death Socket consists of three projects. They are a .Net Standard 2.0 library, a console program and a Test Centre. The purpose of this repository is to provide a way for people to add grids to images. https://www.craigoates.net/Software/project/13
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
3.2 KiB

namespace LibraryTests
(* Initial Setup -- Populating the Test Folders.
===========================================================================
If you have just cloned this repository or have not run any of the tests
before, please head over to script.fs (in Test Centre) and populate the
LoadingTestArea and SavingTestArea folders. More information will be
provided there about what the scripts do. It is worth pointing out here,
though, the .gitignore file ignores any .png files in them.
This is why you must populate them before running any tests. *)
module TestingHelpers =
(* When you are writing tests, please keep all helper functions in this
module. If this module grows to a point where it hinders the actual
testing modules, consider moving it then. *)
open System
open System.Drawing
open System.Reflection
open System.IO
let loadLocation = __SOURCE_DIRECTORY__ + "/LoadingTestArea"
let saveLocation = __SOURCE_DIRECTORY__ + "/SavingTestArea"
let allColours =
let properties =
typeof<Brushes>.GetProperties(BindingFlags.Public ||| BindingFlags.Static)
seq { for prop in properties -> prop}
|> Seq.toArray
let randomBrush () =
let item = allColours.[Random().Next(allColours.Length)]
item.GetValue(null, null)
let imagesInLoadingTestArea =
Directory.GetFileSystemEntries (loadLocation, "*.png")
let generateLoadPath () =
let rand = Random ()
let files = imagesInLoadingTestArea
files.[rand.Next(files.Length)]
let generateSavePath originalFilePath =
let fileName = Path.GetFileName originalFilePath
saveLocation + "/" + fileName
module PropertyTests =
open FsCheck.Xunit
open DeathSocket
open System.Drawing
open DeathSocket.GridPainter
open TestingHelpers
open System.IO
[<Property>]
let ``Can apply grid to image and save it`` () =
let oPath = generateLoadPath ()
let sPath = generateSavePath oPath
let spec =
{ originalPath = oPath
savePath = sPath
colour = randomBrush () :?> Brush
penWidth = float32 1
rows = 10
columns = 10 }
applyGrid spec
|> Async.RunSynchronously
(File.Exists sPath) = true
module UnitTests =
open TestingHelpers
open Xunit
(* This test is a precaution (a test for the tests if you will...).
It is here to make sure the property test has what it needs to run.
If the property test fails, here is a good place to start.
See script.fs (in Test Centre) for information on populating the
LoadingTestArea folder. *)
[<Fact>]
let ``LoadingTestArea contains at least 100 test images`` () =
let length = imagesInLoadingTestArea.Length
let imagesAreThere = if length < 100 then false else true
Assert.True imagesAreThere