/* * StopScan() * Disconnect() * Abort() * ReadStepsAndExercizeTime() * SetClockAndUserSettings (byte [] data) * ClearHistory () * ReadCharacteristicsHandler(string str, byte[] dat) */ /* * MOCK OBJECTS */ void BluetoothHardwareInterface_ScanDevices(Mock_BluetoothHardwareInterface bhi, Mock_WristbandServices services) { bhi.ScanForPeripheralsWithServices_Mock = (string[] serviceUUIDs, Action <string, string> action) => { // fire device found: device name and id output.WriteLine("> BluetoothHardwareInterface.ScanForPeripheralsWithServices() :: called"); action("PCI\\VEN_1000&DEV_0001&SUBSYS_00000000&REV_02", "PR102"); }; bhi.ConnectToPeripheral_Mock = (string name, Action <string> connectAction, Action <string, string> serviceAction, Action <string, string, string> characteristicAction) => { // characteristicAction: string device_id, string service_id, string characteristic_id // represents one of the bleutooth devices found output.WriteLine("> BluetoothHardwareInterface.ConnectToPeripheral() :: called"); characteristicAction("PR102", "0000FED0-494C-4F47-4943-544543480000", "0000FED1-494C-4F47-4943-544543480000"); }; bhi.SubscribeCharacteristic_Mock = (string name, string service, string characteristic, Action <string> notificationAction, Action <string, byte[]> action) => { // subscribe for device notifications output.WriteLine("> BluetoothHardwareInterface.SubscribeCharacteristic() :: called"); notificationAction("Notification Debug message"); }; services.ListOfProfileServicesIDs_Mock = () => { return(new string[1] { "0000FED0-494C-4F47-4943-544543480000" }); }; services.GetProfileByName_Mock = (string name) => { output.WriteLine("> WristbandServices.GetProfileByName() :: called -name:" + name); return(BoosthWristbandServices.DebugProfile); }; }
public void DeInitializeBluetoothCentral_Test() { Mock_BluetoothHardwareInterface bhi = new Mock_BluetoothHardwareInterface(); Mock_WristbandServices services = new Mock_WristbandServices(); WristbandProtocol protocol = new WristbandProtocol(bhi, services); TestObserever observer = new TestObserever(); // Bluetooth hardware interface behaviour // --------------------------- bhi.DeInitialize_Mock = (Action action) => { action(); }; bhi.Initialize_Mock = Initialize_BHI_Success; // track observer event states // --------------------------- bool initFired = false; bool deinitFired = false; bool errorFired = false; observer.TestInitResponse = () => { output.WriteLine("> TestObserever.OnBluetoothInitialized() :: called"); initFired = true; }; observer.TestDeInitResponse = () => { output.WriteLine("> TestObserever.OnBluetoothDeInitialized() :: called"); deinitFired = true; }; observer.TestOnErrorResponse = (WristbandProtocolError error, string msg) => { output.WriteLine("> TestObserever.OnError() :: Error - " + msg); errorFired = true; }; // run protocol // --------------------------- protocol.SubscibeObserver(observer); protocol.InitialyzeCentral(); Assert.True(initFired && !deinitFired, "Observer Initialize should fire before Deinitialize"); Assert.True(protocol.IsInitialized(), "protocol should be in initialized state before we deinitialize"); protocol.DeInitialyzeCentral(); // test results // --------------------------- Assert.True(deinitFired, "Observer should fire OnBluetoothDeInitialized"); Assert.False(errorFired, "Observer should not fire OnError"); // protocol state tests Assert.False(protocol.IsInitialized(), "protocol should not be in initialized state"); Assert.False(protocol.HasProfile(), "protocol should not have a profile"); Assert.False(protocol.HasDiscoveredDevice(), "protocol should not be have disovered divices"); Assert.False(protocol.IsConnected(), "protocol should not be connected"); Assert.False(protocol.HasHistory(), "protocol should not have a history"); Assert.False(protocol.IsBusy(), "protocol should not be busy"); }
public void ScanForDeviceAndAutoConnect_Test() { Mock_BluetoothHardwareInterface bhi = new Mock_BluetoothHardwareInterface(); Mock_WristbandServices services = new Mock_WristbandServices(); WristbandProtocol protocol = new WristbandProtocol(bhi, services); TestObserever observer = new TestObserever(); // Bluetooth hardware interface behaviour // --------------------------- BluetoothHardwareInterface_ScanDevices(bhi, services); bhi.Initialize_Mock = Initialize_BHI_Success; // track observer event states // --------------------------- bool connectFired = false; bool errorFired = false; bool profileFoundFired = false; bool unknownProfile = false; observer.TestInitResponse = () => { output.WriteLine("> TestObserever.OnBluetoothInitialized() :: called"); }; observer.TestConnectedResponse = (string pheriperalID, string pheriperalName, WristbandProfile profile) => { output.WriteLine("> TestObserever.OnWristbandConnected() :: called -name:" + pheriperalName + ", -id:" + pheriperalID); connectFired = true; }; observer.TestOnErrorResponse = (WristbandProtocolError error, string msg) => { output.WriteLine("> TestObserever.OnError() :: Error - " + msg); errorFired = true; }; observer.TestProfileFoundResponse = (string id, string name) => { output.WriteLine("> TestObserever.OnWristbandProfileFound() :: called -name:" + name + ", -id:" + id); profileFoundFired = true; }; observer.TestUnknownProfileResponse = (string id, string name) => { output.WriteLine("> TestObserever.OnWristbandUnknownProfile() :: called -name:" + name + ", -id:" + id); unknownProfile = true; }; // run protocol // --------------------------- protocol.SubscibeObserver(observer); protocol.InitialyzeCentral(); Assert.True(!errorFired && !connectFired, "Observer Initialize should fire before scanning for devices"); Assert.True(protocol.IsInitialized(), "protocol should be in initialized state before scanning for devices"); Assert.False(protocol.HasProfile(), "protocol should not have a profile before scanning for devices"); Assert.False(protocol.HasDiscoveredDevice(), "protocol should not be have disovered divices before scanning for devices"); Assert.False(protocol.IsConnected(), "protocol should not be connected before scanning for devices"); protocol.ScanForDeviceAndAutoConnect(); // test results // --------------------------- Assert.True(connectFired, "Observer should fire OnWristbandConnected"); Assert.False(errorFired, "Observer should not fire OnError"); Assert.True(profileFoundFired, "Observer should fire OnWristbandProfileFound"); Assert.False(unknownProfile, "Observer should not fire OnWristbandUnknownProfile"); // protocol state tests Assert.True(protocol.IsInitialized(), "protocol should be in initialized state"); Assert.True(protocol.HasProfile(), "protocol should have a profile"); Assert.True(protocol.HasDiscoveredDevice(), "protocol should have disovered divices"); Assert.True(protocol.IsConnected(), "protocol should be connected"); Assert.False(protocol.HasHistory(), "protocol should not have a history"); Assert.False(protocol.IsBusy(), "protocol should not be busy"); }