StoryBook
As described in the introduction a StoryBook is the starting Chapter of our Scenario.
Lets illustrate what that really means, with an example. I will use my fictitious Banking API to demonstrate.
We want to test the scenario in our Banking API that the balance of our account is correct after we make a cash deposit.
Before we can do that there are a couple of steps we need to do to test that scenario.
    1.
    Create the bank account
    2.
    Deposit the money into the correct account.
In Bard after we have created the bank account we can pass the results from the 'Create Bank Account' story into the 'Deposit Money' story this is useful because we probably need to know the Id of the newly created bank account.
Lets demonstrate what that would look like with a code example.
1
public BankAccountHasBeenCreated BankAccount_has_been_created()
2
{
3
return When(context =>
4
{
5
var bankAccount = new BankAccount
6
{
7
CustomerName = "Ranulph Fiennes"
8
};
9
​
10
var response = context.Api.Post("api/bankaccounts", bankAccount);
11
12
context.StoryData.BankAccountId = response.Id;
13
})
14
.ProceedToChapter<BankAccountHasBeenCreated>();
15
}
Copied!
Lets talk about what's going on in that example. The first thing to note is we are calling the base method When and this is where we do the 'work' of the story is done by calling our create bank account endpoint. Notice that we are making our API call using our TestContext on line 10.
Now on line 12 we are returning we are updating our StoryData with the response from the API call, making that data available to the next story.
1
context.StoryData.BankAccountId = response.Id;
Copied!
Finally on line 14 we call the generic ProceedToChapter base method. This instructs our fluent API what the next Chapter is that will help us build out our Fluent Test interface.
1
.ProceedToChapter<BankAccountHasBeenCreated>();
Copied!
​
​
Last modified 1yr ago
Export as PDF
Copy link