/// <summary> /// Initializes a new instance of the <see cref="ProcessHandleResult"/> class. /// </summary> /// <param name="handle"> /// The device notification handle. /// </param> /// <param name="marshalWrapper"> /// The marshal static class wrapper. /// </param> public ProcessHandleResult(IntPtr handle, IMarshalWrapper marshalWrapper) { Handle = handle; Win32Error = new Win32ErrorWrapper(0); if (handle != IntPtr.Zero) { return; } Win32Error = marshalWrapper.GetLastWin32Error(); }
/// <summary> /// Initializes a new instance of the <see cref="ProcessHandleResult"/> class. /// </summary> /// <param name="handle"> /// The device notification handle. /// </param> /// <param name="marshalWrapper"> /// The marshal static class wrapper. /// </param> public ProcessHandleResult(IntPtr handle, IMarshalWrapper marshalWrapper) { Handle = handle; Win32Error = new Win32ErrorWrapper(0); if (handle != IntPtr.Zero) { return; } Win32Error = marshalWrapper.GetLastWin32Error(); }
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 Constructor_WhenIntPtrIsZero_ThenErrorIsSetToGetLastError() { // 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.True(error.IsError(2)); }
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_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); }