Carna

Home

Carna is a BDD (Behavior Driven Development) style testing and specification framework for .NET Platform.

[Feature("Transfer")]
class TransferFeature
{
    [Story(
        "Transferring money between accounts",
        Benefit = "to manage my money more efficiently",
        Role = "a bank client",
        Feature = "to transfer funds between my accounts whenever I need to"
    )]
    class Story01 : FixtureSteppable
    {
        Client Client { get; set; } = default!;
        
        [Scenario("Transferring money to a savings account")]
        void Scenario01()
        {
            Given("Tess has a Current account with $1,000", () =>
            {
                Client = new Client("Tess");
                Client.Opens(BankAccount.Of(AccountType.Current).WithBalance(1000));
            });
            Given("a Savings account with $2,000", () =>
                Client.Opens(BankAccount.Of(AccountType.Savings).WithBalance(2000))
            );
            When("she transfers $500 from the Current account to the Savings account", () =>
                TransferApi.Amount(500)
                    .From(Client.GetAccount(AccountType.Current))
                    .To(Client.GetAccount(AccountType.Savings))
            );
            Then("she should have $500 in her Current account", () =>
                Client.GetAccount(AccountType.Current).Balance == 500
            );
            Then("she should have $2,500 in her Savings account", () =>
                Client.GetAccount(AccountType.Savings).Balance == 2500
            );
        }

        [Scenario("Transferring with insufficient funds")]
        void Scenario02()
        {
            Given("Tess has a Current account with $1,000", () =>
            {
                Client = new Client("Tess");
                Client.Opens(BankAccount.Of(AccountType.Current).WithBalance(1000));
            });
            Given("a Savings account with $2,000", () =>
                Client.Opens(BankAccount.Of(AccountType.Savings).WithBalance(2000))
            );
            When("she transfers $1,500 from the Current account to the Savings account", () =>
                TransferApi.Amount(1500)
                    .From(Client.GetAccount(AccountType.Current))
                    .To(Client.GetAccount(AccountType.Savings))
            );
            Then<InsufficientFundsException>("she should receive an 'insufficient funds' error");
            Then("she should have $1,000 in Current account", () => 
                Client.GetAccount(AccountType.Current).Balance == 1000
            );
            Then("she should have $2,000 in her Savings account", () =>
                Client.GetAccount(AccountType.Savings).Balance == 2000
            );
        }
    }
}
> dotnet carna-runner
--------------------------------------------
  Carna Console Runner 3.0.0
--------------------------------------------

Feature: Transfer - Passed
  Story: Transferring money between accounts - Passed
    In order to manage my money more efficiently
    As a bank client
    I want to transfer funds between my accounts whenever I need to
      Scenario: Transferring money to a savings account - Passed
        Given Tess has a Current account with $1,000 - Passed
          And a Savings account with $2,000 - Passed
        When she transfers $500 from the Current account to the Savings account - Passed
        Then she should have $500 in her Current account - Passed
         And she should have $2,500 in her Savings account - Passed
      Scenario: Transferring with insufficient funds - Passed
        Given Tess has a Current account with $1,000 - Passed
          And a Savings account with $2,000 - Passed
        When she transfers $1,500 from the Current account to the Savings account - Passed
        Then she should receive an 'insufficient funds' error - Passed
         And she should have $1,000 in Current account - Passed
         And she should have $2,000 in her Savings account - Passed

Run Summary
  Total Count: 2, Passed: 2, Pending: 0, Failed: 0
  Start Time: 2024-07-17 07:57:59Z
    End Time: 2024-07-17 07:57:59Z
    Duration: 0.020 seconds

Current Releases

Carna
carna-runner
Carna.Runner
Carna.ConsoleRunner
Carna.WinUIRunner