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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:03:58+00:00 2026-06-18T01:03:58+00:00

I am using NSubstitute for my Unit tests. I need to check that a

  • 0

I am using NSubstitute for my Unit tests. I need to check that a object is send to a void method inside the method I am testing. I only need to check that the object is sent with one of the properties being a certain value.

eg.

///The object in question
public class Person
{
   public string Name { get; set; }
   public string Surname{get;set;}
}

Two simple methods

public void NameStartsWithA(Person person)
{
  //do something to person when name starts with A
}

public void NameStartsWithB(Person person)
{
  //do something to person when name starts with B
}

The method i am writing the test for.

public void MethodBeingTested()
{
  var person = new Person() {Name = "Adrian",Surname="SomeSurname"};

  if(person.Name.StartsWith("A"))
    NameStartsWithA(person);
  else
    NameStartsWithB(person);
}

If the person name starts with an A, I need to check, using NSubstitute that the “NameStartsWithA” was called with a name that starts with an A.

My Unit Test so far looks something like this

_someService.Received().NameStartsWithA(new Person(){Name="Adrian",Surname=Arg.Any<string>()});

But Nsubstitute says the function was never called, but when I do the same test with “RecievedArgumentsAny()” then it passes.

Hope this example helps you in understanding what I am trying to accomplish.

  • 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-18T01:04:00+00:00Added an answer on June 18, 2026 at 1:04 am

    got this to work. Posting the code.

    _someService.Received().NameStartsWith(Arg.Is<Person>(p => p.Name.Startswith== "A"));
    

    hopes this will help someone in the future.

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

Sidebar

Related Questions

I have a method that looks like this: private async void DoStuff(long idToLookUp) {
I'm using this code to update an object (MySQL) that we have received via
I want to verify that a method on my NSubstitute mock is called with
I'm using Machine.Fakes.NSubstitute and want to fake a return value such that if the
UPDATED: Using sed, how can I insert (NOT SUBSTITUTE) a new line on only
I'm trying to create some unit tests for an application I've recently inherited. Currently
I have an issue with NSubstitute compiling using its inference typing. When I set
I'm using Mail::Outlook to send messages, but when the content of the message is
I am using CSS 3.0 and it is complaining that the user-select property doesn't
Is there a way to use mocks or fakes in your unit tests without

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.