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.")); }
public void ConnectLoggingTest() { Expect.AtLeastOnce.On(mockConnection); Expect.Once.On(mockApplicationLogger).Method("Log").With(testActiveMqRemoteSender, LogLevel.Information, "Connected to URI: '" + connectUriName + "', Queue: '" + queueName + "'."); testActiveMqRemoteSender.Connect(); mocks.VerifyAllExpectationsHaveBeenMet(); }
//------------------------------------------------------------------------------ // // Method: Connect // //------------------------------------------------------------------------------ /// <summary> /// Connects and initialises the underlying MethodInvocationRemoting and ActiveMQ components. /// </summary> public void Connect() { outgoingSender.Connect(); outgoingReceiver.Connect(); incomingSender.Connect(); incomingReceiver.Connect(); methodInvocationReceiver.Receive(); }
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 void ConnectException() { Expect.Once.On(mockConnection).Method("Start").Will(Throw.Exception(new Exception("Mock Connection Failure"))); Exception e = Assert.Throws <Exception>(delegate { testActiveMqRemoteSender.Connect(); }); mocks.VerifyAllExpectationsHaveBeenMet(); Assert.That(e.Message, NUnit.Framework.Is.StringStarting("Error connecting to message queue.")); }
static void Main(string[] args) { // Setup connection parameters for ActiveMQ const string connectUri = "activemq:tcp://localhost:61616?wireFormat.maxInactivityDuration=0"; const string queueName = "FromJava"; const string requestQueueFilter = "Request"; const string responseQueueFilter = "Response"; const int receiverConnectLoopTimeout = 200; // Setup method invocation receiver ActiveMqRemoteSender activeMqSender = new ActiveMqRemoteSender(connectUri, queueName, responseQueueFilter); ActiveMqRemoteReceiver activeMqReceiver = new ActiveMqRemoteReceiver(connectUri, queueName, requestQueueFilter, receiverConnectLoopTimeout); MethodInvocationSerializer methodSerializer = new MethodInvocationSerializer(new SerializerOperationMap()); MethodInvocationRemoteReceiver methodInvocationReceiver = new MethodInvocationRemoteReceiver(methodSerializer, activeMqSender, activeMqReceiver); methodInvocationReceiver.MethodInvocationReceived += new MethodInvocationReceivedEventHandler(ReceiveMethodInvocation); try { // Connect to ActiveMQ activeMqSender.Connect(); activeMqReceiver.Connect(); // Start receiving method invocations methodInvocationReceiver.Receive(); Console.WriteLine("Waiting for incoming method calls..."); Console.WriteLine("Press [ENTER] to cancel."); Console.ReadLine(); } catch (Exception e) { Console.WriteLine("An exception occurred"); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } finally { // Stop receiving, disconnect, and dispose methodInvocationReceiver.CancelReceive(); activeMqReceiver.CancelReceive(); activeMqReceiver.Disconnect(); activeMqSender.Disconnect(); activeMqReceiver.Dispose(); activeMqSender.Dispose(); } }