コード例 #1
0
        public async Task TryReadValueAsync_ForGattCommunicationStatus_SetsProtocolError(
            RawValueReader sut,
            [Freeze] IBufferReader reader,
            IGattReadResultWrapper result,
            IGattCharacteristicWrapper characteristic,
            byte protocolError)
        {
            WithTryReadValueResult(reader,
                                   Array.Empty <byte> ( ));

            result.Status
            .Returns(GattCommunicationStatus.Success);

            result.ProtocolError
            .Returns(protocolError);

            characteristic.WithCharacteristicProperties(GattCharacteristicProperties.Read)
            .WithReadValueAsyncResult(result);

            _ = await sut.TryReadValueAsync(characteristic);

            sut.ProtocolError
            .Should( )
            .Be(protocolError);
        }
コード例 #2
0
        public static IGattCharacteristicWrapper WithReadValueAsyncResult(
            this IGattCharacteristicWrapper characteristic,
            IGattReadResultWrapper result)
        {
            _ = characteristic.ReadValueAsync( )
                .Returns(Task.FromResult(result));

            return(characteristic);
        }
コード例 #3
0
        public async Task TryReadValueAsync_ForNotSupportingRead_Empty(
            RawValueReader sut,
            [Freeze] IBufferReader reader,
            IGattReadResultWrapper result,
            IGattCharacteristicWrapper characteristic)
        {
            WithTryReadValueResult(reader,
                                   Array.Empty <byte> ( ));

            result.Status
            .Returns(GattCommunicationStatus.Success);

            characteristic.WithCharacteristicProperties(GattCharacteristicProperties.None)
            .WithReadValueAsyncResult(result);

            var(_, bytes) = await sut.TryReadValueAsync(characteristic);

            bytes.Should( )
            .BeEmpty( );
        }
コード例 #4
0
        public async Task TryReadValueAsync_ForSupportsNotifyTrue_False(
            RawValueReader sut,
            [Freeze] IBufferReader reader,
            IGattReadResultWrapper result,
            IGattCharacteristicWrapper characteristic)
        {
            WithTryReadValueResult(reader,
                                   Array.Empty <byte> ( ));

            result.Status
            .Returns(GattCommunicationStatus.Success);

            characteristic.WithCharacteristicProperties(GattCharacteristicProperties.Notify)
            .WithReadValueAsyncResult(result);

            var(success, _) = await sut.TryReadValueAsync(characteristic);

            success.Should( )
            .BeFalse( );
        }
コード例 #5
0
        public async Task TryReadValueAsync_ForGattCommunicationStatusIsSuccess_Bytes(
            RawValueReader sut,
            [Freeze] IBufferReader reader,
            IGattReadResultWrapper result,
            IGattCharacteristicWrapper characteristic,
            byte []                   bytes)
        {
            WithTryReadValueResult(reader,
                                   bytes);

            result.Status
            .Returns(GattCommunicationStatus.Success);

            characteristic.WithCharacteristicProperties(GattCharacteristicProperties.Read)
            .WithReadValueAsyncResult(result);

            var(_, value) = await sut.TryReadValueAsync(characteristic);

            value.Should( )
            .BeEquivalentTo(bytes);
        }