sharppcap
sharppcap copied to clipboard
How can I (unit)test the CaptureDevices?
I wish to knwo if there is any way to mock the CaptureDevices (CaptureDeviceList).
I need that to test several code, that relays on the detection of the devices, but, i can't make a mock or substitute.
Can you provide some info about it?
thanks in advance.
Thanks @NeoMorfeo for this post! I think we need a way to test our code and due to it doesn't use interfaces it is so hard to have a nice way to test
@kayoub5 and I have discussed dropping the singleton use in CaptureDeviceList etc but changes here on master have yet to be made. Suggestions for improvements are welcome. 6.x is coming soon so now is a good time to propose API altering changes.
The way I see it, we already have the PcapInterface.GetAllPcapInterfaces(), and a single class for PCAP device new LibPcapLiveDevice(PcapInterface pcapIf), so the CaptureDeviceList could be removed as far as I see.
For the original request, You can:
- Mock a single device by mocking the
ICaptureDevice - Mock a list of devices by mocking the base class of
CaptureDeviceList:ReadOnlyCollection<>(the application should use a List of CaptureDevice instead of directly referencingCaptureDeviceList.Instance) - Create your own C library
wpcap.dllorlibpcap.so