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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:57:37+00:00 2026-05-28T15:57:37+00:00

I have the following (here simplified) code which I want to test with FakeItEasy

  • 0

I have the following (here simplified) code which I want to test with FakeItEasy.

public class ActionExecutor : IActionExecutor
{
    public void TransactionalExecutionOf(Action action)
    {
        try
        {
           // ...  
           action();
           // ... 
        }
        catch
        {
           // ...
           Rollback();
        }
    }

    public void Commit()
    {    }

    public void Rollback()
    {    }
}

public class Service : IService
{
    private readonly IRepository _repository;

    private readonly IActionExecutor _actionExecutor;

    // ctor for CI

    public void ServiceMethod(string name)
    {
        _actionExecutor.TransactionalExecutionOf(() =>
        {
            var item = _repository.FindByName(ItemSpecs.FindByNameSpec(name));
            if (item == null) throw new ServiceException("Item not found");

            item.DoSomething();
            _actionExecutor.Commit(); 
        }
    }
}

I want to test that the ServiceException is thrown so i setup my test like that

var repo = A.Fake<IRepository>();
A.CallTo(() => repo.FindByName(A<ISpec<Item>>.Ignored))
 .Returns(null);

var executor = A.Fake<IActionExecutor>();
executor.Configure()
        .CallsTo(x => x.Rollback()).DoesNothing();
executor.Configure()
        .CallsTo(x => x.Commit()).DoesNothing();
executor.Configure()
        .CallsTo(x => x.TransactionalExecutionOf(A<Action>.Ignored))
        .CallsBaseMethod();

With the following code

var service = new Service(executor, repo);
service.ServiceMethod("notExists")
       .Throws(new ServiceException());

I get the following message

The current proxy generator can not intercept the specified method
for the following reason:
– Sealed methods can not be intercepted.

If I call the method directly on the service like

var service = new Service(executor, repo);
service.ServiceMethod("NotExists");

I get this message

This is a DynamicProxy2 error: The interceptor attempted to ‘Proceed’
for method ‘Void TransactionalExecutionOf(System.Action)’ which has no
target. When calling method without target there is no implementation
to ‘proceed’ to and it is the responsibility of the interceptor to
mimic the implementation (set return value, out arguments etc)

Now I am a bit confused and don’t know what to do next.

  • 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-28T15:57:38+00:00Added an answer on May 28, 2026 at 3:57 pm

    Problems comes from the way you create fake and what you later expect it to do:

    var executor = A.Fake<IActionExecutor>();
    // ...
    executor.Configure()
        .CallsTo(x => x.TransactionalExecutionOf(A<Action>.Ignored))
        .CallsBaseMethod();
    

    What base method? FakeItEasy has no idea what the base class is, and hence the DynamicProxy2 exception in your second case. You can create partial mock this way:

    var executor = A.Fake<ActionExecutor>();
    

    Note that we’re basing on actual implementation, not interface anymore

    This however introduces a new set of problems, as methods on ActionExecutor are not virtual and therefore interceptor cannot hook up to well – intercept them. To make your current setup work, you’ll have to change your ActionExecutor and make (all) the methods virtual.

    However, you may (or even should) want to avoid modifications of existing code (which sometimes might not even be an option). You could then set up your IActionExecutor fake like this:

    var executor = A.Fake<IActionExecutor>();
    A.CallTo(() => executor.TransactionalExecutionOf(A<Action>.Ignored))
        .Invokes(f => new ActionExecutor()
            .TransactionalExecutionOf((Action)f.Arguments.First())
        );
    

    This will allow you to work on faked object, with the exception of call to TransactionalExecutionOf which will be redirected to actual implementation.

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

Sidebar

Related Questions

I have the following code(simplified). public class OrderProcessor { public virtual string PlaceOrder(string test)
I have following code: public static void ProcessStep(Action action) { //do something here if
Say I have the following class: class Foo { // ctor etc here public
Consider the following simplified version of my code. I have a template class A
I have the below (simplified) code, which uses the following source: <html> <p>line 1</p>
I have the following (simplified) code periodically run by a Thread in the class
I have the following (simplified) code from a generic factory class: - (id) invokeSetup:
I have the following function in my code. Here's a simplified version: $.ajax({ url:
I have the following code here that won't run on ARC since it combines
I have this following jquery text fly-in animation.Here is my code before I explain

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.