예제 #1
0
        public void ProcessFor_ThenRegisteredCreatedHandleIsCalled()
        {
            // ARRANGE
            var testHandle             = new IntPtr(42);
            var mockedDeviceManagement = new Mock <IDeviceNotifications>();
            var mockedUsbDeviceWatcher = new Mock <IUsbDeviceWatcher>();
            var destroyedHandle        = new DestroyedHandle(testHandle, mockedDeviceManagement.Object);

            // ACT
            destroyedHandle.ProcessFor(mockedUsbDeviceWatcher.Object);

            // ASSERT
            mockedUsbDeviceWatcher.Verify(x => x.RegisteredCreatedHandle, Times.Once);
        }
예제 #2
0
        public void ProcessFor_WhenRegisteredCreatedHandleIsNull_ThenUnRegisterForDeviceNotificationsIsNotCalled()
        {
            // ARRANGE
            var testHandle             = new IntPtr(42);
            var mockedDeviceManagement = new Mock <IDeviceNotifications>();
            var mockedUsbDeviceWatcher = new Mock <IUsbDeviceWatcher>();
            var destroyedHandle        = new DestroyedHandle(testHandle, mockedDeviceManagement.Object);

            mockedUsbDeviceWatcher.Setup(x => x.RegisteredCreatedHandle).Returns((CreatedHandle)null);

            // ACT
            destroyedHandle.ProcessFor(mockedUsbDeviceWatcher.Object);

            // ASSERT
            mockedDeviceManagement.Verify(x => x.Register(testHandle), Times.Never());
        }
예제 #3
0
        public void ProcessFor_ThenUnRegisterForDeviceNotificationsIsCalled()
        {
            // ARRANGE
            var testHandle = new IntPtr(42);
            var deviceNotificationHandle = new IntPtr(111);
            var mockedDeviceManagement   = new Mock <IDeviceNotifications>();
            var mockedUsbDeviceWatcher   = new Mock <IUsbDeviceWatcher>();
            var mockedCreatedHandle      = new Mock <CreatedHandle>(testHandle, mockedDeviceManagement.Object);
            var destroyedHandle          = new DestroyedHandle(testHandle, mockedDeviceManagement.Object);

            mockedUsbDeviceWatcher.Setup(x => x.RegisteredCreatedHandle).Returns(mockedCreatedHandle.Object);
            mockedCreatedHandle.Setup(x => x.DeviceNotificationHandle).Returns(deviceNotificationHandle);

            // ACT
            destroyedHandle.ProcessFor(mockedUsbDeviceWatcher.Object);

            // ASSERT
            mockedDeviceManagement.Verify(x => x.UnRegister(deviceNotificationHandle), Times.Once());
        }