示例#1
0
        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());
        }
示例#2
0
        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));
        }
示例#3
0
        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));
        }
示例#4
0
        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());
        }
示例#5
0
        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();
        }
示例#6
0
        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());
        }
示例#7
0
        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();
        }
示例#8
0
        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[] {}));
        }
示例#9
0
        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();
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        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();
        }
示例#13
0
        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);
        }