Пример #1
0
        public void BleManager_ConnectAndDisconnectDevice()
        {
            var dummyAdapter = new DummyBleAdapter();

            var bm     = new BleManager(new[] { dummyAdapter }, null, null);
            var device = new BleDevice
            {
                Id   = "some-device-id",
                Name = "Some-device-Uuid"
            };

            dummyAdapter.RaiseDeviceDiscoveredEvent(device);
            var devices = bm.GetDiscoveredDevices();

            devices.Count().ShouldBe(1);
            var d = devices.First();

            d.Name = device.Name;
            d.Id   = device.Id;

            dummyAdapter.RaiseDeviceConnectedEvent(device);
            devices = bm.GetDiscoveredDevices();
            devices.Count().ShouldBe(1);
            d      = devices.First();
            d.Name = device.Name;
            d.Id   = device.Id;

            dummyAdapter.RaiseDeviceDisconnectedEvent(device);
            devices = bm.GetDiscoveredDevices();
            devices.Count().ShouldBe(1);
        }
Пример #2
0
        public async Task BleManager_Unpair(bool expUnpairResult)
        {
            var dummyAdapter = new DummyBleAdapter {
                DisconnectResult = expUnpairResult
            };

            var bm     = new BleManager(new[] { dummyAdapter }, null, null);
            var device = new BleDevice
            {
                Id   = "some-device-id_" + DateTime.Now.ToString("yyyy-MMMM-dd_hh:mm:ss.fffZ"),
                Name = "Some-device-Uuid"
            };

            dummyAdapter.RaiseDeviceDiscoveredEvent(device);
            var unpairResult = await bm.Disconnect(device.Id);

            unpairResult.ShouldBe(expUnpairResult);
        }