Skip to content

Commit

Permalink
Add documentation for reading variables from environment variables #409
Browse files Browse the repository at this point in the history
… and also to override the definition of a variable in a config file #410
  • Loading branch information
Cédric L. Charlier committed Nov 1, 2018
1 parent bd7b7f0 commit 2502d44
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
1 change: 1 addition & 0 deletions _data/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
- title: Global variables
docs:
- variable-define
- variable-override

- title: Metadata
docs:
Expand Down
2 changes: 1 addition & 1 deletion _documentation/metadata-concept.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: documentation
title: Concept of metadata
prev_section: variable-define
prev_section: variable-override
next_section: metadata-description
permalink: /docs/metadata-concept/
---
Expand Down
40 changes: 36 additions & 4 deletions _documentation/variable-define.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: documentation
title: Define variables
prev_section: config-traces-debugging
next_section: metadata-concept
next_section: variable-override
permalink: /docs/variable-define/
---
Version 1.17 has introduced the notion of *variable*. A variable is a scalar-value (a unique value, not a list of a result-set) that can be reused in different places of your test-suites. another big advantage of variables is that they are evaluated during the test-suite execution. Suppose that you have a query expecting a date as a parameter and that you want to specify the current date: without a variable, it's not possible!
Expand All @@ -26,25 +26,57 @@ The variables are defined at the top of the test-suite (after *settings* but bef
</variables>
{% endhighlight %}

As you can understand fom the fragment above, a variable can be evaluated based on two engines: *C#* and *query-scalar*
As you can understand fom the fragment above, a variable can be evaluated based on different engines.

## C# engine

This engine evaluates one unique sentence of C# and returns the corresponding value. In order to specify this engine use the element *script* and specify the attribute *language* to the value *c-sharp*. Then you'll be ableto specify your c# sentence in the inner text of this element. Note that thsi sentence shouldn't start by *return* and neither end by a semi-column (;).

In this example, the variable named *FirstOfCurrentMonth* is set to the value returned by the C# script:

{% highlight xml %}
<variable name="FirstOfCurrentMonth">
<script language="c-sharp">
DateTime.Now.AddDays(1 - DateTime.Now.Day)
</script>
</variable>
{% endhighlight %}

## Query engine

This engine evaluates a query and returns the first cell of the first row returned by this query. In order to specify this engine use the element *query-scalar* and specify. Then you'll be able to specify a query with the different methods available in the [NBi syntax 2.0 to define a query](../docs/syntax-2-0).

In this example, the variable named *CurrencyCode* is set to the single value returned by the query here under:

{% highlight xml %}
<variable name="CurrencyCode">
<query-scalar>
<![CDATA[select top(1) CurrencyCode from [Sales].[Currency] where Name like '%Canad%']]>
</query-scalar>
</variable>
{% endhighlight %}

## Environment variable

This engine retrieves the value of an environment variable.

In this example, the variable named *myVar* is set to the value of the environment variable named *MyEnvVar*:

{% highlight xml %}
<variable name="myVar"/>
<environment name="MyEnvVar"/>
</variable>
{% endhighlight %}

# Usage

In this first release, you can't use the variables at many places. the usage is strictly limited to the following places:

* *[Parameter](..docs/query-parameter)* (of a query)
* In the [comparisons (*equal*, *more-than*, *less-than*)](../docs/resultset-rows-count) for a *row-count*
* In the [predicates](../docs/resultset-predicate) of the assertions *row-count*, *all-rows*, *no-rows*, *some-rows* and *single-row*
* In the operators of [predicates](../docs/resultset-predicate) of the assertions *row-count*, *all-rows*, *no-rows*, *some-rows* and *single-row*

If you've other places, where you think that a variable would be helpful, report it by creating an [issues](http://github.com/Seddryck/nbi/issues)
If you've other places, where you think that a variable would be helpful, report it by creating an [issue](http://github.com/Seddryck/nbi/issues)

# Notes about the future of variables

Expand Down
21 changes: 21 additions & 0 deletions _documentation/variable-override.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
layout: documentation
title: Override variables
prev_section: variable-define
next_section: metadata-concept
permalink: /docs/variable-override/
---
Version 1.19 introduces the notion of *override* in a *variable*. This option offers the opportunity to enforce the value of a *variable* using a config file.

# Config file

To enforce the value of one or more variables, you must enlist them in the *variables* element of the config file. The attribute *name* specifies the name of the overriden variable, the attribute *value* specifies the value to apply to this variable and finally the attribute *type* sepcifies the type of the variable (could be *text*, *numeric*, *dateTime* or *boolean*).

{% highlight xml %}
<nbi ...>
<variables>
<add name="myDate" value="2013-12-01" type="DateTime"/>
<add name="myNum" value="187" type="Numeric"/>
</variables>
</nbi>
{% endhighlight %}

0 comments on commit 2502d44

Please sign in to comment.