コード例 #1
0
        public void Constructor_WhenIntPtrIsNotZero_ThenErrorExceptionIsSuccess()
        {
            // ARRANGE
            var mockedMarshalWrapper = new Mock<IMarshalWrapper>();

            // ACT
            var processHandleResult = new ProcessHandleResult(new IntPtr(42), mockedMarshalWrapper.Object);

            // ASSERT
            Assert.True(processHandleResult.Win32Error.IsSuccess);
        }
コード例 #2
0
        public void Constructor_WhenIntPtrIsZero_ThenErrorIsNotNull()
        {
            // ARRANGE
            var win32ErrorWrapper = new Win32ErrorWrapper(2);
            var mockedMarshalWrapper = new Mock<IMarshalWrapper>();
            mockedMarshalWrapper.Setup(x => x.GetLastWin32Error()).Returns(win32ErrorWrapper);

            var processHandleResult = new ProcessHandleResult(IntPtr.Zero, mockedMarshalWrapper.Object);

            // ACT
            var error = processHandleResult.Win32Error;

            // ASSERT
            Assert.NotNull(error);
        }
コード例 #3
0
        public void SuccessTest_WhenIntPtrIsZero_ThenErrorNotified()
        {
            // ARRANGE
            const int errorCode = 2;
            var errorExceptionSent = new Win32ErrorWrapper(errorCode);
            var mockedMarshalWrapper = new Mock<IMarshalWrapper>();
            mockedMarshalWrapper.Setup(x => x.GetLastWin32Error()).Returns(errorExceptionSent);
            var processHandleResult = new ProcessHandleResult(IntPtr.Zero, mockedMarshalWrapper.Object);
            var subject = new Subject<IUsbDeviceNotification>();
            Exception exceptionCaught = null;

            // ACT
            subject.Subscribe(next => { }, exception => { exceptionCaught = exception; });
            processHandleResult.SuccessTest(subject);

            // ASSERT
            Assert.NotNull(exceptionCaught);
            Assert.IsType<Win32Exception>(exceptionCaught);
            Assert.Equal(errorCode, ((Win32Exception)exceptionCaught).NativeErrorCode);
        }
コード例 #4
0
        public void SuccessTest_WhenIntPtrIsNotZero_ThenErrorNotNotified()
        {
            // ARRANGE
            var mockedMarshalWrapper = new Mock<IMarshalWrapper>();
            var processHandleResult = new ProcessHandleResult(new IntPtr(42), mockedMarshalWrapper.Object);
            var subject = new Subject<IUsbDeviceNotification>();
            Exception exceptionCaught = null;

            // ACT
            subject.Subscribe(next => { }, exception => { exceptionCaught = exception; });
            processHandleResult.SuccessTest(subject);

            // ASSERT
            Assert.Null(exceptionCaught);
        }