mardi 26 avril 2016

How to mock up System.Uri?

I have the method in a class.

 public virtual async Task<HttpResponseMessage> GetHttpResponseMessageFromDeviceAndDataService(HttpClient client, Uri uri)
 {
    var response = await client.GetAsync(uri).ConfigureAwait(false);
    return response;
 }

So in the unit test, I tried mock up them.

var fakeHttpClient = new Mock<HttpClient>();
var fakeUri = new Mock<Uri>();
var client = fakeHttpClient.Object;
var uri = fakeUri.Object;

But I get the exception.

Object (Moq.Mock) = '((Moq.Mock)fakeUri).Object' threw an exception of type 'Castle.DynamicProxy.InvalidProxyConstructorArgumentsException'

So how to mock up it?

Aucun commentaire:

Enregistrer un commentaire