public PrimitiveMapInterceptor(IMessage message, IPrimitiveMap properties, bool readOnly, bool allowByteArrays) { this.message = message; this.properties = properties; this.readOnly = readOnly; this.allowByteArrays = allowByteArrays; }
public static string ToString(IPrimitiveMap map) { if (map == null) { return("{}"); } string result = "{"; bool first = true; foreach (string key in map.Keys) { if (first) { result += "\n"; } first = false; if (map[key] is byte[]) { result += string.Format("key: {0}, len={1}, value: {2};\n", key.ToString(), (map[key] as byte[]).Length, BitConverter.ToString(map[key] as byte[]).Replace("-", " ")); } else { result += "key: " + key.ToString() + ", value: " + map[key].ToString() + ";\n"; } } result += "}"; return(result); }
public Task <INMSProducer> SendAsync(IDestination destination, IPrimitiveMap body) { IMapMessage message = CreateMapMessage(); NmsMessageTransformation.CopyMap(body, message.Body); return(SendAsync(destination, message)); }
public void Serialize(IPrimitiveMap MsgMap) { string commandId = MsgMap["CommandID"].ToString(); switch (commandId) { case "1": AnalysisCertAuthData(MsgMap); break; case "2": AnalysisEBMIndexData(MsgMap); break; case "3": AnalysisEBMConfigureData(MsgMap); break; case "4": AnalysisDailyBroadcastData(MsgMap); break; case "5": AnalysisEBContentData(MsgMap); break; case "6": ChangeInputChannel(MsgMap); break; } }
private void ChangeInputChannel(IPrimitiveMap map) { string packetype = map["PACKETTYPE"].ToString(); OperatorData op = new OperatorData(); op.OperatorType = packetype; JavaScriptSerializer Serializer = new JavaScriptSerializer(); switch (packetype) { case "AddEBContent": case "ModifyEBContent": string dataAdd = map["data"].ToString(); JsonstructureDeal(ref dataAdd); List <EBMID_Content> listEBContent_ = Serializer.Deserialize <List <EBMID_Content> >(dataAdd); op.Data = (object)listEBContent_; break; case "DelDailyBroadcast": string ItemList = map["ItemIDList"].ToString(); op.Data = ItemList; break; } DataDealHelper.MyEvent(op); }
public void TestConvertProperties() { ActiveMQMessage msg = new ActiveMQMessage(); msg.Properties["stringProperty"] = "string"; msg.Properties["byteProperty"] = (Byte)1; msg.Properties["shortProperty"] = (Int16)1; msg.Properties["intProperty"] = (Int32)1; msg.Properties["longProperty"] = (Int64)1; msg.Properties["floatProperty"] = (Single)1.1f; msg.Properties["doubleProperty"] = (Double)1.1; msg.Properties["booleanProperty"] = (Boolean)true; msg.Properties["nullProperty"] = null; msg.BeforeMarshall(new OpenWireFormat()); IPrimitiveMap properties = msg.Properties; Assert.AreEqual(properties["stringProperty"], "string"); Assert.AreEqual((byte)properties["byteProperty"], (byte)1); Assert.AreEqual((short)properties["shortProperty"], (short)1); Assert.AreEqual((int)properties["intProperty"], (int)1); Assert.AreEqual((long)properties["longProperty"], (long)1); Assert.AreEqual((float)properties["floatProperty"], 1.1f, 0); Assert.AreEqual((double)properties["doubleProperty"], 1.1, 0); Assert.AreEqual((bool)properties["booleanProperty"], true); Assert.IsNull(properties["nullProperty"]); }
public void ReceiveLoggingTest() { ITextMessage mockTextMessage = mocks.NewMock <ITextMessage>(); IPrimitiveMap mockTextMessageProperties = mocks.NewMock <IPrimitiveMap>(); string receivedMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?><MethodInvocation><MethodName>TestMethod</MethodName><Parameters><Parameter><DataType>string</DataType><Data>abc</Data></Parameter><Parameter><DataType>integer</DataType><Data>123</Data></Parameter><Parameter /><Parameter><DataType>double</DataType><Data>4.5678899999999999e+002</Data></Parameter></Parameters><ReturnType /></MethodInvocation>"; string smallMessage = "<TestMessage>Test message content</TestMessage>"; using (mocks.Ordered) { // Expects for Connect() Expect.AtLeastOnce.On(mockConnection); Expect.Once.On(mockApplicationLogger); // Expects for first Receive() Expect.Once.On(mockConsumer).Method("Receive").WithAnyArguments().Will(Return.Value(mockTextMessage)); Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties)); Expect.Once.On(mockTextMessageProperties).Method("GetString").With("Text").Will(Return.Value(receivedMessage)); Expect.Once.On(mockApplicationLogger).Method("Log").With(testActiveMqRemoteReceiver, LogLevel.Information, "Received message '<?xml version=\"1.0\" encoding=\"utf-8\"?><MethodInvocation><MethodName>TestMethod</MethodName><Parameters><Parameter><DataT' (truncated)."); Expect.Once.On(mockApplicationLogger).Method("Log").With(testActiveMqRemoteReceiver, LogLevel.Debug, "Complete message content: '" + receivedMessage + "'."); // Expects for second Receive() Expect.Once.On(mockConsumer).Method("Receive").WithAnyArguments().Will(Return.Value(mockTextMessage)); Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties)); Expect.Once.On(mockTextMessageProperties).Method("GetString").With("Text").Will(Return.Value(smallMessage)); Expect.Once.On(mockApplicationLogger).Method("Log").With(testActiveMqRemoteReceiver, LogLevel.Information, "Received message '" + smallMessage + "'."); Expect.Once.On(mockApplicationLogger).Method("Log").With(testActiveMqRemoteReceiver, LogLevel.Debug, "Complete message content: '" + smallMessage + "'."); } testActiveMqRemoteReceiver.Connect(); testActiveMqRemoteReceiver.Receive(); testActiveMqRemoteReceiver.Receive(); mocks.VerifyAllExpectationsHaveBeenMet(); }
protected virtual void WriteMessage(ActiveMQMessage command, StompFrameStream ss) { ss.WriteCommand(command, "SEND"); ss.WriteHeader("destination", StompHelper.ToStomp(command.Destination)); if (command.ReplyTo != null) { ss.WriteHeader("reply-to", StompHelper.ToStomp(command.ReplyTo)); } if (command.CorrelationId != null) { ss.WriteHeader("correlation-id", command.CorrelationId); } if (command.Expiration != 0) { ss.WriteHeader("expires", command.Expiration); } if (command.Priority != 4) { ss.WriteHeader("priority", command.Priority); } if (command.Type != null) { ss.WriteHeader("type", command.Type); } if (command.TransactionId != null) { ss.WriteHeader("transaction", StompHelper.ToStomp(command.TransactionId)); } ss.WriteHeader("persistent", command.Persistent); // lets force the content to be marshalled command.BeforeMarshall(null); if (command is ActiveMQTextMessage) { ActiveMQTextMessage textMessage = command as ActiveMQTextMessage; ss.Content = encoding.GetBytes(textMessage.Text); } else { ss.Content = command.Content; if (null != command.Content) { ss.ContentLength = command.Content.Length; } else { ss.ContentLength = 0; } } IPrimitiveMap map = command.Properties; foreach (string key in map.Keys) { ss.WriteHeader(key, map[key]); } ss.Flush(); }
public static Amqp.Types.Map NMSMapToAmqp(IPrimitiveMap nmsmap) { if (nmsmap == null) { return(null); } Amqp.Types.Map result = new Amqp.Types.Map(); if (nmsmap is Map.AMQP.AMQPValueMap) { return((nmsmap as Map.AMQP.AMQPValueMap).AmqpMap); } else { foreach (string key in nmsmap.Keys) { object value = nmsmap[key]; if (value is IDictionary) { value = ConversionSupport.MapToAmqp(value as IDictionary); } else if (value is IList) { value = ConversionSupport.ListToAmqp(value as IList); } result[key] = value; //Tracer.InfoFormat("Conversion key : {0}, value : {1}, valueType: {2} nmsValue: {3}, nmsValueType: {4}.", // key, value, value.GetType().Name, ); } } return(result); }
public INMSProducer Send(IDestination destination, IPrimitiveMap body) { IMapMessage message = CreateMapMessage(); ActiveMQMessageTransformation.CopyMap(body, message.Body); return(Send(destination, message)); }
public void SendException() { ITextMessage mockTextMessage = mocks.NewMock <ITextMessage>(); IPrimitiveMap mockTextMessageProperties = mocks.NewMock <IPrimitiveMap>(); const string testMessage = "<TestMessage>Test message content</TestMessage>"; using (mocks.Ordered) { SetConnectExpectations(); Expect.Once.On(mockSession).Method("CreateTextMessage").With(testMessage).Will(Return.Value(mockTextMessage)); Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties)); Expect.Once.On(mockTextMessageProperties).Method("SetString").With(new object[2] { filterIdentifier, messageFilter }); Expect.Once.On(mockProducer).Method("Send").With(mockTextMessage).Will(Throw.Exception(new Exception("Mock Send Failure"))); } testActiveMqRemoteSender.Connect(); Exception e = Assert.Throws <Exception>(delegate { testActiveMqRemoteSender.Send(testMessage); }); mocks.VerifyAllExpectationsHaveBeenMet(); Assert.That(e.Message, NUnit.Framework.Is.StringStarting("Error sending message.")); }
private static void CopyMap(IPrimitiveMap source, IPrimitiveMap target) { foreach (object key in source.Keys) { string name = key.ToString(); object value = source[name]; switch (value) { case bool boolValue: target.SetBool(name, boolValue); break; case char charValue: target.SetChar(name, charValue); break; case string stringValue: target.SetString(name, stringValue); break; case byte byteValue: target.SetByte(name, byteValue); break; case short shortValue: target.SetShort(name, shortValue); break; case int intValue: target.SetInt(name, intValue); break; case long longValue: target.SetLong(name, longValue); break; case float floatValue: target.SetFloat(name, floatValue); break; case double doubleValue: target.SetDouble(name, doubleValue); break; case byte[] bytesValue: target.SetBytes(name, bytesValue); break; case IList listValue: target.SetList(name, listValue); break; case IDictionary dictionaryValue: target.SetDictionary(name, dictionaryValue); break; } } }
public static void AddProperties(this IPrimitiveMap primitiveMap, IEnumerable <KeyValuePair <string, object> > properties) { foreach (var keyValuePair in properties) { var str = keyValuePair.Value as string; if (str != null) { primitiveMap.SetString(keyValuePair.Key, str); continue; } if (keyValuePair.Value is int) { primitiveMap.SetInt(keyValuePair.Key, (int)keyValuePair.Value); } else if (keyValuePair.Value is long) { primitiveMap.SetLong(keyValuePair.Key, (long)keyValuePair.Value); } else if (keyValuePair.Value is bool) { primitiveMap.SetBool(keyValuePair.Key, (bool)keyValuePair.Value); } else if (keyValuePair.Value is double) { primitiveMap.SetDouble(keyValuePair.Key, (double)keyValuePair.Value); } else if (keyValuePair.Value is short) { primitiveMap.SetShort(keyValuePair.Key, (short)keyValuePair.Value); } else if (keyValuePair.Value is float) { primitiveMap.SetFloat(keyValuePair.Key, (float)keyValuePair.Value); } else if (keyValuePair.Value is char) { primitiveMap.SetChar(keyValuePair.Key, (char)keyValuePair.Value); } else if (keyValuePair.Value is byte) { primitiveMap.SetByte(keyValuePair.Key, (byte)keyValuePair.Value); } else if (keyValuePair.Value is byte[]) { primitiveMap.SetBytes(keyValuePair.Key, (byte[])keyValuePair.Value); } else if (keyValuePair.Value is IDictionary) { primitiveMap.SetDictionary(keyValuePair.Key, (IDictionary)keyValuePair.Value); } else if (keyValuePair.Value is IList) { primitiveMap.SetList(keyValuePair.Key, (IList)keyValuePair.Value); } } }
// public void SetNmsPrimitiveMap(IPrimitiveMap map, Dictionary <string, object> dict) { // TODO: lock? map.Clear(); foreach (System.Collections.Generic.KeyValuePair <string, object> kvp in dict) { map[kvp.Key] = kvp.Value; } }
public void TestGetStringThrows(IPrimitiveMap map, string name, string message) { try { map.GetString(name); Assert.Fail(message); } catch (NMSException) { } }
// public Dictionary <string, object> FromNmsPrimitiveMap(IPrimitiveMap pm) { Dictionary <string, object> dict = new Dictionary <string, object>(); // TODO: lock? ICollection keys = pm.Keys; foreach (object key in keys) { dict.Add(key.ToString(), pm[key.ToString()]); } return(dict); }
public void TestConvertProperties() { TextMessage msg = new TextMessage(); // Set/verify a property using each supported AMQP data type msg.Properties["stringProperty"] = "string"; msg.Properties["booleanProperty"] = (Boolean)true; msg.Properties["charProperty"] = (Char)'h'; msg.Properties["shortProperty"] = (Int16)2; msg.Properties["intProperty"] = (Int32)3; msg.Properties["longProperty"] = (Int64)4; msg.Properties["byteProperty"] = (Byte)5; msg.Properties["ushortProperty"] = (UInt16)6; msg.Properties["uintProperty"] = (UInt32)7; msg.Properties["ulongProperty"] = (UInt64)8; msg.Properties["floatProperty"] = (Single)9.9f; msg.Properties["doubleProperty"] = (Double)10.1; msg.Properties["nullProperty"] = null; msg.Properties["guidProperty"] = new Guid("000102030405060708090a0b0c0d0e0f"); IPrimitiveMap properties = msg.Properties; Assert.AreEqual(properties["stringProperty"], "string"); Assert.AreEqual(properties["booleanProperty"], true); Assert.AreEqual((Char)properties["charProperty"], (Char)'h'); Assert.AreEqual(properties["shortProperty"], (short)2); Assert.AreEqual(properties["intProperty"], (int)3); Assert.AreEqual(properties["longProperty"], (long)4); Assert.AreEqual(properties["byteProperty"], (byte)5); Assert.AreEqual(properties["ushortProperty"], (UInt16)6); Assert.AreEqual(properties["uintProperty"], (int)7); Assert.AreEqual(properties["ulongProperty"], (long)8); Assert.AreEqual(properties["floatProperty"], 9.9f); Assert.AreEqual(properties["doubleProperty"], 10.1); Assert.IsNull(properties["nullProperty"]); Guid rxGuid = (Guid)properties["guidProperty"]; Assert.AreEqual(rxGuid.ToString(), "00010203-0405-0607-0809-0a0b0c0d0e0f"); }
public void GetStats() { // Crear consumidor try { // Creo una cola y consumidor IDestination queueReplyTo = session.CreateTemporaryQueue(); IMessageConsumer consumer = session.CreateConsumer(queueReplyTo); // Crear cola monitorizada string listeningQueue = "TEST1"; ActiveMQQueue testQueue = session.GetQueue(listeningQueue); // Crear cola y productor ActiveMQQueue query = session.GetQueue("ActiveMQ.Statistics.Destination.TEST1"); IMessageProducer producer = session.CreateProducer(null); // Mandar mensaje vacío y replicar IMessage msg = session.CreateMessage(); producer.Send(testQueue, msg); msg.NMSReplyTo = queueReplyTo; producer.Send(query, msg); // Recibir IMapMessage reply = (IMapMessage)consumer.Receive(); if (reply != null) { IPrimitiveMap statsMap = reply.Body; foreach (string statKey in statsMap.Keys) { Console.WriteLine("{0} = {1}", statKey, statsMap[statKey]); } } } catch (Exception e) { var t = e.Message + " " + e.StackTrace; } }
protected override void CopyInto(IMessageCloak msg) { base.CopyInto(msg); IPrimitiveMap copy = (msg as IMapMessageCloak).Map; foreach (string key in this.map.Keys) { object value = map[key]; if (value != null) { Type valType = value.GetType(); if (valType.IsPrimitive) { // value copy primitive value copy[key] = value; } else if (valType.IsArray && valType.Equals(typeof(byte[]))) { // use IPrimitive map SetBytes for most common implementation this is a deep copy. byte[] original = value as byte[]; copy.SetBytes(key, original); } else if (valType.Equals(typeof(IDictionary)) || valType.Equals(typeof(Amqp.Types.Map))) { // reference copy copy.SetDictionary(key, value as IDictionary); } else if (valType.Equals(typeof(IList)) || valType.Equals(typeof(Amqp.Types.List))) { // reference copy copy.SetList(key, value as IList); } else { copy[key] = value; } } else { copy[key] = value; } } }
protected NMSPropertyInterceptor(T instance, IPrimitiveMap properties, IDictionary <string, Interceptor> interceptors) : base() { this.properties = properties ?? new Apache.NMS.Util.PrimitiveMap(); this.instance = instance; if (this.properties is Types.Map.PrimitiveMapBase) { SyncLock = (this.properties as Types.Map.PrimitiveMapBase).SyncRoot; } else { SyncLock = new object(); } this.interceptors = new Dictionary <string, Interceptor>(); foreach (string key in interceptors.Keys) { AddInterceptor(key, interceptors[key]); } }
public void ReceiveSuccessTests() { ITextMessage mockTextMessage = mocks.NewMock <ITextMessage>(); IPrimitiveMap mockTextMessageProperties = mocks.NewMock <IPrimitiveMap>(); const string testMessage = "<TestMessage>Test message content</TestMessage>"; using (mocks.Ordered) { SetConnectExpectations(); Expect.Once.On(mockConsumer).Method("Receive").WithAnyArguments().Will(Return.Value(mockTextMessage)); Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties)); Expect.Once.On(mockTextMessageProperties).Method("GetString").With("Text").Will(Return.Value(testMessage)); } testActiveMqRemoteReceiver.Connect(); string receivedMessage = testActiveMqRemoteReceiver.Receive(); Assert.AreEqual(testMessage, receivedMessage); mocks.VerifyAllExpectationsHaveBeenMet(); }
public void SendSuccessTest() { ITextMessage mockTextMessage = mocks.NewMock <ITextMessage>(); IPrimitiveMap mockTextMessageProperties = mocks.NewMock <IPrimitiveMap>(); const string testMessage = "<TestMessage>Test message content</TestMessage>"; using (mocks.Ordered) { SetConnectExpectations(); Expect.Once.On(mockSession).Method("CreateTextMessage").With(testMessage).Will(Return.Value(mockTextMessage)); Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties)); Expect.Once.On(mockTextMessageProperties).Method("SetString").With(new object[2] { filterIdentifier, messageFilter }); Expect.Once.On(mockProducer).Method("Send").With(mockTextMessage); } testActiveMqRemoteSender.Connect(); testActiveMqRemoteSender.Send(testMessage); mocks.VerifyAllExpectationsHaveBeenMet(); }
public static string ToString(IPrimitiveMap map) { if (map == null) { return("{}"); } string result = "{"; bool first = true; foreach (string key in map.Keys) { if (first) { result += "\n"; } first = false; result += "key: " + key.ToString() + ", value: " + map[key].ToString() + ";\n"; } result += "}"; return(result); }
public void TestUnmarshalPrimitiveMap() { XmlPrimitiveMapMarshaler marshaler = new XmlPrimitiveMapMarshaler(); byte[] rawBytes = Encoding.UTF8.GetBytes(xmlString); IPrimitiveMap result = marshaler.Unmarshal(rawBytes); Assert.IsNotNull(result); Assert.IsTrue(result.Contains("BOOL")); Assert.IsTrue(result.Contains("BYTES")); Assert.IsTrue(result.Contains("STRING")); Assert.IsTrue(result.Contains("LONG")); Assert.IsTrue(result.Contains("FLOAT")); Assert.IsTrue(result.Contains("INT")); Assert.IsTrue(result.Contains("BYTE")); Assert.IsTrue(result.Contains("SHORT")); Assert.IsTrue(result.Contains("DOUBLE")); Assert.IsTrue(result.Contains("CHAR")); }
public byte[] Marshal(IPrimitiveMap map) { if (map == null) { return(null); } StringBuilder builder = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; settings.Encoding = this.encoder; settings.NewLineHandling = NewLineHandling.None; XmlWriter writer = XmlWriter.Create(builder, settings); writer.WriteStartElement("map"); foreach (String entry in map.Keys) { writer.WriteStartElement("entry"); // Encode the Key <string>key</string> writer.WriteElementString("string", entry); Object value = map[entry]; // Encode the Value <${type}>value</${type}> MarshalPrimitive(writer, value); writer.WriteEndElement(); } writer.WriteEndElement(); writer.Close(); return(this.encoder.GetBytes(builder.ToString())); }
public void ReceiveMetricsTest() { ITextMessage mockTextMessage = mocks.NewMock <ITextMessage>(); IPrimitiveMap mockTextMessageProperties = mocks.NewMock <IPrimitiveMap>(); string receivedMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?><MethodInvocation><MethodName>TestMethod</MethodName><Parameters><Parameter><DataType>string</DataType><Data>abc</Data></Parameter><Parameter><DataType>integer</DataType><Data>123</Data></Parameter><Parameter /><Parameter><DataType>double</DataType><Data>4.5678899999999999e+002</Data></Parameter></Parameters><ReturnType /></MethodInvocation>"; using (mocks.Ordered) { // Expects for Connect() Expect.AtLeastOnce.On(mockConnection); // Expects for first Receive() Expect.Once.On(mockConsumer).Method("Receive").WithAnyArguments().Will(Return.Value(mockTextMessage)); Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties)); Expect.Once.On(mockTextMessageProperties).Method("GetString").With("Text").Will(Return.Value(receivedMessage)); Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived())); Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(381))); } testActiveMqRemoteReceiver.Connect(); testActiveMqRemoteReceiver.Receive(); mocks.VerifyAllExpectationsHaveBeenMet(); }
public void SendLoggingTest() { ITextMessage mockTextMessage = mocks.NewMock <ITextMessage>(); IPrimitiveMap mockTextMessageProperties = mocks.NewMock <IPrimitiveMap>(); Expect.AtLeastOnce.On(mockConnection); Expect.AtLeastOnce.On(mockProducer); Expect.Once.On(mockSession).Method("CreateTextMessage").Will(Return.Value(mockTextMessage)); Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties)); Expect.Once.On(mockTextMessageProperties).Method("SetString").With(new object[2] { filterIdentifier, messageFilter }); using (mocks.Ordered) { Expect.Once.On(mockApplicationLogger); Expect.Once.On(mockApplicationLogger).Method("Log").With(testActiveMqRemoteSender, LogLevel.Information, "Message sent."); } testActiveMqRemoteSender.Connect(); testActiveMqRemoteSender.Send("<TestMessage>Test message content</TestMessage>"); mocks.VerifyAllExpectationsHaveBeenMet(); }
private void InitializeMapBody() { if (message.BodySection == null) { amqpmap = new Map(); map = new AMQPValueMap(amqpmap); AmqpValue val = new AmqpValue(); val.Value = amqpmap; message.BodySection = val; } else { if (message.BodySection is AmqpValue) { object obj = (message.BodySection as AmqpValue).Value; if (obj == null) { amqpmap = new Map(); map = new AMQPValueMap(amqpmap); (message.BodySection as AmqpValue).Value = amqpmap; } else if (obj is Map) { amqpmap = obj as Map; map = new AMQPValueMap(amqpmap); } else { throw new NMSException(string.Format("Invalid message body value type. Type: {0}.", obj.GetType().Name)); } } else { throw new NMSException("Invalid message body type."); } } }
public void SendExceptionMetricsTest() { ITextMessage mockTextMessage = mocks.NewMock <ITextMessage>(); IPrimitiveMap mockTextMessageProperties = mocks.NewMock <IPrimitiveMap>(); Expect.AtLeastOnce.On(mockConnection); Expect.Once.On(mockProducer).Method("Send").WithAnyArguments().Will(Throw.Exception(new Exception("Mock Send Failure"))); Expect.Once.On(mockSession).Method("CreateTextMessage").Will(Return.Value(mockTextMessage)); Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties)); Expect.Once.On(mockTextMessageProperties).Method("SetString").With(new object[2] { filterIdentifier, messageFilter }); using (mocks.Ordered) { Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageSendTime())); Expect.Once.On(mockMetricLogger).Method("CancelBegin").With(IsMetric.Equal(new MessageSendTime())); } Exception e = Assert.Throws <Exception>(delegate { testActiveMqRemoteSender.Connect(); testActiveMqRemoteSender.Send("<TestMessage>Test message content</TestMessage>"); }); }
public void SendMetricsTest() { ITextMessage mockTextMessage = mocks.NewMock <ITextMessage>(); IPrimitiveMap mockTextMessageProperties = mocks.NewMock <IPrimitiveMap>(); Expect.AtLeastOnce.On(mockConnection); Expect.AtLeastOnce.On(mockProducer); Expect.Once.On(mockSession).Method("CreateTextMessage").Will(Return.Value(mockTextMessage)); Expect.Once.On(mockTextMessage).GetProperty("Properties").Will(Return.Value(mockTextMessageProperties)); Expect.Once.On(mockTextMessageProperties).Method("SetString").With(new object[2] { filterIdentifier, messageFilter }); using (mocks.Ordered) { Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageSendTime())); Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageSendTime())); Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageSent())); } testActiveMqRemoteSender.Connect(); testActiveMqRemoteSender.Send("<TestMessage>Test message content</TestMessage>"); mocks.VerifyAllExpectationsHaveBeenMet(); }
// public Dictionary<string, object> FromNmsPrimitiveMap(IPrimitiveMap pm) { Dictionary<string, object> dict = new Dictionary<string,object>(); // TODO: lock? ICollection keys = pm.Keys; foreach (object key in keys) { dict.Add(key.ToString(), pm[key.ToString()]); } return dict; }
// public void SetNmsPrimitiveMap(IPrimitiveMap map, Dictionary<string, object> dict) { // TODO: lock? map.Clear(); foreach (System.Collections.Generic.KeyValuePair <string, object> kvp in dict) { map[kvp.Key] = kvp.Value; } }
public PrimitiveMapInterceptor(IMessage message, IPrimitiveMap properties, bool readOnly) { this.message = message; this.properties = properties; this.readOnly = readOnly; }
public PrimitiveMapInterceptor(IMessage message, IPrimitiveMap properties) { this.message = message; this.properties = properties; }
public MessagePropertyIntercepter(IMessage message, IPrimitiveMap properties, bool readOnly) : base(message, properties, readOnly) { this.messageType = message.GetType(); }