title: NSubstitute.Exceptions.ReceivedCallsException: Expected to receive a call matching error while unit testing
body: <p>I am getting a below error while unit testing the piece of code</p>
  
  <blockquote>
    <p>NSubstitute.Exceptions.ReceivedCallsException: Expected to receive a call matching error while unit testing
    NSubstitute.Exceptions.ReceivedCallsException
      HResult=0x80131500
      Message=Expected to receive a call matching:
        enrollWithHelper("", "")
    Actually received no matching calls.</p>
    
    <p>Source=NSubstitute
      StackTrace:
       at NSubstitute.Core.ReceivedCallsExceptionThrower.Throw(ICallSpecification callSpecification, IEnumerable<code>1 matchingCalls, IEnumerable</code>1 nonMatchingCalls, Quantity requiredQuantity)
       at NSubstitute.Routing.Handlers.CheckReceivedCallsHandler.Handle(ICall call)
       at NSubstitute.Routing.Route.Handle(ICall call)
       at NSubstitute.Proxies.CastleDynamicProxy.CastleForwardingInterceptor.Intercept(IInvocation invocation)
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Castle.DynamicProxy.AbstractInvocation.Proceed()
       at Castle.Proxies.ObjectProxy_1.enrollWithHelper(String name, String type)
       at MyProject.MyTest.processing_test_pass() in C:\MyProject\MyTest.cs:line 75</p>
  </blockquote>
  
  <p><strong>Framework</strong>: .NET Core</p>
  
  <p><strong>Unit Testing</strong>: NSubstitute</p>
  
  <p>Here is my class under test</p>
  
  <pre><code> public class MyService: IMysService
   {
     private readonly IRepository _repository;
     Private readonly IIoTHelper _iotHelper;  
     Private readonly HttpClient _httpClient;
     private Configuration _configuration; 
  
     public MyService(IRepository repository, IIoTHelper iotHelper, HttpClient httpClient )
     {
          _repository = repository;
          _iotHelper =iotHelper;
          _httpClient = httpClient ;
     }
  
     public bool CallService(JObject reqObj, out Status status)
     {
          bool provisioningSuccess = false;
          return PreProcessing(reqObj,out Status status); //private method
     }
  }
  </code></pre>
  
  <p>Here is my private method</p>
  
  <pre><code>    private PreProcessing(JObject JosnObj, out Status status)
      {
          if (_configuration== null)
          {
              _configuration= _repository.GetConfigurations()                 
          }
  
         using (var client = this._httpClient)
         {
              var request = new {_configuration.Number,_configuration.Type};
              var response = client.PostAsJsonAsync("api/preprocess", request).Result;
  
              if (response.IsSuccessStatusCode)
              {
                    _iotHelper.enrollWithHelper(_configuration.Number,_configuration.Type);
              }
         }
      }
  </code></pre>
  
  <p>Here is my Configuration class</p>
  
  <pre><code>   public class Configuration 
     {
       public Configuration (string number, string type)
       {
          Number= number;
          Type= type;
       }      
       public string Number { get;}
  
       public string Type { get; }
  
     }
  </code></pre>
  
  <p>Here is my unit test code, where I want to make sure it reaches the <code>private</code> method </p>
  
  <pre><code>    protected override void InitializeTest()
      {
          this._repository = Substitute.For&lt;IRepository&gt;();
          this._iotHelper = Substitute.For&lt;IIotHelper&gt;();
      }
  
      [TestMethod]
      public void processing_test_pass()
      {
            //Arrange
          var messageHandler = new MockHttpMessageHandler("TEST VALUE", HttpStatusCode.OK);
          var httpClient = new HttpClient(messageHandler);
  
  
            JObject reqobj= new JObject(
            new JProperty("user", "username"),
            new JProperty("pass", "password"));
  
          Status status = new Status();
  
          //act
          var t = new MyService(this._repository,this._iotHelper, httpClient );
          bool success = t.CallService(reqobj, out status);
          //assert
          this._iotHelper.Received().enrollWithHelper("","");
  
      }
  </code></pre>
  
  <p>How would I test <code>enrollWithHelper</code> is called?</p>
  
  <p>Also I am stuck due to error!</p>