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

The Archive Base Latest Questions

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

I am currently using Unity with MOQ to do my unit testing for WCF.

  • 0

I am currently using Unity with MOQ to do my unit testing for WCF. In the application’s code, I have the following:

private void MyMethod()
{
.....
.....
    _proxy = new UnityContainer().LoadConfiguration().Resolve<IMyInterface>();
.....
}

In the application’s app.config, I have the following:

<container>
  <register type="IMyInterface" mapTo="MyActualObject" />
</container> 

In the unit test’s app.config, I replace that with my mock object implementation of the proxy.

<container>
  <register type="IMyInterface" mapTo="MyMockObject" />
</container> 

That is all working fine. But what I would like to do further is for certain tests, I would like to replace MyMockObject with a different mock object implementation.

Is it possible to change the registered type at runtime? I have tried modifying the application config during runtime but it fails to detect the change.

 Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
 var section = (UnityConfigurationSection)appConfig.GetSection("unity");
 section.Containers[0].Registrations[0].MapToName = "AnotherMockObject";
 appConfig.Save();  

Thanks!!

  • 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:26:52+00:00Added an answer on June 2, 2026 at 4:26 pm

    Yes its possible.

    You can configure Unity as many times as you want. If there’s a conflict the most recent definition wins.

    In your case if you want to make a runtime change, use the fluent API instead of the config file. Try something like this:

    IUnityContainer container = new UnityContainer();
    container.LoadConfiguration();
    container.RegisterType<IMyInterface, AnotherMockObject>();
    
    // use AnotherMockObject
    _proxy = Resolve<IMyInterface>();
    

    The documentation for Registering Types and Type Mappings

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

Sidebar

Related Questions

I'm using the Moq framework to do my unit testing. I'm following some really
I'm currently building a unit test suite for my application, using QTestLib . It's
I'm currently using the validation code listed here in an application. I'd like to
I'm currently using Unity with Unity.Mvc3 in my MVC3 application which uses Windows Authentication.
I'm currently using Zend Framework in conjunction with PHPUnit to conduct unit testing on
We're currently using MBUnit for both unit testing and UI testing. For UI testing
I'm mocking the WebOperationContext class over wrapper for unit testing (using Moq). But I
We are currently using unit tests to test our project. We have the majority
Using pyUnit to do what is currently a very small and simple unit test
Currently using Xcode 4.2 and I have two view controllers (1 and 2). I

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.