public async Task BleManager_GetDeviceCharacteristics_Found()
        {
            var deviceId = "device-Id";
            var gsUuid   = Guid.Parse("4C088D33-76C6-4094-8C4A-65A80430678A");
            var gs       = new BleGattService {
                DeviceId = deviceId, Uuid = gsUuid
            };

            gs.Characteristics = new BleGattCharacteristic[] { };

            var bleAdapter = new DummyBleAdapter();

            var device = new BleDevice
            {
                Id   = deviceId,
                Name = "some-device-name"
            };

            var bm = new BleManager(new[] { bleAdapter }, null, null);

            bleAdapter.SetGetGattServices(device, new[] { gs });

            var res = await bm.GetDeviceCharacteristics(deviceId, gsUuid.ToString());

            res.ShouldBe(gs.Characteristics);
        }
        public void BleManager_GetDeviceCharacteristics_NotFound()
        {
            var deviceId = "device-Id";
            var gsUuid   = Guid.Parse("4C088D33-76C6-4094-8C4A-65A80430678A");
            var gs       = new BleGattService {
                DeviceId = deviceId, Uuid = gsUuid
            };

            gs.Characteristics = new BleGattCharacteristic[] { };

            var bleAdapter = new DummyBleAdapter();
            var device     = new BleDevice
            {
                Id   = deviceId,
                Name = "some-device-name"
            };

            var bm = new BleManager(new[] { bleAdapter }, null, null);

            bleAdapter.SetGetGattServices(device, new[] { gs });

            var task = bm.GetDeviceCharacteristics(deviceId, "not-exists-gatt-service-id");

            task.Exception.InnerExceptions.First().ShouldBeOfType <NullReferenceException>();
        }
        public void BleManager_RegisterToCharacteristicNotificationsasses()
        {
            const string deviceUuid         = "device-Id";
            const string serviceUuid        = "4C088D33-76C6-4094-8C4A-65A80430678A";
            const string characteristicUuid = "some-characteristic-id";
            const string message            = "this is notifucation content";
            var          gs = new BleGattService {
                DeviceId = deviceUuid, Uuid = Guid.Parse(serviceUuid)
            };

            gs.Characteristics = new BleGattCharacteristic[] { };

            var bleAdapter = new DummyBleAdapter();
            var device     = new BleDevice
            {
                Id   = deviceUuid,
                Name = "some-device-name"
            };

            var notifier = new Mock <INotifier>();
            var bm       = new BleManager(new[] { bleAdapter }, notifier.Object, null);

            bleAdapter.SetGetGattServices(device, new[] { gs });

            bleAdapter.RaiseDeviceValueChangedEvent(deviceUuid, serviceUuid, characteristicUuid, message);
            notifier.Verify(n => n.Push(It.Is <string>(s => s == deviceUuid), It.Is <BleDeviceValueChangedEventArgs>(
                                            b =>
                                            b.DeviceUuid == deviceUuid &&
                                            b.ServiceUuid == serviceUuid &&
                                            b.CharacteristicUuid == characteristicUuid &&
                                            b.Message == message)), Times.Once);
        }
        public async Task BleManager_RegisterToCharacteristicNotifications_Fails(bool readResult)
        {
            var deviceId         = "device-Id";
            var gattServiceId    = "4C088D33-76C6-4094-8C4A-65A80430678A";
            var characteristicId = "some-characteristic-id";
            var gs = new BleGattService {
                DeviceId = deviceId, Uuid = Guid.Parse(gattServiceId)
            };

            gs.Characteristics = new BleGattCharacteristic[] { };

            var bleAdapter = new DummyBleAdapter();
            var device     = new BleDevice
            {
                Id   = deviceId,
                Name = "some-device-name"
            };

            var bm = new BleManager(new[] { bleAdapter }, null, null);

            bleAdapter.SetGetGattServices(device, new[] { gs });
            bleAdapter.BleNotificationResult = readResult;
            var res = await bm.RegisterToCharacteristicNotifications(deviceId, gattServiceId, characteristicId);

            res.ShouldBe(readResult);
        }
        public async Task BleManager_WriteToCharacteristic(bool writeResult)
        {
            var deviceId         = "device-Id";
            var gattServiceId    = "4C088D33-76C6-4094-8C4A-65A80430678A";
            var characteristicId = "some-characteristic-id";
            var gs = new BleGattService {
                DeviceId = deviceId, Uuid = Guid.Parse(gattServiceId)
            };

            gs.Characteristics = new BleGattCharacteristic[] { };

            var bleAdapter = new DummyBleAdapter();
            var device     = new BleDevice
            {
                Id   = deviceId,
                Name = "some-device-name"
            };

            var bm = new BleManager(new[] { bleAdapter }, null, null);

            bleAdapter.SetGetGattServices(device, new[] { gs });
            bleAdapter.WriteToCharacteristicResult = writeResult;
            var res = await bm.WriteToCharacteristric(deviceId, gattServiceId, characteristicId, new List <byte>());

            res.ShouldBe(writeResult);
        }
        public async Task BleManager_GetDeviceGattServices(IEnumerable <BleGattService> gattServices)
        {
            var bleAdapter = new DummyBleAdapter();
            var device     = new BleDevice
            {
                Id   = "some-device-id",
                Name = "some-device-name"
            };

            var bm = new BleManager(new[] { bleAdapter }, null, null);

            bleAdapter.SetGetGattServices(device, gattServices);

            var res = await bm.GetDeviceGattServices(device.Id);

            res.Count().ShouldBe(gattServices?.Count() ?? 0);
            foreach (var r in res)
            {
                gattServices.Any(s => s.Uuid == r.Uuid).ShouldBeTrue();
            }
        }