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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:17:00+00:00 2026-05-12T09:17:00+00:00

I am using an interface (IDataSet) in front of System.Data.DataSet for testing purposes. I

  • 0

I am using an interface (IDataSet) in front of System.Data.DataSet for testing purposes. I want to be able to mock the Copy() method. Basically I want a copy/clone of the same mocked object.

Here’s some pseudo code of what I would like to do.

Mock<IDataSet> dataMock = new Mock<IDataSet>();
Mock<IDataSet> copyMock = ???    // How do I clone the mock?

dataMock.Setup(c => c.Copy()).Returns(copyMock.Object);

Is this possible?

  • 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-12T09:17:00+00:00Added an answer on May 12, 2026 at 9:17 am

    Basically, a Mock is not the real thing, so it does not have real behavior. It’s not supposed to have real behavior – it’s supposed to do whatever you tell it while keeping track of what happened. Nothing more and nothing less.

    This means that you have to tell it how its Copy method works. If you do the following, that’s the implmementation the Copy method will have:

    Mock<IDataSet> dataMock = new Mock<IDataSet>();
    Mock<IDataSet> copyMock = new Mock<IDataSet>();
    
    dataMock.Setup(c => c.Copy()).Returns(copyMock.Object);
    

    However, you can also do this:

    Mock<IDataSet> dataMock = new Mock<IDataSet>();
    Mock<IDataSet> copyMock = dataMock;
    
    dataMock.Setup(c => c.Copy()).Returns(copyMock.Object);
    

    and that, then, becomes the implementation of the Copy method. Remember: an interface is not a contract that states what the method should do; it only defines the signature of methods.

    You were probably hoping to copy data from one IDataSet to another, but remember that a Mock is pure behavior; it has no data.

    A couple of alternatives you can think about are the following:

    • Replace IDataSet with an abstract DataSetBase class, and implement the Copy method like you want it to behave (that is, not as an abstract or virtual method).
    • Instead of creating a Mock of IDataSet, use a Fake. A Fake is a a test-specifict implementation of an interface that has behavior close to the real thing. There are no frameworks/libraries for creating Fakes, so you would need to code such a Fake by hand.
    • Consider whether the Copy method should really be part of the interface. It sounds to me like it’s an implementation detail that doesn’t belong on the interface in the first place.

    You can read about Stubs, Mocks, Fakes and other unit testing design patterns in the excellent book xUnit Test Patterns.

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

Sidebar

Related Questions

I created a label using Interface Builder, and now I want to set the
I want to implement my project using interface oriented programming. Since Python itself does
Using interface builder, I want an a button that when clicked shows you a
I'm using interface builder's tag feature to access some UILabels I'm instantiating in a
I made a UIView using Interface Builder with a top bar that has Cancel
I am using Interface Builder to play around with some ideas. I never noticed
can we implement polymorphism using interface in c#? any example .
I wanted to generate one fix view using interface builder, but the size of
I'm trying to avoid using Interface Builder as much as possible. At the moment
How does one bind an iPhone SDK control (say a UISlider) using Interface Builder?

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.