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

The Archive Base Latest Questions

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

I have a private method which is being called in a method I am

  • 0

I have a private method which is being called in a method I am testing.I want to verify the correct parameters are being passed to this private method. I have written the following setup in Moq which will test what I want, however it doesn’t really allow me to follow the Arrange, Act, Assert pattern.

Is there any way I can perform a similar test where by the assert can appear with all of my other asserts? At the moment the code below lives within the Arrange.

     myClass.Setup(
                x =>
                x.myMethod(
                    It.IsAny<Person>>(),
                    It.IsAny<string>(),
                    It.IsAny<Person>(),
                    It.IsAny<ICollection<string>>(),
                    It.IsAny<ICollection<string>>(),
                    It.IsAny<bool>())).Callback
                <Person, string, Person, Person, ICollection<string>, bool>(
                    (a, b, c, d, e, f) =>
                        { 
                            Assert.AreEqual("NameA", a.Name); 
                            Assert.AreEqual("StringB", b);
                            Assert.AreEqual("NameC", c.Name);
                            Assert.AreEqual(2, d);

                            var dList = d.ToList().OrderBy(x => x.Name);
                            Assert.AreEqual("PersonA", dList[0].Name)
                            Assert.AreEqual("PersonB", dList[1].Name);
                        });

I should say, I am aware that you can perfom a verify to check whether a method has been called with certain inputs, however I am not aware of any way of matching the ICollection params.

  • 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-02T01:10:29+00:00Added an answer on June 2, 2026 at 1:10 am

    If you are using those assertions to check the parameters, you can do it in your setup. If your mock uses strict behavior, it will fail if a parameter doesn’t match the predicate.

     // declare your mock with strict behavior
    
     myClass.Setup(
         x =>
         x.myMethod(
             It.Is<Person>(person => person.Name == "NameA"),
             "Stringb",
             It.Is<Person>(person => person.Name == "NameC"),,
             It.Is<ICollection<string>>(coll =>{ 
                    //your other validations
                }),
             It.IsAny<ICollection<string>>(),
             It.IsAny<bool>()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this recursive method which deletes empty folders: private void DeleteEmpty(DirectoryInfo directory) {
I have a method which returns some xml in a memory stream private MemoryStream
I have class which have one public method Start , one private method and
In my messages_controller I have the following private method: def find_message_or_404(slug) message = user.messages.find_by_slug(slug)
I have a method private static DataTable ParseTable(HtmlNode table) and sometimes this method has
I have the following method: private JobCard PopulateObject(JobCard jc, DataRow dataRow) { PropertyInfo[] proplist
I have the following JUnit test. The method that I'm testing is quite simple,
I have a JQuery control which has some private methods. I would like to
I have a private method def __pickSide(self): in a parent class that I would
I have a problem getting a private method using reflection. Even with BindingFlags.NonPublic 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.