I am writing xunit tests for IotEdge custom Module, where I need to Mock ModuleClient.CreateFromEnvironmentAsync()
which opens a connection to Edge runtime.
Iot Edge Module code looks like this :
var amqpSetting = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only);
ITransportSettings[] settings = { amqpSetting };
// Open a connection to the Edge runtime
this.ioTHubModuleClient = await ModuleClient.CreateFromEnvironmentAsync(settings);
await this.ioTHubModuleClient.OpenAsync();
Unit test code looks like this:
var amqpSetting = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only);
ITransportSettings[] settings = { amqpSetting };
var moduleClientMoq = new Mock<ModuleClient>(ModuleClient.CreateFromEnvironmentAsync(settings)); // getting an exception-"System.NotSupportedException: 'Type to mock must be an interface or an abstract or non-sealed class."
I am getting "System.NotSupported" exception.Please suggest how to mock Module client.