0

I am currently trying to unittest a this

bool hasImageUrl =  HttpContext.Current.Request.AcceptTypes?.Any(x => x.ToLower().StartsWith("image/")) ?? false;

Which require me to set the accepttype, since when I mock it by

HttpRequest httpRequest = new HttpRequest(string.Empty, "http://google.com", string.Empty);

I seem to get an nullreferenceException, instead of outputting it as false.

I tried something as while mocking it to do something like this

Httpcontext.current.Request.AcceptTypes.ReturnNullForAnyArgs()

But this seem not to work. Any proper way of doing this?

Dalton Cézane
  • 3,672
  • 2
  • 35
  • 60
anita
  • 193
  • 10

0 Answers0