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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:12:05+00:00 2026-06-02T16:12:05+00:00

Scratching my head how to do this. Suppose I had a concrete class Foo

  • 0

Scratching my head how to do this.

Suppose I had a concrete class Foo with 2 virtual methods, Execute() and GetFile(). Execute() will call GetFile. I want to make sure that when it does, GetFile() will throw a couple of different exceptions that Foo is supposed to handle gracefully in a testable manner.

For my unit tests, I am envisioning instantiating a DynamicProxy<Foo> from castle project where I intercept the GetFile() to throw the exception, and then invoke the DynamicProxy object’s Execute() method, and test the results, but I can’t see how to do this.

Is this possible/ practical? If so, what would the creation of the dynamic proxy object look like?

  • 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-02T16:12:07+00:00Added an answer on June 2, 2026 at 4:12 pm

    You don’t need to handcode your own proxy because most the mocking frameworks support your scenario.

    Here is an example using Moq (Moq will create a dynamic proxy internally for you):

    public class SomeException : Exception { }
    
    public class Foo
    {
        public virtual int Execute()
        {
            try
            {
                GetFiles();
            }
            catch (SomeException)
            {
                return 1;
            }
            return 0;
        }
    
        public virtual void GetFiles()
        {
            //...
        }
    }
    
    [Test]
    public void FooTest()
    {
        var fooUnderTest = new Mock<Foo>();
        fooUnderTest.CallBase = true;
        fooUnderTest.Setup(f => f.GetFiles()).Throws(new SomeException());
        var result = fooUnderTest.Object.Execute();
        Assert.AreEqual(1, result);
    }
    

    You just need to take care to set Callbase = true which will:

    Invoke base class implementation if no expectation overrides the
    member (a.k.a. “Partial Mocks” in Rhino Mocks): default is false.

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

Sidebar

Related Questions

My newness to xcode has had me scratching my head over this problem for
I am scratching my head about this. My scenario are that I need to
I've been scratching my head over this for an hour... I have a list
I've been scratching my head about this for the last 4 hours, trying out
Ok, been scratching my head on this one for a bit now... seems related
It's late on a Friday and I'm scratching my head on this one. I'm
This one has me scratching my head, so I'm hoping a second pair of
I have been scratching my head for a while on this one. I dont
I have been scratching my head for hours trying to figure out why this
I ran into this concurrency problem which I've been scratching my head for several

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.