Exemple #1
0
        public void Given_Valid_Arguments_When_Multiple_Subscribe_Invoked_Then_Valid_Result_Asserted()
        {
            Callbacks callbacks           = new Callbacks();
            VitalsMonitoringFunction func = new VitalsMonitoringFunction(callbacks.VitalsCallback);

            vitalsMonitorList.Subscribe("patientId", "id", func);
            func = new VitalsMonitoringFunction(callbacks.VitalsCallback1);
            vitalsMonitorList.Subscribe("patientId1", "id1", func);
            SharedResources.VitalsMonitorList.VitalsMonitorList list = SharedResources.VitalsMonitorList.VitalsMonitorList.Instance;
            var           output = list.TryGetValue("patientId");
            PatientVitals alert  = new PatientVitals();

            foreach (var function in output)
            {
                function.Invoke(alert);
            }
            Assert.AreEqual("TestPassed", alert.PatientId);
            output = list.TryGetValue("patientId1");
            foreach (var function in output)
            {
                function.Invoke(alert);
            }
            Assert.AreEqual("TestPassed1", alert.PatientId);
            vitalsMonitorList.Unsubscribe("patientId", "id");
            vitalsMonitorList.Unsubscribe("patientId1", "id1");
        }
Exemple #2
0
        public void Given_Invalid_Arguments_When_TryGetValue_Invoked_Then_Invalid_Result_Asserted()
        {
            Callbacks callbacks           = new Callbacks();
            VitalsMonitoringFunction func = new VitalsMonitoringFunction(callbacks.VitalsCallback);

            vitalsMonitorList.Subscribe("patientId", "id", func);
            Assert.IsFalse(vitalsMonitorList.TryGetValue("id2").Any());
            vitalsMonitorList.Unsubscribe("patientId", "id");
        }
Exemple #3
0
        public void Given_Valid_Arguments_When_Multiple_Instance_Invoked_Then_Valid_Result_Asserted()
        {
            Callbacks callbacks           = new Callbacks();
            VitalsMonitoringFunction func = new VitalsMonitoringFunction(callbacks.VitalsCallback);

            vitalsMonitorList.Subscribe("patientId", "id", func);
            SharedResources.VitalsMonitorList.VitalsMonitorList list = SharedResources.VitalsMonitorList.VitalsMonitorList.Instance;
            Assert.IsFalse(list.IsEmpty());
            vitalsMonitorList.Unsubscribe("patientId", "id");
            Assert.IsTrue(list.IsEmpty());
        }
        public void Subscribe(string patientId, string id, VitalsMonitoringFunction function)
        {
            mutex.WaitOne();
            Dictionary <string, VitalsMonitoringFunction> subscribers;

            vitalsMonitoringList.TryGetValue(patientId, out subscribers);
            if (subscribers != null)
            {
                subscribers.Add(patientId, function);
            }
            else
            {
                subscribers = new Dictionary <string, VitalsMonitoringFunction>();
                subscribers.Add(id, function);
                vitalsMonitoringList.Add(patientId, subscribers);
            }
            mutex.ReleaseMutex();
        }