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.
71 lines
2.2 KiB
71 lines
2.2 KiB
namespace LibraryTests |
|
|
|
module TestingHelpers = |
|
|
|
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 |
|
|
|
let fileSaved path = File.Exists path |
|
|
|
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 0.1 |
|
rows = 10 |
|
columns = 10 } |
|
applyGrid spec |
|
|> Async.RunSynchronously |
|
(File.Exists sPath) = true |
|
|
|
module UnitTests = |
|
|
|
open System.IO |
|
open TestingHelpers |
|
open Xunit |
|
|
|
// This test is just a check to make sure the property tests have what they need to run. |
|
[<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 |