I'm writing unit tests for a class that uses XConnectClient
, which means I need to mock an XConnectClient
.
I've tried the following using Moq and RandomTestValues packages:
Mock<XConnectClient> client = new Mock<XConnectClient>(
new Mock<XConnectClientConfiguration>(
new Mock<XdbModel>(
"XdbName",
new XdbModelVersion(RandomValue.Int(), RandomValue.Int()),
new XdbNamedType[0],
new XdbFacetDefinition[0],
new XdbModel[0]).Object,
new Mock<Uri>(RandomValue.Uri().ToString()).Object).Object);
This compiles, but generates a NullReferenceException
in XConnectClientConfiguration.ctor
at runtime. I don't know what is NULL here, and there's really too much going on in the mocking so it's not easily readable any more.
Is there a way of mocking XConnectClient
(preferrably without having to write a wrapper around it)?