Reputation: 35037
The signature for DeviceClient
class in Microsoft.Azure.Devices.Client
is
public sealed class DeviceClient : IDisposable
.
This doesn't really suggest ideas for how to write testable code for the class that uses the client.
The client depends on a transport layer which sounds promising ("let's provide the transport and then mock it in tests; something like HttpClient
and HttpMessageHandler
") but the factory methods DeviceClient.Create
take the transport as an enum
so this angle of attack seem to be closed.
Is an adapter pattern (i.e. re-implement the interface) the way to go?
Upvotes: 2
Views: 435
Reputation: 41
With a sealed class and no virtual methods, an interface and adapter pattern may be the best (though high maintenance) solution. You need interception and so have you looked at Microsoft Fake framework and use a shim to isolate that assembly when testing.
Upvotes: 3