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"); }
public void ObservableSubscription_Test() { output.WriteLine("ObservableSubscription_Test"); TestObservable observable = new TestObservable(); TestObserever observer = new TestObserever(); observable.SubscibeObserver(observer); List <IWristbandObserver> observers = observable.SubscribtionList; Assert.True(observers.Count > 0, "observers.Count should return exactly one subscription"); Assert.True(observers.IndexOf(observer) != -1, "observers should contain the observer object"); bool init, deinit, error, connect, debug, disconnect, profile, steps, unknown, write; init = deinit = error = connect = debug = disconnect = profile = steps = unknown = write = false; observer.TestInitResponse = () => { init = true; output.WriteLine("> TestObserever.OnBluetoothDeInitialized() :: called"); }; observer.TestDeInitResponse = () => { deinit = true; output.WriteLine("> TestObserever.OnBluetoothInitialized() :: called"); }; observer.TestOnErrorResponse = (WristbandProtocolError werror, string msg) => { error = true; output.WriteLine("> TestObserever.OnError() :: called - " + msg); }; observer.TestConnectedResponse = (string pheriperalID, string pheriperalName, WristbandProfile wprofile) => { connect = true; output.WriteLine("> TestObserever.OnWristbandConnected() :: called"); }; observer.TestDebugResponse = (string msg) => { debug = true; output.WriteLine("> TestObserever.OnWristbandDebugMessage() :: called"); }; observer.TestDisconnectedResponse = () => { disconnect = true; output.WriteLine("> TestObserever.OnWristbandDisconnected() :: called"); }; observer.TestProfileFoundResponse = (string pheriperalID, string pheriperalName) => { profile = true; output.WriteLine("> TestObserever.OnWristbandProfileFound() :: called"); }; observer.TestStepsCollectedResponse = (StepsData stepsData) => { steps = true; output.WriteLine("> TestObserever.OnWristbandStepsCollected() :: called"); }; observer.TestUnknownProfileResponse = (string pheriperalID, string pheriperalName) => { unknown = true; output.WriteLine("> TestObserever.OnWristbandUnknownProfile() :: called"); }; observer.TestWriteCompleteResponse = () => { write = true; output.WriteLine("> TestObserever.OnWristbandWriteComplete() :: called"); }; observable.OnInitComplete_Test(); observable.OnDeInitComplete_Test(); observable.OnERROR_Test(WristbandProtocolError.INITIALIZATION_FAILED, "Debug Error"); observable.OnConnected_Test("001", "002", BoosthWristbandServices.DebugProfile); observable.OnDebugMSG_Test("Debug Message"); observable.OnDisconnected_Test(); observable.OnMatchingProfile_Test("001", "002"); observable.OnUnknownProfile_Test("001", "002"); observable.OnStepsCollected_Test(new StepsData()); observable.OnWriteComplete_Test(); Assert.True(init); Assert.True(deinit); Assert.True(error); Assert.True(connect); Assert.True(debug); Assert.True(disconnect); Assert.True(profile); Assert.True(steps); Assert.True(unknown); Assert.True(write); observable.UnsubscibeObserver(observer); observers = observable.SubscribtionList; Assert.True(observers.Count == 0, "observers.Count should return exactly zero subscriptions after unsubscribing"); Assert.True(observers.IndexOf(observer) == -1, "observers should not contain the observer object anymore, after unsubscribing"); }