0

I create a test case for null argument check but got this error : Expected a <System.ArgumentNullException> to be thrown, but found a <System.NullReferenceException>: System.NullReferenceException with message "Object reference not set to an instance of an object."

[Fact]
public void GivenNull_WhenMapIsCalled_ThenArgumentNullExceptionIsThrown()
{
    //Given

    Request request = null;

    //When
    Action action = () => new ConsumerServiceWrapper().IndividualsSearch(request);

    //Then
    action.ShouldThrow<ArgumentNullException>();

}

Individual Search

public List<Response> IndividualsSearch(Request request)
{
   var response = new List<Response>();
   //some code
   return response;
}
UC57
  • 359
  • 4
  • 16
  • Please, share your implemetation of IndividualsSearch() method – PWND Nov 11 '20 at 12:54
  • Please, check now. – UC57 Nov 11 '20 at 13:28
  • 1
    @UC57 where's the code that throws? What's behind `//some code`? What you posted doesn't throw anything, it returns an empty list. At the very least post the full exception, not just the message. The full extension text shows where the exception was thrown, any inner exceptions and the stack trace with the calls that caused the exception. – Panagiotis Kanavos Nov 11 '20 at 13:30
  • 1
    "I create a test case for null argument check but..." given that you **don't have** a null argument check, it's not surprising that it fails. Good test. – nvoigt Nov 11 '20 at 13:32
  • @PanagiotisKanavos behind some code is calling of soap service which add the response. – UC57 Nov 11 '20 at 13:45
  • @nvoigt so please tell me how to do it? – UC57 Nov 11 '20 at 13:46
  • uh... `if(request == null) throw new ArgumentNullException(nameof(request));` ? – nvoigt Nov 11 '20 at 13:48

0 Answers0