1 module tagion.behaviour.BehaviourUnittestWithoutCtor;
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 
45         @Given("the card is valid")
46         Document is_valid() {
47             if (pass_some) {
48                 pass = true;
49             }
50             count++;
51             return result(__FUNCTION__);
52         }
53 
54         @Given("the account is in credit")
55         Document in_credit() {
56             count++;
57             return result(__FUNCTION__);
58         }
59 
60         @Given("the dispenser contains cash")
61         Document contains_cash() {
62             count++;
63             return result(__FUNCTION__);
64         }
65 
66         @When("the Customer request cash")
67         Document request_cash() {
68             if (pass_some) {
69                 pass = false;
70             }
71             count++;
72             return result(__FUNCTION__);
73         }
74 
75         @Then("the account is debited")
76         Document is_debited() {
77             count++;
78             return result(__FUNCTION__);
79         }
80 
81         @Then("the cash is dispensed")
82         Document is_dispensed() {
83             count++;
84             return result(__FUNCTION__);
85         }
86 
87         @But("if the Customer does not take his card, then the card must be swollowed")
88         Document swollow_the_card() {
89             count++;
90             return result(__FUNCTION__);
91         }
92 
93         void helper_function() {
94         }
95     }
96 
97     @safe
98     @Scenario("Some money printer which is controlled by a bankster")
99     class Some_awesome_feature_bad_format_double_property {
100         uint count;
101 
102         @Given("the card is valid")
103         Document is_valid() {
104             if (pass_some || pass_one) {
105                 pass = true;
106             }
107             count++;
108             return result(__FUNCTION__);
109         }
110 
111         @When("the Customer request cash")
112         Document request_cash() {
113             count++;
114             return result(__FUNCTION__);
115         }
116 
117         @Then("the account is debited")
118         Document is_debited() {
119             count++;
120             return result(__FUNCTION__);
121         }
122 
123         @Then("the cash is dispensed")
124         Document is_dispensed() {
125             if (pass_some) {
126                 pass = false;
127             }
128             count++;
129             return result(__FUNCTION__);
130         }
131     }
132 
133 }