public void ReadRawDataAsyncExceptionTest() { var stubHelper = new StubNativeHelper(); var stubInfo = new StubDeviceInfo($"{nameof(ReadRawDataAsyncExceptionTest)}", 1, 1); var mock = new MockHidDevice(stubInfo, stubHelper); Assert.CatchAsync <DeviceIsNotOpenedException>(() => mock.ReadRawDataAsync()); }
public void WriteRawDataAsyncExceptionTest() { var stubHelper = new StubNativeHelper(); var stubInfo = new StubDeviceInfo($"{nameof(ReadOpenTest)}", 1, 1); var mock = new MockHidDevice(stubInfo, stubHelper); Assert.CatchAsync <ArgumentNullException>(() => mock.WriteRawDataAsync(null)); }
public void BaseHidDeviceExceptionTest() { var stubHelper = new StubNativeHelper(); var stubInfo = new StubDeviceInfo($"{nameof(BaseHidDeviceExceptionTest)}", 1, 1); Assert.Catch <ArgumentNullException>(() => new MockHidDevice(null, stubHelper)); Assert.Catch <ArgumentNullException>(() => new MockHidDevice(stubInfo, null)); Assert.Catch <ArgumentNullException>(() => new MockHidDevice(null, null)); }
public void WriteOpenExceptionTest() { var stubHelper = new StubNativeHelper(); var stubInfo = new StubDeviceInfo($"{nameof(WriteOpenExceptionTest)}", 1, 1); var mock = new MockHidDevice(stubInfo, stubHelper); stubHelper.IsThrow = true; Assert.Catch <DeviceCouldNotOpenedException>(() => mock.WriteOpen()); }
public void WriteOpenTest() { var stubHelper = new StubNativeHelper(); var stubInfo = new StubDeviceInfo($"{nameof(WriteOpenTest)}", 1, 1); var mock = new MockHidDevice(stubInfo, stubHelper); mock.WriteOpen().IsTrue(); mock.IsWriteOpened.IsTrue(); }
public void ReadRawDataAsyncExceptionTest1() { var stubHelper = new StubNativeHelper(); var stubInfo = new StubDeviceInfo($"{nameof(ReadRawDataAsyncExceptionTest1)}", 0, 1); var mock = new MockHidDevice(stubInfo, stubHelper); mock.ReadHandle = new SafeFileHandle(new IntPtr(1), true); Assert.CatchAsync <HasNotCapabilityException>(() => mock.ReadRawDataAsync()); }
public void WriteOpenFailureTest() { var stubHelper = new StubNativeHelper(); var stubInfo = new StubDeviceInfo($"{nameof(WriteOpenFailureTest)}", 1, 1); var mock = new MockHidDevice(stubInfo, stubHelper); stubHelper.IsFailureHandle = true; mock.WriteOpen().IsFalse(); mock.IsWriteOpened.IsFalse(); }
public void WriteRawDataAsyncExceptionTest2() { var stubHelper = new StubNativeHelper(); var stubInfo = new StubDeviceInfo($"{nameof(ReadOpenTest)}", 1, 0); var mock = new MockHidDevice(stubInfo, stubHelper); mock.WriteHandle = new SafeFileHandle(new IntPtr(1), true); Assert.CatchAsync <HasNotCapabilityException>(() => mock.WriteRawDataAsync(new byte[] {})); }
public void WriteCloseTest() { var stubHelper = new StubNativeHelper(); var stubInfo = new StubDeviceInfo($"{nameof(WriteCloseTest)}", 1, 1); var mock = new MockHidDevice(stubInfo, stubHelper); mock.WriteHandle = new SafeFileHandle(new IntPtr(1), true); mock.WriteClose(); mock.IsWriteOpened.IsFalse(); mock.WriteHandle.IsClosed.IsTrue(); }
public async Task WriteRawDataAsyncTest(byte[] data) { var stubHelper = new StubNativeHelper(); var stubInfo = new StubDeviceInfo($"{nameof(ReadOpenTest)}", 1, 10); var mock = new MockHidDevice(stubInfo, stubHelper); mock.WriteHandle = new SafeFileHandle(new IntPtr(1), true); stubHelper.IsWriteAsync.IsFalse(); await mock.WriteRawDataAsync(data); stubHelper.IsWriteAsync.IsTrue(); stubHelper.WriteReturnValue.SequenceEqual(data); }
public void ReadRawDataAsyncCancelTest() { var cts = new CancellationTokenSource(); var stubHelper = new StubNativeHelper(); var stubInfo = new StubDeviceInfo($"{nameof(ReadRawDataAsyncCancelTest)}", 1, 1); var mock = new MockHidDevice(stubInfo, stubHelper); mock.ReadHandle = new SafeFileHandle(new IntPtr(1), true); stubHelper.IsDelay = true; var value = mock.ReadRawDataAsync(cts.Token); cts.Cancel(); Assert.CatchAsync <OperationCanceledException>(() => value); }
public async Task ReadRawDataAsyncTest(byte[] data) { var stubHelper = new StubNativeHelper(); var stubInfo = new StubDeviceInfo($"{nameof(ReadRawDataAsyncTest)}", 1, 1); var mock = new MockHidDevice(stubInfo, stubHelper); mock.ReadHandle = new SafeFileHandle(new IntPtr(1), true); stubHelper.ReadReturnValue = data; stubHelper.IsReadAsync.IsFalse(); var value = await mock.ReadRawDataAsync(); value.SequenceEqual(data); stubHelper.IsReadAsync.IsTrue(); }
public void BaseHidDeviceTest() { var stubHelper = new StubNativeHelper(); var stubInfo = new StubDeviceInfo($"{nameof(BaseHidDeviceTest)}", 1, 1); var mock = new MockHidDevice(stubInfo, stubHelper); mock.IsNotNull(); mock.DisposeTokenSource.IsNotNull(); mock.DisposeTokenSource.IsCancellationRequested.IsFalse(); mock.DisposeTokenSource.Token.Is(mock.DisposeToken); mock.DisposeToken.IsCancellationRequested.IsFalse(); mock.IsReadOpened.IsFalse(); mock.IsWriteOpened.IsFalse(); mock.DeviceInfo.Is(stubInfo); }