# HG changeset patch # User IBBoard # Date 1301859642 0 # Node ID 50cd43bf51b3259d68b03a03bb5e3c9b2458d534 # Parent 4497ebce9a57e052bd4dafb46b177c79c4a45345 Re #27: Unit requirements * Add tri-state enum (passed, failed, not applicable) and helper class diff -r 4497ebce9a57 -r 50cd43bf51b3 API/Objects/Requirement/Validation.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/Validation.cs Sun Apr 03 19:40:42 2011 +0000 @@ -0,0 +1,54 @@ +// This file (Validation.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. +using System; + +namespace IBBoard.WarFoundry.API.Objects.Requirement +{ + /// + /// A custom enum for validation to distinguish between "validation wasn't necessary" and "validation passed". + /// This should allow for easier handling of failed requirements later being satisfied. + /// + public enum Validation + { + Passed = 1, + Failed = 2, + NotApplicable = 3 + } + + /// + /// A helper class to handle the enums and treat them as booleans where a pass/fail is all that is necessary. + /// + public class Validates + { + /// + /// Checks if the validation was okay (pass or not applicable) + /// + /// + /// true if the validation passed or was not applicable, else false + /// + /// + /// The Validation enum value to check + /// + public static bool AsOkay(Validation result) + { + return (result | Validation.Passed) == Validation.Passed; + } + + /// + /// Checks if the validation result was not okay (failed or not applicable). Note that this is different + /// to !Validates.AsOkay(result) because this method treats not applicable as not being okay. + /// + /// + /// true if the validation failed or was not applicable, else false + /// + /// + /// The Validation enum value to check + /// + public static bool AsNotOkay (Validation result) + { + return (result | Validation.Failed) == Validation.Failed; + } + } +} + diff -r 4497ebce9a57 -r 50cd43bf51b3 IBBoard.WarFoundry.API.csproj --- a/IBBoard.WarFoundry.API.csproj Sun Apr 03 19:03:30 2011 +0000 +++ b/IBBoard.WarFoundry.API.csproj Sun Apr 03 19:40:42 2011 +0000 @@ -1,5 +1,5 @@ - + Debug AnyCPU @@ -189,6 +189,7 @@ +