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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:26:13+00:00 2026-05-17T17:26:13+00:00

I am trying to use the fluent test helpers to test an AbstractRestfulFluentController public

  • 0

I am trying to use the fluent test helpers to test an AbstractRestfulFluentController

public class CustomerController : AbstractRestfulFluentController
{
    private readonly IService<Customer> _customerService;
    private readonly IService<CustomerAddress> _addressService;

    public CustomerController(IService<Customer> customerService, IService<CustomerAddress> addressService)
    {
        //Assume we use these in other actions
        _customerService = customerService;
        _addressService = addressService;
    }

    public ActionResult Index()
    {
        return View();
    }
}

As you can see I am injecting some services into the controller and resolving them using IOC. My problem is that all the examples I have found using the fluent test methods in mvccontrib don’t work without a paramaterless controller.

public void SuccessfulIndex()
    {
        GivenController.As<CustomerController>()
            .ShouldRenderItself(RestfulAction.Index)
            .WhenCalling(x => x.Index());
    }

I’m not sure what I need to do in order to be able to use IOC with the fluent test techniques in mvccontrib. I have found a few comments that it is possible but haven’t found anything. What can I do in order to actually use IOC and fluent tests?

  • 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-17T17:26:14+00:00Added an answer on May 17, 2026 at 5:26 pm

    You could write a method which allows you to provide the instance of the controller:

    public static class GivenController
    {
        public static ActionExpectations<T> As<T>(T controller) where T: Controller, new()
        {
            return new ActionExpectations<T> { MockController = controller };
        }
    }
    

    And then in your unit test:

    var controller = CreateMockedCustomerController();
    GivenController
        .As<CustomerController>(controller)
        .ShouldRenderItself(RestfulAction.Index)
        .WhenCalling(x => x.Index());
    

    The requirement is that the controller should be a mock object which in my opinion is not a very clean approach (testing a mocked object). You could create it like this:

    var controller =  MockRepository
        .GeneratePartialMock<CustomerController>(new object[] { dep1, dep2 });
    

    Notice how dependencies are passed to the constructor.

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

Sidebar

Related Questions

I've been trying to use #harp architecture and Fluent-NHibernate. I am trying to sublass
I am trying to use the automapping feature of Fluent with nHinbernate to map
Trying to use an excpetion class which could provide location reference for XML parsing,
I'm trying to use the fluent mocking style of Rhino.Mocks and have the following
I am newbie to NHibernate and trying to use Fluent for mapping. My entity
I am trying to use the repository pattern, ninject for DI with fluent nhibernate.
I'm trying to figure out how to use CompositeId to map another class. Here's
I am trying to use fluent nhibernate in a MVC project... i am very
I am trying to do a MVC project where i want to use fluent
I am trying to use Fluent NHibernate. I have setup two table Products and

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.