Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 808661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:35:53+00:00 2026-05-15T00:35:53+00:00

I was tinkering with doing the setups with our unit test specifciations which go

  • 0

I was tinkering with doing the setups with our unit test specifciations which go like

Specification for SUT when behaviour X happens in scenario Y
Given that this thing
And also this other thing
When I do X…
Then It should do …
And It should also do …

I wrapped each of the steps of the GivenThat in Actions… any feed back whether separating with Actions is good / bad / or better way to make the GivenThat clear?

        /// <summary>
        /// Given a product is setup for injection
        ///     And Product Image Factory Is Stubbed();
        ///     And Product Size Is Stubbed();
        ///     And Drawing Scale Is Stubbed();
        ///     And Product Type Is Stubbed();
        /// </summary>
        protected override void GivenThat()
        {
            base.GivenThat();

            Action givenThatAProductIsSetupforInjection = () =>
              {
                  var randomGenerator = new RandomGenerator();

                  this.Position = randomGenerator.Generate<Point>();

                  this.Product = new Diffuser
                                     {
                                         Size =
                                             new RectangularProductSize(
                                             2.Inches()),
                                         Position = this.Position,
                                         ProductType =
                                             Dep<IProductType>()
                                     };
              };

            Action andProductImageFactoryIsStubbed = () => Dep<IProductBitmapImageFactory>().Stub(f => f.GetInstance(Dep<IProductType>())).Return(ExpectedBitmapImage);

            Action andProductSizeIsStubbed = () =>
                 {
                     Stub<IDisplacementProduct, IProductSize>(p => p.Size);

                     var productBounds = new ProductBounds(Width.Feet(), Height.Feet());

                     Dep<IProductSize>().Stub(s => s.Bounds).Return(productBounds);
                 };

            Action andDrawingScaleIsStubbed = () => Dep<IDrawingScale>().Stub(s => s.PixelsPerFoot).Return(PixelsPerFoot);

            Action andProductTypeIsStubbed = () => Stub<IDisplacementProduct, IProductType>(p => p.ProductType);

            givenThatAProductIsSetupforInjection();
            andProductImageFactoryIsStubbed();
            andProductSizeIsStubbed();
            andDrawingScaleIsStubbed();
            andProductTypeIsStubbed();
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:35:54+00:00Added an answer on May 15, 2026 at 12:35 am

    Put them in separate methods so that you can compose them in other givens. Also, use underscores to replace spaces (instead of camel case). Also, create a method Given_that that takes params of Action delegates.

    protected void Given_that(params Action[] preconditions)
    {
        foreach (var action in preconditions)
        {
            action();
        }
    }
    
    ...
    
    protected void a_product_is_set_up_for_injection()
    {
        ...
    }
    
    protected void product_image_factory_is_stubbed()
    {
        ...
    }
    
    etc...
    
    ...
    
    Given_that(a_product_is_set_up_for_injection,
               product_image_factory_is_stubbed,
               product_size_is_stubbed,
               drawing_scale_is_stubbed,
               product_type_is_stubbed);
    

    That being said, I think the naming of your preconditions are not BDD. They are very technical in nature and do not denote the business need. If you were to tell a non-programmer what you were testing, you would probably not say “the product is stubbed for injection.” You would more likely say

    Given a displacement product
        that is a two inch rectangular diffuser
        that has a random position
        that has a bitmap
        that has a size bounded by feet
        that has the expected pixels per foot
    

    Now you can compose your “given” methods with little duplication:

    protected [the type of your test class] Given(params Action given)
    {
        given();
        return this;
    }
    
    protected void That(params Action[] preconditions)
    {
        foreach (var precondition in preconditions)
        {
            precondition();
        }
    }
    
    Given(a_displacement_product)
        .That(is_a_two_inch_rectangular_diffuser,
              has_a_random_position,
              has_a_bitmap,
              has_a_size_bounded_by_feet,
              has_the_expected_pixels_per_foot);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently tinkering around with Workflow Foundation. I have an activity which contains the
I'm tinkering with writing a simple text-based role-playing game. I would like to use
I'm tinkering with a domain name finder and want to favour those words which
I'm tinkering with Silverlight 2.0. I have some images, which I currently have a
I was doing some .NET programming in WPF which involved reading .png and .txt
I have a directory named tinkering which has following subdirectories: saraswati\ and\ durga\ pooja
I'm tinkering with a projecteuler problem and I encountered the following really odd behaviour.
I'm new to tinkering with app.config and xml, and am currently doing some refactoring
I'm interested in doing some tinkering on compiled Class files before they're converted to
I have been tinkering around with OOP and seeing how to go about doing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.