public async Task CloseForwarded() { var connectionHandler = Mock.Of <IConnectionRegistry>(); var twinHandler = Mock.Of <ITwinHandler>(); var m2mHandler = Mock.Of <IModuleToModuleMessageHandler>(); var c2dHandler = Mock.Of <ICloud2DeviceMessageHandler>(); var directMethodHandler = Mock.Of <IDirectMethodHandler>(); var identity = new DeviceIdentity("hub", "device_id"); Mock.Get(connectionHandler) .Setup(h => h.CloseConnectionAsync(It.Is <IIdentity>(i => i == identity))) .Returns(Task.CompletedTask); var sut = new DeviceProxy(identity, true, connectionHandler, twinHandler, m2mHandler, c2dHandler, directMethodHandler); await sut.CloseAsync(new Exception()); Mock.Get(connectionHandler).VerifyAll(); }