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
 public void Services_ForInvoked_CallsServices(
     GattServicesProvider sut,
     [Freeze][Populate] IGattServicesDictionary services)
 {
     sut.Services
     .Should( )
     .BeEquivalentTo(services.ReadOnlyDictionary);
 }
        public async Task Refresh_ForInvoked_ClearsServices(
            GattServicesProvider sut,
            [Freeze] IGattServicesDictionary services)
        {
            await sut.Refresh();

            services.Received()
            .Clear();
        }
示例#4
0
        public void Dispose_ForInvoked_CallsServices(
            GattServicesProvider sut,
            [Freeze][Populate] IGattServicesDictionary services)
        {
            sut.Dispose( );

            services.Received( )
            .Dispose( );
        }
        public void Constructor_ForServicesNull_Throws(
            Lazy <GattServicesProvider> sut,
            [BeNull] IGattServicesDictionary services)
        {
            // ReSharper disable once UnusedVariable
            Action action = () =>
            {
                var test = sut.Value;
            };

            action.Should()
            .Throw <ArgumentNullException>()
            .WithParameter(nameof(services));
        }
示例#6
0
        public GattServicesProvider([NotNull] ILogger logger,
                                    [NotNull] IGattServicesDictionary services,
                                    [NotNull] ISubject <GattCommunicationStatus> refreshed,
                                    [NotNull] IBluetoothLeDeviceWrapper device)
        {
            Guard.ArgumentNotNull(logger,
                                  nameof(logger));
            Guard.ArgumentNotNull(services,
                                  nameof(services));
            Guard.ArgumentNotNull(refreshed,
                                  nameof(refreshed));
            Guard.ArgumentNotNull(device,
                                  nameof(device));

            _logger    = logger;
            _services  = services;
            _refreshed = refreshed;
            _device    = device;
        }
        public BluetoothLeDeviceWrapper(
            [JetBrains.Annotations.NotNull] ILogger logger,
            [JetBrains.Annotations.NotNull] IScheduler scheduler,
            [JetBrains.Annotations.NotNull] IGattServicesProviderFactory providerFactory,
            [JetBrains.Annotations.NotNull] IGattDeviceServicesResultWrapperFactory servicesFactory,
            [JetBrains.Annotations.NotNull] IGattServicesDictionary gattServicesDictionary,
            [JetBrains.Annotations.NotNull] ISubject <BluetoothConnectionStatus> connectionStatusChanged,
            [JetBrains.Annotations.NotNull] BluetoothLEDevice device)
        {
            Guard.ArgumentNotNull(logger,
                                  nameof(logger));
            Guard.ArgumentNotNull(scheduler,
                                  nameof(scheduler));
            Guard.ArgumentNotNull(providerFactory,
                                  nameof(providerFactory));
            Guard.ArgumentNotNull(servicesFactory,
                                  nameof(servicesFactory));
            Guard.ArgumentNotNull(gattServicesDictionary,
                                  nameof(gattServicesDictionary));
            Guard.ArgumentNotNull(connectionStatusChanged,
                                  nameof(connectionStatusChanged));
            Guard.ArgumentNotNull(device,
                                  nameof(device));

            _logger                  = logger;
            _servicesFactory         = servicesFactory;
            _provider                = providerFactory.Create(this);
            _gattServicesDictionary  = gattServicesDictionary;
            _connectionStatusChanged = connectionStatusChanged;
            _device                  = device;

            var statusChanged =
                Observable.FromEventPattern <object> (_device,
                                                      "ConnectionStatusChanged");

            _subscriberConnectionStatus = statusChanged.SubscribeOn(scheduler)
                                          .Subscribe(OnConnectionStatusChanged);
        }