Exemplo n.º 1
0
        private void AddBasicMessageCreators()
        {
            string @namespace = "Sharpduino.Creators";
            var messageCreators = (from t in Assembly.GetExecutingAssembly().GetTypes()
                                   where t.IsClass && !t.IsAbstract && //We are searching for a non-abstract class
                                         t.Namespace == @namespace && //in the namespace we provide
                                         t.BaseType.GetGenericArguments()[0] != typeof (StaticMessage) && // Do not include the static message creator
                          t.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IMessageCreator<>)) //that implements IMessageCreator<>
                    select t).ToList();

            // Create an instance for each type we found and add it to the MessageCreators with
            // the Message Type that it creates as a key
            messageCreators.ForEach(
                t => MessageCreators[t.BaseType.GetGenericArguments()[0]] = (IMessageCreator)Activator.CreateInstance(t));

            // This is the special case for the static message creator
            StaticMessageCreator staticMessageCreator = new StaticMessageCreator();

            // Get only the StaticMessage derived types
            @namespace = "Sharpduino.Messages";
            var staticMessages = (from t in Assembly.GetExecutingAssembly().GetTypes()
                                  where t.IsClass && t.BaseType == typeof (StaticMessage)
                                  select t).ToList();

            // Add them to the MessageCreators dictionary
            staticMessages.ForEach(t => MessageCreators[t] = staticMessageCreator);
        }
Exemplo n.º 2
0
        private void AddBasicMessageCreators()
        {
            string @namespace      = "Sharpduino.Creators";
            var    messageCreators = (from t in Assembly.GetExecutingAssembly().GetTypes()
                                      where t.IsClass && !t.IsAbstract &&                                                                       //We are searching for a non-abstract class
                                      t.Namespace == @namespace &&                                                                              //in the namespace we provide
                                      t.BaseType.GetGenericArguments()[0] != typeof(StaticMessage) &&                                           // Do not include the static message creator
                                      t.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IMessageCreator <>)) //that implements IMessageCreator<>
                                      select t).ToList();

            // Create an instance for each type we found and add it to the MessageCreators with
            // the Message Type that it creates as a key
            messageCreators.ForEach(
                t => MessageCreators[t.BaseType.GetGenericArguments()[0]] = (IMessageCreator)Activator.CreateInstance(t));

            // This is the special case for the static message creator
            StaticMessageCreator staticMessageCreator = new StaticMessageCreator();

            // Get only the StaticMessage derived types
            @namespace = "Sharpduino.Messages";
            var staticMessages = (from t in Assembly.GetExecutingAssembly().GetTypes()
                                  where t.IsClass && t.BaseType == typeof(StaticMessage)
                                  select t).ToList();

            // Add them to the MessageCreators dictionary
            staticMessages.ForEach(t => MessageCreators[t] = staticMessageCreator);
        }
        public void Creates_Appropriate_Message(StaticMessage message)
        {
            var creator = new StaticMessageCreator();
            var bytes   = creator.CreateMessage(message);

            Assert.AreEqual(bytes, message.Bytes);
        }
Exemplo n.º 4
0
        public void Receive_Firmware_Message_From_Live_Arduino_Running_Standard_Firmata_2_3()
        {
            var smc   = new StaticMessageCreator();
            var bytes = smc.CreateMessage(new QueryFirmwareMessage());

            port.Write(bytes, 0, bytes.Length);

            // Wait for the arduino to reply
            Thread.Sleep(100);

            while (port.BytesToRead > 0)
            {
                var incomingByte = (byte)port.ReadByte();
                Assert.IsTrue(handler.CanHandle(incomingByte));
                handler.Handle(incomingByte);
            }

            mockBroker.Verify(p => p.CreateEvent(
                                  It.Is <SysexFirmwareMessage>(mes => mes.MajorVersion == 2 && mes.MinorVersion == 3)), Times.Once());
        }
 public void Throws_Error_On_Wrong_Message()
 {
     var creator = new StaticMessageCreator();
     Assert.Throws<MessageCreatorException>(() => creator.CreateMessage(new AnalogMessage()));
 }
 public void Creates_Appropriate_Message(StaticMessage message)
 {
     var creator = new StaticMessageCreator();
     var bytes = creator.CreateMessage(message);
     Assert.AreEqual(bytes,message.Bytes);
 }
        public void Throws_Error_On_Wrong_Message()
        {
            var creator = new StaticMessageCreator();

            Assert.Throws <MessageCreatorException>(() => creator.CreateMessage(new AnalogMessage()));
        }