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

  • SEARCH
  • Home
  • 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 8222331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:14:38+00:00 2026-06-07T14:14:38+00:00

In an AutoFixture-based test, I’m trying to express as cleanly as possible the following:

  • 0

In an AutoFixture-based test, I’m trying to express as cleanly as possible the following:

When I pass <input> to the parameter x of this method, filling in the other parameters anonymously, the result is…

Taking the example of a factory method:-

class X
{
    public static X Create( Guid a, Guid b, Guid c, String x, String y);

I’m trying to express as a succinct series of tests:

  1. If I pass null for x, it should throw
  2. If I pass null for y, it should throw

In order to express I can say:

var fixture = Fixture();
var sut = default( Func<Guid, Guid, Guid,string,X>);
sut = fixture.Get( ( Guid anonA, Guid anonB, Guid anonC, string anonY ) => 
    x =>
        X.Create( anonA, anonB, anonC, x, anonY ) );

Assert.Throws<ArgumentNullException>( () => sut( null));

For the second instance, which is only slightly different, I need to do:

var fixture = Fixture();
var sut = default( Func<Guid, Guid, Guid,string,X> );
sut = fixture.Get( ( Guid anonA, Guid anonB, Guid anonC, string anonX ) => 
    y =>
        X.Create( anonA, anonB, anonC, anonX, y ) );
Assert.Throws<ArgumentNullException>( () => sut( null));

For properties, there’s With in AutoFixture. Is there an eqivalent for method (and/or ctor) arguments ?

PS 0. I don’t mind if its necessary to get into ‘magic’ strings for this case – i.e., having the x bit be "x".

PS 1. The other elephant in the room is that I’m bumping my head against the 4x overloads of Get in AutoFixture – or is that because I have an old version in this environment?

PS 2. Also open to better suggestions as to how to model this – as long as they deal with the fact that I want it to be a method invocation and not properties or fields (and I’d like it to work in an AutoFixture stylee).

  • 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-06-07T14:14:40+00:00Added an answer on June 7, 2026 at 2:14 pm

    There really isn’t any feature in AutoFixture that makes this easier, but I’m open to suggestions. However, I don’t see how you could express something like that in a strongly typed fashion. What would the syntax look like?

    However, if you only need this for testing that Null Guards work, you can use AutoFixture.Idioms for that.

    Here’s an example.

    var fixture = new Fixture();
    var assertion = new GuardClauseAssertion(fixture);
    var method = typeof(GuardedMethodHost).GetMethod("ConsumeStringAndInt32AndGuid");
    assertion.Verify(method);
    

    If you look at the source code of Ploeh.AutoFixture.IdiomsUnitTest.Scenario you’ll find other examples, but I admit it’s one of the more poorly documented areas of AutoFixture…

    Another thing entirely is that methods with few (or no) parameters are better than methods with many parameters, so have you considered Introducing a Parameter Object?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We find ourselves coding repetitive fixture/mock setups in many test-cases - like this case:
I'm trying to unit test a custom ConfigurationElementCollection , but I'm having a problem
Referring to django-autofixture documentation , I wrote the following code (edited for terseness): def
I'm trying again to upgrade to AutoFixture 2, and I'm running into a problem
I started to use AutoFixture http://autofixture.codeplex.com/ as my unit tests was bloated with a
I'm trying to use SUT Factory 'pattern' to create my SUT. Given the SUT
I encountered a class during my work that looks like this: public class MyObject
I want to be able to compare the two following objects for likeness using
How do you prevent a CakePHP 2.0 test case, which extends CakeTestCase (uses PHPUnit),
I recently started using AutoFixture library (http://autofixture.codeplex.com/) for Unit Testing and I quite like

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.