I wonder if anyone can help. I created my own IHttpClient, so I can mock HttpClient using moq. Works very well, but there is an internal object called DetaultRequestHeaders that has the Authorization property.
I install this in my constructor or my class, which accepts in the injected IHttpClient, of course, at runtime everything works as expected. But using Unit Tests, I get an error
Object reference not set to instance....
This is because DefaultRequestHeaders is null.
Now, after it is confirmed further, it looks like a type
HttpRequestHeaders
but its a sealed class, so I can't even do it
.Setup(x => x.DefaultRequestHeaders).Returns(return new HttpRequestHeaders())
Does anyone have any experience with this?
This is an interface definition.
HttpRequestHeaders DefaultRequestHeaders { get; }
Thanks in advance
source share