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

  • Home
  • SEARCH
  • 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 3443452
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:47:34+00:00 2026-05-18T08:47:34+00:00

I have a constructor and a property in the class: private IMyCollectionObjects _myCollectionObjects; public

  • 0

I have a constructor and a property in the class:

private IMyCollectionObjects _myCollectionObjects;

public MyClassConstructor(string message)
{
     _myCollectionObjects = MyCollection.GetCollectionObejects(message);
}
  1. With as much detail can you please help me understand how to unit test this constructor
    and GetCollectionObjects method?

  2. How do I completely decouple the
    classes? You can give the answer
    using any IoC, I want to
    understand the concept.

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-18T08:47:35+00:00Added an answer on May 18, 2026 at 8:47 am

    For of all, unit testing is all about unitary testing, that is, one thing at a time.

    With as much detail can you please help me understand how to unit test this constructor and GetCollectionObjects method?

    First things first, have you unit tested your MyCollection class?

    If not, you should begin with it, as your MyClassConstructor class depends on it, that is the basis of dependency injection. Otherwise, how can you manage to know if the results you’re getting are right or wrong? You won’t be able to test and be sure that it works flawlessly.

    How do I completely decouple the classes? You can give the answer using any IoC, I want to understand the concept.

    I my humble point of view, you must have a clear reason to make an object dependant of another using dependency injection. Once you make an object depend on another, it makes no sense, in my opinion, to decouple them. One way of decoupling might be to use Unity Application Block of Enterprise Library.

    Unit test this constructor

    You generally only need to check for three things while testing such a constructor.

    1. That the constructor doesn’t return a null value;
    2. That the instance it returns is of the expected type;
    3. That the object you expect to be instantiated through its dependency is actually instiated.
        [TestCase("message")]
        public void DependentConstructorTest(string message) {
            MyClassConstructor myclass = new MyClassConstructor(message);
    
            Assert.IsNotNull(myclass);
            Assert.IsInstanceOf(typeof(MyClassConstructor), myclass);
            Assert.IsNotNull(myclass.MyCollection); // Where MyCollection represents the property that 
                                                    // exposes the instance created of the object from
                                                    // which your MyClassConstructor class depends on.
        }
    

    Note: This test is written using NUnit attributes and assertion methods. Use whatever else you like.

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

Sidebar

Related Questions

I have a class defined as: public ref class MyParameters { private: property Decimal^
I have a class defined as: public ref class MyParameters { private: property Decimal^
I have a constructor signature like this public NavigationLink(Func<String> getName, Func<UrlHelper, String> getURL, Func<bool>
I have a constructor question for C#. I have this class: public partial class
I have the following classes: type TSong = class(TObject) private FArtist: String; FTitle: String;
I have the following classes: public abstract class BaseClass { private readonly double cachedValue;
I have a constructor like as follows: public Agent(){ this.name = John; this.id =
I have a constructor (for an auto generated class) that has 255 paremeters. Using
I have a constructor which has a non-interface dependency: public MainWindowViewModel(IWorkItemProvider workItemProvider, WeekNavigatorViewModel weekNavigator)
I have a very odd problem. A class property is mysteriously reset between method

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.