public async Task Refresh_ForConnectedAndCharacteristicsUnreachable_DoesNotAddService(
            GattServicesProvider sut,
            [Freeze] IBluetoothLeDeviceWrapper device,
            [Freeze] IGattServicesDictionary services,
            IGattDeviceServicesResultWrapper result,
            IGattDeviceServiceWrapper service,
            IGattCharacteristicsResultWrapper characteristics)
        {
            result.Status
            .Returns(GattCommunicationStatus.Success);

            result.Services
            .Returns(new[] { service });

            device.ConnectionStatus
            .Returns(BluetoothConnectionStatus.Connected);

            device.GetGattServicesAsync()
            .Returns(Task.FromResult(result));

            characteristics.Status
            .Returns(GattCommunicationStatus.Unreachable);

            service.GetCharacteristicsAsync()
            .Returns(characteristics);

            await sut.Refresh();

            services[service]
            .Should()
            .NotBe(characteristics);
        }
示例#2
0
        private async Task GetCharacteristicsAsync(IGattDeviceServicesResultWrapper gatt)
        {
            foreach (var service in gatt.Services)
            {
                var characteristics = await service.GetCharacteristicsAsync( );

                if (characteristics.Status != GattCommunicationStatus.Success)
                {
                    _logger.Error($"[{_device.DeviceId}] Could not get Characteristics for device " +
                                  $"'{service.DeviceId}' and service '{service.Uuid}'");

                    continue;
                }

                _services [service] = characteristics;
            }
        }
        public async Task Refresh_ForConnected_SetsGattCommunicationStatusUnreachable(
            GattServicesProvider sut,
            [Freeze] IBluetoothLeDeviceWrapper device,
            IGattDeviceServicesResultWrapper result)
        {
            result.Status
            .Returns(GattCommunicationStatus.Unreachable);

            device.ConnectionStatus
            .Returns(BluetoothConnectionStatus.Connected);

            device.GetGattServicesAsync()
            .Returns(Task.FromResult(result));

            await sut.Refresh();

            sut.GattCommunicationStatus
            .Should()
            .Be(GattCommunicationStatus.Unreachable);
        }
        public async Task GattCommunicationStatus_ForConnectedAndServicesAvailable_Success(
            GattServicesProvider sut,
            [Freeze] IBluetoothLeDeviceWrapper device,
            IGattDeviceServicesResultWrapper resultWrapper)
        {
            resultWrapper.Status
            .Returns(GattCommunicationStatus.Success);

            device.ConnectionStatus
            .Returns(BluetoothConnectionStatus.Connected);

            device.GetGattServicesAsync()
            .Returns(resultWrapper);

            await sut.Refresh();

            sut.GattCommunicationStatus
            .Should()
            .Be(resultWrapper.Status);
        }
        public async Task Refresh_ForConnected_Notifies(
            GattServicesProvider sut,
            [Freeze] IBluetoothLeDeviceWrapper device,
            [Freeze] ISubject <GattCommunicationStatus> refreshed,
            IGattDeviceServicesResultWrapper result)
        {
            var expected = GattCommunicationStatus.ProtocolError;

            result.Status
            .Returns(expected);

            device.ConnectionStatus
            .Returns(BluetoothConnectionStatus.Connected);

            device.GetGattServicesAsync()
            .Returns(Task.FromResult(result));

            await sut.Refresh();

            refreshed.Received()
            .OnNext(expected);
        }