public void When_InValidHeartbeatMessageArrives_ThenMessagedetailsAreNotPublished()
 {
     _count = 0;
     HeartbeatProcessor processor = new HeartbeatProcessor();
     _container.ComposeParts(processor);
     IMessage message = new Message("BLAH", "1:10");
     processor.Execute(message);
     Assert.AreEqual(0, _count, "The message fired and it should not have");
 }
 public void When_InValidHeartbeatMessageDeviceNumberContainsCharacters_ThenMessagedetailsAreNotPublished()
 {
     _count = 0;
     HeartbeatProcessor processor = new HeartbeatProcessor();
     _container.ComposeParts(processor);
     IMessage message = new Message(processor.MessageType, "A:10");
     processor.Execute(message);
     Assert.AreEqual(0, _count, "The message fired and it should not have");
 }
 public void When_DoorBellMessageContainsTooManyParameters_ThenMessagedetailsAreNotPublished()
 {
     _count = 0;
     DoorBellProcessor processor = new DoorBellProcessor();
     _container.ComposeParts(processor);
     IMessage message = new Message(processor.MessageType, "1:BLAH");
     processor.Execute(message);
     Assert.AreEqual(0, _count, "The message did fire and it should not have");
 }
 public void When_InValidDoorbellMessageDetailExists_ThenMessagedetailsAreNotPublished()
 {
     _count = 0;
     DoorBellProcessor processor = new DoorBellProcessor();
     _container.ComposeParts(processor);
     IMessage message = new Message(processor.MessageType, "");
     processor.Execute(message);
     Assert.AreEqual(0, _count, "The message fired and it should not have");
 }
 public void When_InValidTemperatureMessageContainsTooManyCharacters_ThenMessagedetailsAreNotPublished()
 {
     _count = 0;
     TemperatureProcessor processor = new TemperatureProcessor();
     _container.ComposeParts(processor);
     IMessage message = new Message(processor.MessageType, "1:2:38:blah");
     processor.Execute(message);
     Assert.AreEqual(0, _count, "The message fired and it should not have");
 }
 public void When_InValidAnalogThresholdArrivesWithPinParmCharacters_ThenMessagedetailsAreNotPublished()
 {
     _count = 0;
     AnalogThreshholdProcessor processor = new AnalogThreshholdProcessor();
     _container.ComposeParts(processor);
     IMessage message = new Message(processor.MessageType, "1:A:2:3");
     processor.Execute(message);
     Assert.AreEqual(0, _count, "The message fired and it should not have");
 }
 public void When_ValidHeartbeatMessageArrives_ThenMessagedetailsArePublished()
 {
     _count = 0;
     HeartbeatProcessor processor = new HeartbeatProcessor();
     _container.ComposeParts(processor);
     IMessage message = new Message(processor.MessageType,"1:10");
     processor.Execute(message);
     Assert.AreEqual(1,_count,"The message did not fire");
 }
 public void When_ValidAnalogThresholdMessageArrives_ThenMessagedetailsArePublished()
 {
     _count = 0;
     AnalogThreshholdProcessor processor = new AnalogThreshholdProcessor();
     _container.ComposeParts(processor);
     IMessage message = new Message(processor.MessageType,"1:1:10:12");
     processor.Execute(message);
     Assert.AreEqual(1,_count,"The message did not fire");
 }
 public void When_InValidAnalogThresholdMessageWithTooManyParmsArrives_ThenMessagedetailsArePublished()
 {
     _count = 0;
     AnalogThreshholdProcessor processor = new AnalogThreshholdProcessor();
     _container.ComposeParts(processor);
     IMessage message = new Message(processor.MessageType, "1:1:10:12:BLAH");
     processor.Execute(message);
     Assert.AreEqual(0, _count, "The message did fire and it should not have");
 }
        private void HandleClientComm(object client)
        {
            TcpClient tcpClient = (TcpClient)client;
            NetworkStream clientStream = tcpClient.GetStream();
            byte[] message = new byte[4096];
            int bytesRead;
            while (true)
            {
                try
                {
                    // Wait for an entire line to be read
                    bytesRead = clientStream.Read(message, 0, 4096);
                }
                catch (Exception ex)
                {
                    break;
                }
                if (bytesRead == 0)
                    break;
                ASCIIEncoding encoder = new ASCIIEncoding();
                string data = encoder.GetString(message, 0, bytesRead);

                IMessage msg = new Message(data);

                // TODO Add an export that sends the raw data instead of dumping to the console
                System.Console.WriteLine(data);

                // Process the data that came from the Arduino
                if (MessageProcessors != null)
                {
                    foreach (IMessageProcessor processor in MessageProcessors)
                    {
                        if (processor.ShouldProcess(msg))
                        {
                            processor.Execute(msg);
                            break;
                        }
                    }
                }

            }
            tcpClient.Close();
        }