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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:21:52+00:00 2026-05-27T01:21:52+00:00

I am working on adding basic automatic UI tests to the block of unit

  • 0

I am working on adding basic automatic UI tests to the block of unit tests we run with each nightly build. We used MSTest coded UI and created a script.

The code-behind is dependent upon IClientManager which both the real manager and mock implement.
My problem is that I don’t know how to switch automatically between the real and mock implementations inside the button click handler, when running a test.

My two other constraints are that I can’t have a dependency on the mock assembly in the code-behind and that I can’t use a DI framework, since the client is “security conscious” and getting a framework approved might take months.

Is there any way of doing this manually, and hopefully, not a bigger problem than the problem I am looking to solve?

Thank you!

  • 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-27T01:21:53+00:00Added an answer on May 27, 2026 at 1:21 am

    You could build your own simple object container if you can’t use a third party one (which is silly but I understand, I’ve been there before)

    here is something that I whipped up that could get you started… haven’t tested it and it is really rough, but hopefully you get the idea

    public static class ObjectFactory
    {
        static IDictionary<Type, object> _factory = new Dictionary<Type, object>();
    
        public static void Register<T>(Func<T> builder)
        {
            if (_factory.ContainsKey(typeof(T)))
                _factory[typeof(T)] = builder;
            else
                _factory.Add(typeof(T), builder);
        }
    
        public static T GetInstance<T>()
        {
            if (_factory.ContainsKey(typeof(T)))
                throw new ArgumentException(string.Format("Type <{0}> not registered in ObjectFactory", typeof(T).Name));
    
            return ((Func<T>)_factory[typeof(T)])();
        }
    }
    
    public interface IClientManager { }
    public class RealClientManager : IClientManager { }
    public class MockClientManager : IClientManager { }
    
    public class MyView
    {
        public MyView()
        {
            // probably better to do this registry in some sort of application initialization
            ObjectFactory.Register<IClientManager>(() => new RealClientManager());
        }
    
        public void SomeMethodThatNeedsClientManager()
        {
            var clientManager = ObjectFactory.GetInstance<IClientManager>();
        }
    }
    
    public class MyTester
    {
        [TestMethod()]
        public void SomeTest()
        {
            var view = new MyView();
    
            // swap the client manager in the test
            ObjectFactory.Register<IClientManager>(() => new MockClientManager());
    
            // Asserts
        }
    }
    

    you can see that if you’ve used StructureMap or some other DI container before they do a lot of the same thing with a lot of added niceties such as traversing your object graph and registering objects automatically based on conventions, managing object lifecycles, scoping of containers, etc… a lot of this stuff you could implement yourself too… but you should just really used a tried and true solution such as StructureMap

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

Sidebar

Related Questions

I'm working on a basic event form created from a model, but I keep
I have coded a basic game in JavaScript and am working on a high
I'm working on a basic program and I've tried adding a working webBrowser component
I working on adding file uploading to my web application. I'm using an iframe
I'm working on adding globalization to my product cataloge and I have made it
I am working on adding in a settings bundle for my application as a
I am working on adding In-App purchases to my app. I am able to
I am working on adding a custom accessory view, (a button) to a UITableViewCell,
Context: I'm working on master adding a simple feature. After a few minutes I
The code I'm currently working on requires adding an NSNumber object to an array.

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.