public void ReceiveAvailableDataExceptionMetricsTest()
        {
            // Tests where a socket exception occurs whilst checking the underlying client for available data, afterwhich the class reconnects and receives a message
            //   Ensures the correct order of metric logging in this case, especially that a corresponding End() is called for each Begin()

            using (mocks.Ordered)
            {
                SetConnectExpectations();
                // Set expectations for socket exception when checking available data
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Throw.Exception(new System.Net.Sockets.SocketException(1)));
                SetReconnectExpectations();
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new TcpRemoteReceiverReconnected()));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockNetworkStream).Method("Read").With(new byte[testMessageByteArray.Length], 0, testMessageByteArray.Length).Will(new SetNamedParameterAction("buffer", testMessageByteArray), Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte").With((byte)6);
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(16)));
            }

            testTcpRemoteReceiver.Connect();
            testTcpRemoteReceiver.Receive();
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void ReceiveReconnectRereceieveExceptionMetricsTest()
        {
            // Tests that if an exception occurs when receiving and causes a reconnect, a subsequent failure to receive will call method CancelBegin() when handling the exception

            byte[] shortMessageByteArray = new byte[1];
            Array.Copy(testMessageByteArray, 0, shortMessageByteArray, 0, 1);

            using (mocks.Ordered)
            {
                SetConnectExpectations();
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Throw.Exception(new System.IO.IOException("Mock IOException.")));
                SetReconnectExpectations();
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new TcpRemoteReceiverReconnected()));
                Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockNetworkStream).Method("Read").With(new byte[testMessageByteArray.Length], 0, testMessageByteArray.Length).Will(Throw.Exception(new AccessViolationException("Mock AccessViolationException.")));
                Expect.Once.On(mockMetricLogger).Method("CancelBegin").With(IsMetric.Equal(new MessageReceiveTime()));
            }

            Exception e = Assert.Throws <Exception>(delegate
            {
                testTcpRemoteReceiver.Connect();
                testTcpRemoteReceiver.Receive();
            });

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void ReceiveAfterNoDataAvailableMetricsTest()
        {
            // Tests where the loop in the Receive() method iterates through once with no data being available before the message is received

            using (mocks.Ordered)
            {
                SetConnectExpectations();
                // Expects for Receive() where no data is available
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(0));
                // Expects for Receive() where data is available
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockNetworkStream).Method("Read").Will(new SetNamedParameterAction("buffer", testMessageByteArray), Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte");
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(16)));
            }

            testTcpRemoteReceiver.Connect();
            testTcpRemoteReceiver.Receive();
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void ReceiveReconnectExceptionMetricsTest()
        {
            // Tests that if an exception occurs when receiving, subsequent failure to reconnect will call method CancelBegin() when handling the exception

            using (mocks.Ordered)
            {
                SetConnectExpectations();
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Throw.Exception(new System.IO.IOException("Mock IOException.")));
                // Below expects simulate throwing an unhandled exception when attempting to reconnect
                Expect.Once.On(mockTcpListener).GetProperty("Active").Will(Return.Value(true));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(true));
                Expect.Once.On(mockTcpClient).Method("Close").WithNoArguments();
                Expect.Once.On(mockTcpClient).Method("Dispose").WithNoArguments();
                Expect.Once.On(mockTcpListener).Method("AcceptTcpClient").Will(Throw.Exception(new AccessViolationException("Mock AccessViolationException.")));
                Expect.Once.On(mockMetricLogger).Method("CancelBegin").With(IsMetric.Equal(new MessageReceiveTime()));
            }

            Exception e = Assert.Throws <Exception>(delegate
            {
                testTcpRemoteReceiver.Connect();
                testTcpRemoteReceiver.Receive();
            });

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 5
0
        public void SendReconnectMetricsTest()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageSendTime()));
                Expect.Once.On(mockTcpClient).GetProperty("Connected").Will(Return.Value(true));
                Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
                Expect.Once.On(mockNetworkStream).Method("Write").WithAnyArguments().Will(Throw.Exception(new System.IO.IOException("Mock IOException")));
                Expect.Once.On(mockTcpClient).GetProperty("Connected").Will(Return.Value(false));
                // Expectations for attempt to reconnect
                Expect.Once.On(mockTcpClient).Method("Close").WithAnyArguments();
                Expect.Once.On(mockTcpClient).Method("Connect").WithAnyArguments();
                Expect.Once.On(mockTcpClient).GetProperty("Connected").Will(Return.Value(true));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new TcpRemoteSenderReconnected()));
                // Expectations for resend
                Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
                Expect.Once.On(mockNetworkStream).Method("Write");
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(1));
                Expect.Once.On(mockNetworkStream).Method("ReadByte").WithNoArguments().Will(Return.Value(6));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageSendTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageSent()));
            }

            testTcpRemoteSender.Send("<TestMessage>Test message content</TestMessage>");
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 6
0
        public void SendReconnectResendExceptionMetricsTest()
        {
            // Tests that if an exception occurs when sending and causes a reconnect, a subsequent failure to send will call method CancelBegin() when handling the exception

            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageSendTime()));
                Expect.Once.On(mockTcpClient).GetProperty("Connected").Will(Return.Value(true));
                Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
                Expect.Once.On(mockNetworkStream).Method("Write").WithAnyArguments().Will(Throw.Exception(new System.IO.IOException("Mock IOException")));
                Expect.Once.On(mockTcpClient).GetProperty("Connected").Will(Return.Value(false));
                // Expectations for attempt to reconnect
                Expect.Once.On(mockTcpClient).Method("Close").WithAnyArguments();
                Expect.Once.On(mockTcpClient).Method("Connect").WithAnyArguments();
                Expect.Once.On(mockTcpClient).GetProperty("Connected").Will(Return.Value(true));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new TcpRemoteSenderReconnected()));
                // Expectations for resend
                Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
                Expect.Once.On(mockNetworkStream).Method("Write").WithAnyArguments().Will(Throw.Exception(new System.IO.IOException("Mock IOException")));
                Expect.Once.On(mockMetricLogger).Method("CancelBegin").With(IsMetric.Equal(new MessageSendTime()));
            }

            Exception e = Assert.Throws <Exception>(delegate
            {
                testTcpRemoteSender.Send("<TestMessage>Test message content</TestMessage>");
            });

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
 //******************************************************************************
 //
 // Method: SetBeginMessageReceiveExpectations
 //
 //******************************************************************************
 /// <summary>
 /// Sets mock expectations for the start of the Receive() method.
 /// </summary>
 /// <param name="receiveMessageSize">The number of bytes in the received message.</param>
 private void SetBeginMessageReceiveExpectations(int receiveMessageSize)
 {
     Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
     Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(receiveMessageSize));
     Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageReceiveTime()));
     Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
     Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
     Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(receiveMessageSize));
 }
Ejemplo n.º 8
0
        public void SendVoidReturnValueExceptionMetricsTest()
        {
            Expect.Once.On(mockMethodInvocationSerializer).GetProperty("VoidReturnValue").Will(Return.Value(testVoidReturnValue));
            Expect.AtLeastOnce.On(mockRemoteSender).Method("Send").WithAnyArguments().Will(Throw.Exception(new Exception("Mock Send Failure")));
            Expect.Once.On(mockMetricLogger).Method("CancelBegin").With(IsMetric.Equal(new RemoteMethodReceiveTime()));

            Exception e = Assert.Throws <Exception>(delegate
            {
                testMethodInvocationRemoteReceiver.SendVoidReturn();
            });
        }
Ejemplo n.º 9
0
        public void SendVoidReturnValueMetricsTest()
        {
            Expect.Once.On(mockMethodInvocationSerializer).GetProperty("VoidReturnValue").Will(Return.Value(testVoidReturnValue));
            Expect.AtLeastOnce.On(mockRemoteSender);
            Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new RemoteMethodReceiveTime()));
            Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new RemoteMethodReceived()));

            testMethodInvocationRemoteReceiver.SendVoidReturn();

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void ReceiveDuplicateSequenceNumberMetricsTest()
        {
            // Tests that a message received with the same sequence number as the previous message is ignored
            //   Ensures the correct order of metric logging in this case, especially that a corresponding End() is called for each Begin()

            byte[] secondMessageByteArray = new byte[testMessageByteArray.Length];
            Array.Copy(testMessageByteArray, secondMessageByteArray, testMessageByteArray.Length);
            // Update the sequence number in the second message
            byte[] updatedSequenceNumber = BitConverter.GetBytes(124);
            if (BitConverter.IsLittleEndian == false)
            {
                Array.Reverse(updatedSequenceNumber);
            }
            Array.Copy(updatedSequenceNumber, 0, secondMessageByteArray, 1, updatedSequenceNumber.Length);
            // Update the body of the second message to be <Data>XYZ</Data>
            secondMessageByteArray[19] = 0x58;
            secondMessageByteArray[20] = 0x59;
            secondMessageByteArray[21] = 0x5A;

            using (mocks.Ordered)
            {
                SetConnectExpectations();
                // Set expectations for receiving first message
                SetBeginMessageReceiveExpectations(testMessageByteArray.Length);
                Expect.Once.On(mockNetworkStream).Method("Read").With(new byte[testMessageByteArray.Length], 0, testMessageByteArray.Length).Will(new SetNamedParameterAction("buffer", testMessageByteArray), Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte").With((byte)6);
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(16)));
                // Set expectations for receiving duplicate message
                SetBeginMessageReceiveExpectations(testMessageByteArray.Length);
                Expect.Once.On(mockNetworkStream).Method("Read").With(new byte[testMessageByteArray.Length], 0, testMessageByteArray.Length).Will(new SetNamedParameterAction("buffer", testMessageByteArray), Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte").With((byte)6);
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new TcpRemoteReceiverDuplicateSequenceNumber()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                // Set expectations for receiving next message
                SetBeginMessageReceiveExpectations(secondMessageByteArray.Length);
                Expect.Once.On(mockNetworkStream).Method("Read").With(new byte[secondMessageByteArray.Length], 0, secondMessageByteArray.Length).Will(new SetNamedParameterAction("buffer", secondMessageByteArray), Return.Value(secondMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").WithNoArguments().Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte").With((byte)6);
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(16)));
            }

            testTcpRemoteReceiver.Connect();
            testTcpRemoteReceiver.Receive();
            testTcpRemoteReceiver.Receive();
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 11
0
        public void InvokeMethodVoidMethodInvocationExceptionMetricsTest()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new RemoteMethodSendTime()));
                Expect.Once.On(mockMetricLogger).Method("CancelBegin").With(IsMetric.Equal(new RemoteMethodSendTime()));
            }

            ArgumentException e = Assert.Throws <ArgumentException>(delegate
            {
                testMethodInvocationRemoteSender.InvokeMethod(new MethodInvocation("TestMethod"));
            });
        }
        public void DeserializeReturnValueExceptionMetricsTest()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new ReturnValueDeserializeTime()));
                Expect.Once.On(mockMetricLogger).Method("CancelBegin").With(IsMetric.Equal(new ReturnValueDeserializeTime()));
            }

            DeserializationException e = Assert.Throws <DeserializationException>(delegate
            {
                testSoapMethodInvocationSerializer.DeserializeReturnValue("InvalidSerializedMethodInvocation");
            });
        }
Ejemplo n.º 13
0
        public void DeserializeMetricsTest()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MethodInvocationDeserializeTime()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MethodInvocationDeserializeTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MethodInvocationDeserialized()));
            }

            testMethodInvocationSerializer.Deserialize("<?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>");

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 14
0
        public void DeserializeExceptionMetricsTest()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MethodInvocationDeserializeTime()));
                Expect.Once.On(mockMetricLogger).Method("CancelBegin").With(IsMetric.Equal(new MethodInvocationDeserializeTime()));
            }

            DeserializationException e = Assert.Throws <DeserializationException>(delegate
            {
                testMethodInvocationSerializer.Deserialize("<?xml version=\"1.0\" encoding=\"utf-8\"?><MethodInvocationX></MethodInvocationX>");
            });
        }
Ejemplo n.º 15
0
        public void SerializeReturnValueMetricsTest()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new ReturnValueSerializeTime()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new ReturnValueSerializeTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new ReturnValueSerialized()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new SerializedReturnValueSize(117)));
            }

            testMethodInvocationSerializer.SerializeReturnValue("ReturnString");

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 16
0
        public void ReceiveExceptionMetricsTest()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockUnderlyingRemoteReceiver).Method("Receive").Will(Return.Value("InvalidCompressedString"));
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new StringDecompressTime()));
                Expect.Once.On(mockMetricLogger).Method("CancelBegin").With(IsMetric.Equal(new StringDecompressTime()));
            }

            Exception e = Assert.Throws <Exception>(delegate
            {
                testRemoteReceiverDecompressor.Receive();
            });
        }
Ejemplo n.º 17
0
        public void InvokeMethodSerializationExceptionMetricsTest()
        {
            Expect.Once.On(mockMethodInvocationSerializer).Method("Serialize").WithAnyArguments().Will(Throw.Exception(new Exception("Mock Serialization Failure")));
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new RemoteMethodSendTime()));
                Expect.Once.On(mockMetricLogger).Method("CancelBegin").With(IsMetric.Equal(new RemoteMethodSendTime()));
            }

            Exception e = Assert.Throws <Exception>(delegate
            {
                testMethodInvocationRemoteSender.InvokeMethod(testMethodInvocation);
            });
        }
Ejemplo n.º 18
0
        public void SendReturnValueMetricsTest()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMethodInvocationSerializer).Method("SerializeReturnValue").Will(Return.Value(testSerializedReturnValue));
                Expect.AtLeastOnce.On(mockRemoteSender);
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new RemoteMethodReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new RemoteMethodReceived()));
            }

            testMethodInvocationRemoteReceiver.SendReturnValue(new object());

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 19
0
        public void DeserializeReturnValueExceptionMetricsTest()
        {
            string serializedReturnValue = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ReturnValue><InvalidTag></InvalidTag></ReturnValue>";

            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new ReturnValueDeserializeTime()));
                Expect.Once.On(mockMetricLogger).Method("CancelBegin").With(IsMetric.Equal(new ReturnValueDeserializeTime()));
            }

            DeserializationException e = Assert.Throws <DeserializationException>(delegate
            {
                testMethodInvocationSerializer.DeserializeReturnValue(serializedReturnValue);
            });
        }
Ejemplo n.º 20
0
        public void SerializeReturnValueExceptionMetricsTest()
        {
            Dictionary <int, string> returnValue = new Dictionary <int, string>();

            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new ReturnValueSerializeTime()));
                Expect.Once.On(mockMetricLogger).Method("CancelBegin").With(IsMetric.Equal(new ReturnValueSerializeTime()));
            }

            SerializationException e = Assert.Throws <SerializationException>(delegate
            {
                testMethodInvocationSerializer.SerializeReturnValue(returnValue);
            });
        }
Ejemplo n.º 21
0
        public void SerializeMetricsTest()
        {
            MethodInvocation testMethodInvocation = new MethodInvocation("TestMethod", new object[] { "abc", ((int)123), null, ((double)456.789) });

            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MethodInvocationSerializeTime()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MethodInvocationSerializeTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MethodInvocationSerialized()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new SerializedMethodInvocationSize(381)));
            }
            testMethodInvocationSerializer.Serialize(testMethodInvocation);

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void SendExceptionMetricsTest()
        {
            Expect.AtLeastOnce.On(mockLockFile);
            Expect.Once.On(mockMessageFile).Method("WriteAll").WithAnyArguments().Will(Throw.Exception(new Exception("Mock File Write Failure")));
            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
            {
                testFileRemoteSender.Send("<TestMessage>Test message content</TestMessage>");
            });
        }
        public void SendMetricsTest()
        {
            Expect.AtLeastOnce.On(mockMessageFile);
            Expect.AtLeastOnce.On(mockLockFile);
            Expect.AtLeastOnce.On(mockFileSystem);
            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()));
            }

            testFileRemoteSender.Send("<TestMessage>Test message content</TestMessage>");

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 24
0
        public void InvokeMethodMetricsTest()
        {
            Expect.Once.On(mockMethodInvocationSerializer).Method("Serialize").WithAnyArguments().Will(Return.Value(testSerializedMethodInvocation));
            Expect.Once.On(mockRemoteReceiver).Method("Receive").WithAnyArguments().Will(Return.Value(testSerializedReturnValue));
            Expect.Once.On(mockMethodInvocationSerializer).Method("DeserializeReturnValue").WithAnyArguments().Will(Return.Value("Return Data"));
            Expect.AtLeastOnce.On(mockRemoteSender);
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new RemoteMethodSendTime()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new RemoteMethodSendTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new RemoteMethodSent()));
            }

            testMethodInvocationRemoteSender.InvokeMethod(testMethodInvocation);

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 25
0
        public void DeserializeReturnValueMetricsTest()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new ReturnValueDeserializeTime()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new ReturnValueDeserializeTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new ReturnValueDeserialized()));
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new ReturnValueDeserializeTime()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new ReturnValueDeserializeTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new ReturnValueDeserialized()));
            }

            testMethodInvocationSerializer.DeserializeReturnValue("<?xml version=\"1.0\" encoding=\"utf-8\"?><ReturnValue><DataType>string</DataType><Data>ReturnString</Data></ReturnValue>");
            testMethodInvocationSerializer.DeserializeReturnValue("<?xml version=\"1.0\" encoding=\"utf-8\"?><ReturnValue />");

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 26
0
        public void ReceiveMetricsTest()
        {
            testMethodInvocationRemoteReceiver.MethodInvocationReceived += new MethodInvocationReceivedEventHandler(SimulateMethodInvocationReceive);

            Expect.AtLeastOnce.On(mockRemoteReceiver).Method("Receive").WithNoArguments().Will(Return.Value(testSerializedMethodInvocation));
            Expect.AtLeastOnce.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new RemoteMethodReceiveTime()));
            Expect.AtLeastOnce.On(mockMethodInvocationSerializer).Method("Deserialize").Will(Return.Value(new MethodInvocation("TestMethod")));
            Expect.Once.On(mockRemoteReceiver).Method("CancelReceive").WithNoArguments();

            testMethodInvocationRemoteReceiver.Receive();
            // Need to pause so that receiveLoopThread has time to iterate before CancelReceive() is sent.
            //   Unfortunately this is still not a deterministic way to test, but best that can be done given that the Receive() spawns off a new thread.
            System.Threading.Thread.Sleep(50);
            testMethodInvocationRemoteReceiver.CancelReceive();

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 27
0
        public void SendMetricsTest()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MessageSendTime()));
                Expect.Once.On(mockTcpClient).GetProperty("Connected").Will(Return.Value(true));
                Expect.Once.On(mockTcpClient).Method("GetStream").WithNoArguments().Will(Return.Value(mockNetworkStream));
                Expect.Once.On(mockNetworkStream).Method("Write");
                Expect.Once.On(mockTcpClient).GetProperty("Available").Will(Return.Value(1));
                Expect.Once.On(mockNetworkStream).Method("ReadByte").WithNoArguments().Will(Return.Value(6));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageSendTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageSent()));
            }

            testTcpRemoteSender.Send("<TestMessage>Test message content</TestMessage>");
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Ejemplo n.º 28
0
        public void SerializeExceptionMetricsTest()
        {
            object[] methodParameters = new object[1] {
                (UInt16)123
            };
            MethodInvocation testMethodInvocation = new MethodInvocation("TestMethod", methodParameters);

            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new MethodInvocationSerializeTime()));
                Expect.Once.On(mockMetricLogger).Method("CancelBegin").With(IsMetric.Equal(new MethodInvocationSerializeTime()));
            }

            SerializationException e = Assert.Throws <SerializationException>(delegate
            {
                testMethodInvocationSerializer.Serialize(testMethodInvocation);
            });
        }
        public void ReceiveMetricsTest()
        {
            using (mocks.Ordered)
            {
                SetConnectExpectations();
                // Expects for Receive()
                SetBeginMessageReceiveExpectations(testMessageByteArray.Length);
                Expect.Once.On(mockNetworkStream).Method("Read").Will(new SetNamedParameterAction("buffer", testMessageByteArray), Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte");
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(16)));
            }

            testTcpRemoteReceiver.Connect();
            testTcpRemoteReceiver.Receive();
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
        public void SerializeDeserializeReturnValueMetricsTest()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new ReturnValueSerializeTime()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new ReturnValueSerializeTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new ReturnValueSerialized()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(new TypeMatcher(typeof(SerializedReturnValueSize)));
                Expect.Once.On(mockMetricLogger).Method("Begin").With(IsMetric.Equal(new ReturnValueDeserializeTime()));
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new ReturnValueDeserializeTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new ReturnValueDeserialized()));
            }

            string serializedReturnValue = testSoapMethodInvocationSerializer.SerializeReturnValue(new Int32[] { 1, 2, 3, 4, 5 });

            testSoapMethodInvocationSerializer.DeserializeReturnValue(serializedReturnValue);

            mocks.VerifyAllExpectationsHaveBeenMet();
        }