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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:34:37+00:00 2026-06-04T16:34:37+00:00

[TestClass] public class FooTests { [TestMethod] public void TestFoo() { var fooMock = MockRepository.GenerateMock<IFoo>();

  • 0
[TestClass]
public class FooTests {
        [TestMethod]
        public void TestFoo() {
            var fooMock = MockRepository.GenerateMock<IFoo>();
            // MUT
            FooUser.Run(fooMock);

            var stream = fooMock.Content;
            stream.Position = 0;

            var first = stream.ReadByte();
            Assert.AreEqual(0x77, (byte) first);
            var second = stream.ReadByte();
            Assert.AreEqual(0x78, (byte) second);
        }
    }

    public class Foo :IFoo {
        public Stream Content { get; set; }
    }

    public class FooUser {
        public static void Run(IFoo foo) {
            foo.Content = new MemoryStream(new byte[] {0x77, 0x78});
        }
    }

    public interface IFoo {
        Stream Content { get; set; }
    }

AssertWasCalled does not seem to be a good fit for validating the stream.

fooMock.Content.Stub(aStream => stream = aStream);

threw exception:

System.ArgumentNullException: You cannot mock a null instance
Parameter name: mock

Note: Seems like Moles would work better for this problem.

  • 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-04T16:34:39+00:00Added an answer on June 4, 2026 at 4:34 pm

    Replace:

    var fooMock = MockRepository.GenerateMock<IFoo>();
    

    with:

    var fooMock = MockRepository.GenerateStub<IFoo>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this test fixture: [TestClass] public class MSTestThreads { [TestMethod] public void Test1() {
consider the following test class: [TestClass] public class ExampleTests { [TestMethod] public void FileDoesNotExists()
I have the folowing tests: [TestClass] public class GeneralTest { [TestMethod] public void VerifyAppDomainHasConfigurationSettings()
Example: public class TestClass { public static void main(String[] args) { TestClass t =
When I run the following test, I get an ArgumentOutOfRangeException: [TestClass] public class ReproduceException
So if i have something like this: public class TestClass { public static void
I've some class with these methods: public class TestClass { public void method1() {
@Entity public class TestClass implements Serializable{ private Integer id; private Set<String> mySet; @Id @GeneratedValue
My jpa looks like below public class TESTClass implements Serializable { ... private String
Given I have a class with two constructors: public class TestClass { ObjectOne o1;

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.