public void Should_Send_Messages_Using_The_SerialProvider() { var mockSerialProvider = new Mock <ISerialProvider>(); Func <IEnumerable <byte>, bool> f = b => { var c = b.ToArray(); return(c[0] == MessageConstants.ANALOG_MESSAGE && c[1] == 0x01 && c[2] == 0x02); }; using (var moqFirmataEmptyBase = new FirmataEmptyBaseStub(mockSerialProvider.Object)) { // Add the creator for the message moqFirmataEmptyBase.Creators.Add(typeof(AnalogMessage), new AnalogOutputMessageCreator()); // Send a new message moqFirmataEmptyBase.SendMessage(new AnalogMessage() { Pin = 0x01, Value = 0x02 }); } // Verify that the base class called the serialprovider's send method mockSerialProvider.Verify(x => x.Send( It.Is <IEnumerable <byte> >(b => b.First() == (MessageConstants.ANALOG_MESSAGE | 0x01) && b.Skip(1).First() == 0x02 && b.Skip(2).First() == 0x00))); }
public void Should_Throw_Error_If_There_Is_Not_Suitable_MessageCreator() { var mockSerialProvider = new Mock <ISerialProvider>(); using (var moqFirmataEmptyBase = new FirmataEmptyBaseStub(mockSerialProvider.Object)) { Assert.Throws <FirmataException>(() => moqFirmataEmptyBase.SendMessage(new AnalogMessage())); } }
public void Should_Throw_Error_If_There_Is_Not_Suitable_MessageCreator() { var mockSerialProvider = new Mock<ISerialProvider>(); using (var moqFirmataEmptyBase = new FirmataEmptyBaseStub(mockSerialProvider.Object)) { Assert.Throws<FirmataException>(() => moqFirmataEmptyBase.SendMessage(new AnalogMessage())); } }
public void Should_Send_Messages_Using_The_SerialProvider() { var mockSerialProvider = new Mock<ISerialProvider>(); Func<IEnumerable<byte>, bool> f = b => { var c = b.ToArray(); return c[0] == MessageConstants.ANALOG_MESSAGE && c[1] == 0x01 && c[2] == 0x02; }; using (var moqFirmataEmptyBase = new FirmataEmptyBaseStub(mockSerialProvider.Object)) { // Add the creator for the message moqFirmataEmptyBase.Creators.Add(typeof(AnalogMessage),new AnalogOutputMessageCreator()); // Send a new message moqFirmataEmptyBase.SendMessage(new AnalogMessage() { Pin = 0x01, Value = 0x02 }); } // Verify that the base class called the serialprovider's send method mockSerialProvider.Verify(x => x.Send( It.Is<IEnumerable<byte>>(b => b.First() == (MessageConstants.ANALOG_MESSAGE | 0x01) && b.Skip(1).First() == 0x02 && b.Skip(2).First() == 0x00))); }