1 module tagion.behaviour.BehaviourUnittestWithCtor; 2 3 import tagion.behaviour.BehaviourFeature; 4 5 /// This module is only use to support the unittest 6 version (unittest) { 7 import std.format; 8 import std.process; 9 import std.typecons : Tuple; 10 import tagion.behaviour.BehaviourException; 11 import tagion.behaviour.BehaviourResult; 12 import tagion.hibon.Document; 13 import tagion.hibon.HiBON; 14 15 bool pass; /// Pass the test 16 bool pass_one; /// Pass only one scenario 17 bool pass_some; /// Pass some of the scenario 18 19 @safe 20 Document result(string test) { 21 if (pass) { 22 auto h = new HiBON; 23 h["test"] = test; 24 Result result; 25 result.outcome = Document(h); 26 return result.toDoc; 27 } 28 // Return a docunent which is not a Result 29 return Document(); 30 } 31 32 enum feature = Feature("Some awesome feature should print some cash out of the blue"); 33 alias FeatureContext = Tuple!( 34 Some_awesome_feature, "Some_awesome_feature", 35 Some_awesome_feature_bad_format_double_property, "Some_awesome_feature_bad_format_double_property", 36 FeatureGroup*, "result" 37 ); 38 // Behavioral examples 39 @safe 40 @Scenario("Some awesome money printer") 41 class Some_awesome_feature { 42 uint count; 43 string text; 44 @disable this(); 45 this(const uint count, string text) { 46 this.count = count; 47 this.text = text; 48 } 49 50 @Given("the card is valid") 51 Document is_valid() { 52 if (pass_some) { 53 pass = true; 54 } 55 count++; 56 return result(__FUNCTION__); 57 } 58 59 @Given("the account is in credit") 60 Document in_credit() { 61 count++; 62 return result(__FUNCTION__); 63 } 64 65 @Given("the dispenser contains cash") 66 Document contains_cash() { 67 count++; 68 return result(__FUNCTION__); 69 } 70 71 @When("the Customer request cash") 72 Document request_cash() { 73 if (pass_some) { 74 pass = false; 75 } 76 count++; 77 return result(__FUNCTION__); 78 } 79 80 @Then("the account is debited") 81 Document is_debited() { 82 count++; 83 return result(__FUNCTION__); 84 } 85 86 @Then("the cash is dispensed") 87 Document is_dispensed() { 88 count++; 89 return result(__FUNCTION__); 90 } 91 92 @But("if the Customer does not take his card, then the card must be swollowed") 93 Document swollow_the_card() { 94 count++; 95 return result(__FUNCTION__); 96 } 97 98 void helper_function() { 99 } 100 } 101 102 @safe 103 @Scenario("Some money printer which is controlled by a bankster", 104 ["The bankster has a big heart so shares some of the money to politicians"] 105 ) 106 class Some_awesome_feature_bad_format_double_property { 107 uint count; 108 @disable this(); 109 this(const uint count) { 110 this.count = count; 111 } 112 113 @Given("the card is valid") 114 Document is_valid() { 115 if (pass_some || pass_one) { 116 pass = true; 117 } 118 count++; 119 return result(__FUNCTION__); 120 } 121 122 @When("the Customer request cash") 123 Document request_cash() { 124 count++; 125 return result(__FUNCTION__); 126 } 127 128 @Then("the account is debited") 129 Document is_debited() { 130 count++; 131 return result(__FUNCTION__); 132 } 133 134 @Then("the cash is dispensed") 135 Document is_dispensed() { 136 if (pass_some) { 137 pass = false; 138 } 139 count++; 140 return result(__FUNCTION__); 141 } 142 } 143 144 }