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); }
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); }
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); }
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); }