NSubstitute
NSubstitute copied to clipboard
NSubstitute.Exceptions.CouldNotSetReturnDueToTypeMismatchException
I am using NSubstitute for unit testing. I am getting below exception for ReturnsForAnyArgs Exception thrown: 'NSubstitute.Exceptions.CouldNotSetReturnDueToTypeMismatchException' in NSubstitute.dll
this.exchangeService = Substitute.For<IExchangeService>();
HttpClient httpClient = new HttpClient();
this.exchangeService.Client.Returns(httpClient);
HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, this.applicationContext.SubstrateRestApiUrl);
this.exchangeService.Client.SendAsync(request).ReturnsForAnyArgs(Task.FromResult(httpResponseMessage));
Hi @gsmittal ,
Sorry for the late response; this notification got lost in my inbox. 😓
Have you added the NSubstitute.Analyzers package to your test project? This is probably the easiest way to find the cause of these problems.
In this case, exchangeService.Client is set to a real HttpClient, so maybe exchangeService.Client.SendAsync is failing due to this?
Closing this due to inactivity. Please let us know if this still an issue and please provide the requested info - thanks!