🃏
Bard
  • Introduction
  • Getting Started
    • Installation
    • Writing Your First Test
    • Configuration
    • .NET Fiddles
  • Anatomy Of A Scenario
    • Given
      • StoryData
      • StoryBook
      • Chapter
      • Story
    • When
    • Then
      • HTTP Response
      • Headers
      • Bad Requests
      • Performance Testing
  • Advanced
    • Dependency Injection
  • Miscellaneous
    • Change Log
    • Migration Guide
  • gRPC
    • Installation
    • Configuration
    • Writing A Test
  • Tips & Tricks
    • FAQ
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Anatomy Of A Scenario
  2. Given

StoryData

PreviousGivenNextStoryBook

Last updated 4 years ago

Was this helpful?

StoryData is a plain old C# object (POCO) of your choice. An instance of this class will be instantiated at the beginning of your test arrangement and is accessible in every story. This means you can enrich your StoryData as your stories progress.

You can only have one instance of StoryData per configured scenario.

The story data can be accessed from within a story from the scenario context.

The example below demonstrates accessing the story data to get the correct id to use in the URL and updating the story data with the result of the API call.

 public DepositMade Deposit_has_been_made(Deposit depositRequest)
 {
    return  
           When(context => 
           {
               var response = context.Api.Post($"api/bankaccounts/{context.StoryData?.BankAccountId}/deposits",
                    depositRequest);
                    
               response.ShouldBe.Ok();
               
               context.StoryData.DepositAmount = depositRequest.Amount;
           })
           .ProceedToChapter<DepositMade>();
 }
Story Data flow