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 7808551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:10:03+00:00 2026-06-02T03:10:03+00:00

Let’s say I have interface: public interface IFoo { int Bar1 { get; set;

  • 0

Let’s say I have interface:

public interface IFoo
{
    int Bar1 { get; set; }
    int Bar2 { get; set; }
}

If IFoo was class, I could write:

fixture.CreateAnonymous<IFoo>();

and the result will have numbers set for Bar1 and Bar2.

But how to do this with interface? I tried to use AutoMoqCustomization but this seems to be for properties with interface type and not interfaces itself.

I am looking for automated way like CreateAnonymous is for classes. Currenlty I am creating interface mock and setuping it’s properties explicitly which is work I would like to save. I must missing something obvious.

  • 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-02T03:10:04+00:00Added an answer on June 2, 2026 at 3:10 am

    If you want to map an interface to a specific concrete class, you can certainly do that:

    fixture.Register<IFoo>(() => fixture.CreateAnonymous<ConcreteFoo>());
    

    (Or fixture.Register<IFoo>( fixture.CreateAnonymous<ConcreteFoo>) for short)

    However, AutoMoq (as well as AutoRhinoMocks and AutoFakeItEasy) is also an option. With that, an attempt to create an instance of IFoo will return a Moq-created proxy which implements IFoo.

    However, with Moq you aren’t going to see the Bar1 and Bar2 populated. That’s not only because AutoFixture doesn’t invoke the setters, but because Moq doesn’t (by default) implement the getters.

    In order to make that work for Moq, one needs to invoke SetupAllProperties() on the Mock<T> itself. While possible, that’s a little bit difficult to do in the current AutoMoq graph. There’s already a work item for this, but if you read through the discussion you’ll see that the issue is more complex than it would seem.

    In any case, interfaces with properties is a bad idea for a number of other reasons too, so the best solution is to redesign the interface so that it doesn’t have properties.

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

Sidebar

Related Questions

Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have the string: hello world; some random text; foo; How could
Let's imagine I have a Java class of the type: public class MyClass {
Let's say that I have a set of relations that looks like this: relations
Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):
Let's say I have a list of objects TheListOfObjects. If I write this: TheListOfObjects
Let's suppose we have: Class Foo{ int x,y; int setFoo(); } int Foo::setFoo(){ return
Let's say i have two tables in db: Car and Part. Car owns arbitrialy
Let’s say I have a number like 0x448 . In binary this is 0100

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.