/// <summary> /// Unmarshals a PrimitiveMap directly from a Stream object. This /// allows for clients to read PrimitiveMaps from Compressed or other /// wise encoded streams without this class needing to know about it. /// </summary> /// <param name="source"> /// A <see cref="Stream"/> /// </param> /// <returns> /// A <see cref="PrimitiveMap"/> /// </returns> public static PrimitiveMap Unmarshal(Stream source) { PrimitiveMap answer = new PrimitiveMap(); answer.dictionary = UnmarshalPrimitiveMap(source); return(answer); }
/// <summary> /// Unmarshalls the map from the given data or if the data is null just /// return an empty map /// </summary> public static PrimitiveMap Unmarshal(byte[] data) { PrimitiveMap answer = new PrimitiveMap(); answer.dictionary = UnmarshalPrimitiveMap(data); return(answer); }
public void Decode_WhenControlMessage_ThenTrue() { var primitiveMap = new PrimitiveMap(); primitiveMap[Headers.ControlMessageHeader] = null; var message = Mock.Of<IBytesMessage>(x => x.Properties == primitiveMap); var result = this.testee.Decode(new TransportMessage(), message); Assert.IsTrue(result); }
public void Decode_WhenControlMessageWithContent_ThenAssignBody() { var transportMessage = new TransportMessage { Body = null }; var primitiveMap = new PrimitiveMap(); primitiveMap[Headers.ControlMessageHeader] = null; var bytesMessage = Mock.Of<IBytesMessage>(m => m.Properties == primitiveMap && m.Content == new byte[] { 1 }); this.testee.Decode(transportMessage, bytesMessage); Assert.NotNull(transportMessage.Body); }
protected PrimitiveMap CreatePrimitiveMap() { PrimitiveMap map = new PrimitiveMap(); map["a"] = a; map["b"] = b; map["c"] = c; map["d"] = d; map["e"] = e; map["f"] = f; map["g"] = g; map["h"] = h; map["i"] = i; map["j"] = j; map["k"] = k; map["l"] = l; map["m"] = m; map["n"] = n; return map; }
protected virtual BaseMessage CreateNmsMessage(Message message) { BaseMessage result = null; if ("amqp/map" == message.ContentType) { Dictionary<string, object> dict = new Dictionary<string,object>(); message.GetContent(dict); PrimitiveMap bodyMap = new PrimitiveMap(); SetNmsPrimitiveMap(bodyMap, dict); MapMessage mapMessage = new MapMessage(); mapMessage.Body = bodyMap; result = mapMessage; } else if ("amqp/list" == message.ContentType) { Collection<object> coll = new Collection<object>(); message.GetContent(coll); ObjectMessage objMessage = new ObjectMessage(); objMessage.Body = ConvertAmqpListToObject(coll); result = objMessage; } else { TextMessage textMessage = new TextMessage(); textMessage.Text = message.GetContent(); result = textMessage; } return result; }
public void MapConversion() { IMapMessage message = mocks.StrictMock<IMapMessage>(); IPrimitiveMap primitiveMap = new PrimitiveMap(); IDictionary content = new Hashtable(); content["key1"] = "value1"; content["key2"] = "value2"; Expect.Call(session.CreateMapMessage()).Return(message).Repeat.Once(); Expect.Call(message.Body).Return(primitiveMap).Repeat.Any(); //can't seem to mock indexer... mocks.ReplayAll(); IMessage msg = converter.ToMessage(content, session); Assert.AreEqual(content, converter.FromMessage(msg)); mocks.VerifyAll(); }
public MapMessage(PrimitiveMap body) : base() { this.body = body; this.typeConverter = new PrimitiveMapInterceptor(this, this.body); }
public override void ClearBody() { this.body = null; this.typeConverter = null; base.ClearBody(); }
/// <summary> /// Unmarshals a PrimitiveMap directly from a Stream object. This /// allows for clients to read PrimitiveMaps from Compressed or other /// wise encoded streams without this class needing to know about it. /// </summary> /// <param name="source"> /// A <see cref="Stream"/> /// </param> /// <returns> /// A <see cref="PrimitiveMap"/> /// </returns> public static PrimitiveMap Unmarshal(Stream source) { PrimitiveMap answer = new PrimitiveMap(); answer.dictionary = UnmarshalPrimitiveMap(source); return answer; }
/// <summary> /// Unmarshalls the map from the given data or if the data is null just /// return an empty map /// </summary> public static PrimitiveMap Unmarshal(byte[] data) { PrimitiveMap answer = new PrimitiveMap(); answer.dictionary = UnmarshalPrimitiveMap(data); return answer; }
protected void AssertPrimitiveMap(PrimitiveMap map) { // use generic API to access entries Assert.AreEqual(a, map["a"], "generic map entry: a"); Assert.AreEqual(b, map["b"], "generic map entry: b"); Assert.AreEqual(c, map["c"], "generic map entry: c"); Assert.AreEqual(d, map["d"], "generic map entry: d"); Assert.AreEqual(e, map["e"], "generic map entry: e"); Assert.AreEqual(f, map["f"], "generic map entry: f"); Assert.AreEqual(g, map["g"], "generic map entry: g"); Assert.AreEqual(h, map["h"], "generic map entry: h"); Assert.AreEqual(i, map["i"], "generic map entry: i"); Assert.AreEqual(j, map["j"], "generic map entry: j"); Assert.AreEqual(k, map["k"], "generic map entry: k"); Assert.AreEqual(l, map["l"], "generic map entry: l"); //Assert.AreEqual(m, map["m"], "generic map entry: m"); //Assert.AreEqual(n, map["n"], "generic map entry: n"); // use type safe APIs Assert.AreEqual(a, map.GetBool("a"), "map entry: a"); Assert.AreEqual(b, map.GetByte("b"), "map entry: b"); Assert.AreEqual(c, map.GetChar("c"), "map entry: c"); Assert.AreEqual(d, map.GetShort("d"), "map entry: d"); Assert.AreEqual(e, map.GetInt("e"), "map entry: e"); Assert.AreEqual(f, map.GetLong("f"), "map entry: f"); Assert.AreEqual(g, map.GetString("g"), "map entry: g"); Assert.AreEqual(h, map.GetBool("h"), "map entry: h"); Assert.AreEqual(i, map.GetByte("i"), "map entry: i"); Assert.AreEqual(j, map.GetShort("j"), "map entry: j"); Assert.AreEqual(k, map.GetInt("k"), "map entry: k"); Assert.AreEqual(l, map.GetLong("l"), "map entry: l"); //Assert.AreEqual(m, map.GetList("m"), "map entry: m"); //Assert.AreEqual(n, map.GetDictionary("n"), "map entry: n"); IList list = map.GetList("m"); Assert.AreEqual(2, list.Count, "list size"); Assert.IsTrue(list.Contains("Item1")); Assert.IsTrue(list.Contains("Item2")); IDictionary dictionary = map.GetDictionary("n"); Assert.AreEqual(5, dictionary.Count, "dictionary size"); IDictionary childMap = (IDictionary) dictionary["childMap"]; Assert.IsNotNull(childMap); Assert.AreEqual("childMap", childMap["name"], "childMap[name]"); IList childList = (IList) dictionary["childList"]; Assert.IsNotNull(childList); Assert.IsTrue(childList.Contains("childListElement1")); }