public void Zero_length_string_encoded_without_error() { EncodedString es = new EncodedString(string.Empty); Assert.AreEqual(0x00, es.Encode().First()); Assert.AreEqual(0x00, es.Encode().Skip(1).First()); Assert.AreEqual(2, es.Encode().Count()); }
public void Topic_is_encoded_as_first_field() { EncodedString topicName = "Test/topic"; PublishVariableHeader variableHeader = new PublishVariableHeader(topicName); byte[] encodedTopicNameBytes = variableHeader .Encode() .Take( topicName.Encode().Count()).ToArray(); for (int i = 0; i < topicName.Encode().Count(); i++) { Assert.AreEqual(topicName.Encode().ToArray()[i], encodedTopicNameBytes[i]); } }
public void Encoded_string_accepts_specified_max_lenth_string() { // 12345678901234567890123 string length23Test = "Test 1 length to be: 23"; UInt16 MaxSpecLength = (UInt16)length23Test.Length; IByteEncodable es = new EncodedString(length23Test); byte[] esBytes = es.Encode().ToArray(); Assert.AreEqual(23, MaxSpecLength); Assert.AreEqual(MaxSpecLength.MostSignificantByte(), esBytes[0]); Assert.AreEqual(MaxSpecLength.LeastSignificantByte(), esBytes[1]); }
public void Username_encoded_when_provided() { EncodedString username = new EncodedString("username"); Authentication auth = new Authentication(username); EncodedString clientID = "ClientID"; IByteEncodable cp = new ConnectPayload(clientID, null, auth); IEnumerable <byte> encodedBytes = cp.Encode(); EncodedString encodedUsername = new EncodedString( new MemoryStream( encodedBytes.Skip(clientID.Encode().Count()).ToArray())); Assert.IsTrue(username == encodedUsername); }
public void Specified_character_set_encodes_correctly() { // 12345678901234567890123 string encodeTest1 = "abcdefghijklmnopqrstuvw"; string encodeTest2 = "xyzABCDEFGHIJKLMNOPQRST"; string encodeTest3 = "UVWXYZ0123456789"; IByteEncodable set1 = new EncodedString(encodeTest1); IByteEncodable set2 = new EncodedString(encodeTest2); IByteEncodable set3 = new EncodedString(encodeTest3); string decodedTest1 = utf8.GetString(set1.Encode().ToArray().Skip(2).ToArray()); string decodedTest2 = utf8.GetString(set2.Encode().ToArray().Skip(2).ToArray()); string decodedTest3 = utf8.GetString(set3.Encode().ToArray().Skip(2).ToArray()); Assert.AreEqual(encodeTest1, decodedTest1); Assert.AreEqual(encodeTest2, decodedTest2); Assert.AreEqual(encodeTest3, decodedTest3); }
public void Will_topic_encoded_when_provided() { EncodedString willTopic = "Will Topic"; Will w = new Will( QoSLevel.AtMostOnce, false, willTopic.Value, new EncodedDataField(utf8.GetBytes("Will Message"))); EncodedString clientID = "test 1"; IByteEncodable cp = new ConnectPayload(clientID, w); IEnumerable <byte> encodedBytes = cp.Encode(); EncodedString encodedTopic = new EncodedString( new MemoryStream( encodedBytes.Skip(clientID.Encode().Count()).ToArray())); Assert.IsTrue(willTopic == encodedTopic); }