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.

106 lines
4.1 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 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. If you do decide to move them
out, pay attention to ConsoleTests.fs and its helper functions. *)
open System
open System.Drawing
open System.Reflection
open System.IO
(* These are duplicates from ConsoleTests.fs (both of them). See point
about helpers. Tests for checking these locations can be found in
ConsoleTests.fs.*)
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
(* To "manually" clear out the SavingTestArea folder, use this function
in script.fsx. More information can be found there, also.*)
let resetSavingTestArea () =
let files = Directory.GetFileSystemEntries(saveLocation, "*.png")
match files.Length with
| 0 -> ()
| _ ->
files
|> Array.iter (fun f -> File.Delete(f))
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`` () =
(* You should end up with one image left over in SavingTestArea.
Comment out the "reset" function to see all the images produced,
by this test. This will mean you will need to manually delete the
images yourself if you do.*)
resetSavingTestArea ()
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