Ejemplo n.º 1
0
        public void SendFollowedWithReceiveTimeout_WritesTelemetry()
        {
            TestTelemetryChannel.Clear();
            var innerChannel = new MockClientChannel(SvcUrl);
            var channel      = GetChannel(innerChannel, typeof(ISimpleService));

            var request = BuildMessage(TwoWayOp1);

            request.Headers.MessageId     = new UniqueId();
            innerChannel.MessageToReceive = null;

            channel.Send(request, TimeSpan.FromMilliseconds(50));
            bool failed = false;

            try
            {
                channel.Receive();
            } catch (TimeoutException)
            {
                failed = true;
            }

            Assert.IsTrue(failed, "Receive did not fail with TimeoutException");
            // there's potentially some additional delay between our timeout firing internally,
            // and the callback firing so that telemetry can be written
            Thread.Sleep(200);

            var telemetry = TestTelemetryChannel.CollectedData()
                            .OfType <DependencyTelemetry>()
                            .FirstOrDefault();

            Assert.IsNotNull(telemetry, "No telemetry event written");
            Assert.IsFalse(telemetry.Success.Value, "Dependency call succeeded");
        }
        public void WhenMessageIsSent_Async_TelemetryIsWritten_ExceptionOnEnd()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = this.GetChannel(innerChannel, typeof(IOneWayService));

            innerChannel.FailEndRequest = true;

            var  result = channel.BeginSend(BuildMessage(OneWayOp1), TimeSpan.FromSeconds(10), null, null);
            bool failed = false;

            try
            {
                channel.EndSend(result);
            }
            catch
            {
                failed = true;
            }

            Assert.IsTrue(failed, "EndSend did not throw an exception");

            CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(IOneWayService), OneWayOp1, "SuccessfullOneWayCall", false);
        }
Ejemplo n.º 3
0
        public void AsyncSendAndTryReceive_WritesTelemetry()
        {
            TestTelemetryChannel.Clear();
            var innerChannel = new MockClientChannel(SvcUrl);
            var channel      = GetChannel(innerChannel, typeof(ISimpleService));

            var request = BuildMessage(TwoWayOp1);

            request.Headers.MessageId = new UniqueId();
            var expectedReply = BuildMessage(TwoWayOp1);

            expectedReply.Headers.RelatesTo = request.Headers.MessageId;
            innerChannel.MessageToReceive   = expectedReply;

            var result = channel.BeginSend(request, null, null);

            channel.EndSend(result);
            result = channel.BeginTryReceive(TimeSpan.FromMilliseconds(10), null, null);
            Message reply;

            Assert.IsTrue(channel.EndTryReceive(result, out reply), "EndTryReceive failed");

            var telemetry = TestTelemetryChannel.CollectedData()
                            .OfType <DependencyTelemetry>()
                            .FirstOrDefault();

            Assert.IsNotNull(telemetry, "No telemetry event written");
        }
Ejemplo n.º 4
0
        public void WhenRequestIsSent_Async_TelemetryIsWritten_ExceptionOnEnd()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = this.GetChannel(innerChannel, typeof(ISimpleService));

            innerChannel.FailEndRequest = true;

            var result = channel.BeginRequest(BuildMessage(TwoWayOp1), null, null);
            var failed = false;

            try
            {
                var response = channel.EndRequest(result);
            }
            catch
            {
                failed = true;
            }

            Assert.IsTrue(failed, "EndRequest did not throw an exception");

            CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(ISimpleService), TwoWayOp1, "GetSimpleData", false);
        }
Ejemplo n.º 5
0
        public void WhenMessageIsSent_WithTimeoutException_TelemetryHasResultCode()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(IOneWayService));

            innerChannel.FailRequest            = true;
            innerChannel.ExceptionToThrowOnSend = new TimeoutException();

            bool failed = false;

            try
            {
                channel.Send(BuildMessage(OneWayOp1));
            } catch (TimeoutException)
            {
                failed = true;
            }
            Assert.IsTrue(failed, "Send did not throw TimeoutException");

            var telemetry = TestTelemetryChannel.CollectedData().OfType <DependencyTelemetry>().First();

            Assert.AreEqual("Timeout", telemetry.ResultCode);
        }
Ejemplo n.º 6
0
        public void WhenRequestIsSentWithTimeout_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = this.GetChannel(innerChannel, typeof(ISimpleService));

            var response = channel.Request(BuildMessage(TwoWayOp1), TimeSpan.FromSeconds(10));

            CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(ISimpleService), TwoWayOp1, "GetSimpleData", true);
        }
Ejemplo n.º 7
0
        public void WhenMessageIsSentWithTimeout_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(IOneWayService));

            channel.Send(BuildMessage(OneWayOp1), TimeSpan.FromSeconds(10));

            CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(IOneWayService), OneWayOp1, "SuccessfullOneWayCall", true);
        }
        public void WhenChannelIsOpenedWithTimeout_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(ISimpleService));

            channel.Open(TimeSpan.FromSeconds(10));

            CheckOpenDependencyWritten(typeof(ISimpleService), true);
        }
        public void WhenChannelIsOpened_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = this.GetChannel(innerChannel, typeof(ISimpleService));

            channel.Open();

            CheckOpenDependencyWritten(typeof(ISimpleService), true);
        }
Ejemplo n.º 10
0
        public void WhenRequestIsSent_Async_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = this.GetChannel(innerChannel, typeof(ISimpleService));

            var result   = channel.BeginRequest(BuildMessage(TwoWayOp1), null, null);
            var response = channel.EndRequest(result);

            CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(ISimpleService), TwoWayOp1, "GetSimpleData", true);
        }
        public void WhenChannelIsOpenedAsyncWithTimeout_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = this.GetChannel(innerChannel, typeof(ISimpleService));
            var result  = channel.BeginOpen(TimeSpan.FromSeconds(10), null, null);

            channel.EndOpen(result);

            CheckOpenDependencyWritten(typeof(ISimpleService), true);
        }
        public void WhenChannelIsOpenedAsync_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(ISimpleService));
            var result  = channel.BeginOpen(null, null);

            channel.EndOpen(result);

            CheckOpenDependencyWritten(typeof(ISimpleService), true);
        }
        public void WhenChannelIsCreated_InnerChannelRemoteAddressIsReturned()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(ISimpleService));
            // IChannel does not define RemoteAddress, so cheat

            var prop = channel.GetType().GetProperty("RemoteAddress", BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty);

            Assert.AreEqual(innerChannel.RemoteAddress, prop.GetValue(channel, null));
        }
 public void AfterReceiveRequest_Null_HttpRequestMessage_Throws()
 {
     IDispatchMessageInspector inspector = new MockHttpMessageInspector();
     Message wcfMessage = Message.CreateMessage(MessageVersion.None, "unused"); ;
     IClientChannel channel = new MockClientChannel();
     InstanceContext context = new InstanceContext(new MockService1());
     ExceptionAssert.ThrowsInvalidOperation(
         "Message without HttpRequestMessage should throw",
         () =>
         {
             inspector.AfterReceiveRequest(ref wcfMessage, channel, context);
         });
 }
Ejemplo n.º 15
0
        public void WhenMessageIsSent_Async_TelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(IOneWayService));

            var result = channel.BeginSend(BuildMessage(OneWayOp1), null, null);

            channel.EndSend(result);

            CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(IOneWayService), OneWayOp1, "SuccessfullOneWayCall", true);
        }
 public void AfterReceiveRequest_Null_Message_Throws()
 {
     IDispatchMessageInspector inspector = new MockHttpMessageInspector();
     Message wcfMessage = null;
     IClientChannel channel = new MockClientChannel();
     InstanceContext context = new InstanceContext(new MockService1());
     ExceptionAssert.ThrowsArgumentNull(
         "Null WCF message argument should throw",
         "request",
         () =>
         {
             inspector.AfterReceiveRequest(ref wcfMessage, channel, context);
         });
 }
Ejemplo n.º 17
0
        public void AfterReceiveRequest_Null_HttpRequestMessage_Throws()
        {
            IDispatchMessageInspector inspector = new MockHttpMessageInspector();
            Message         wcfMessage          = Message.CreateMessage(MessageVersion.None, "unused");;
            IClientChannel  channel             = new MockClientChannel();
            InstanceContext context             = new InstanceContext(new MockService1());

            ExceptionAssert.ThrowsInvalidOperation(
                "Message without HttpRequestMessage should throw",
                () =>
            {
                inspector.AfterReceiveRequest(ref wcfMessage, channel, context);
            });
        }
        public void WhenChannelManagerIsNull_ConstructorThrowsException()
        {
            var  innerChannel = new MockClientChannel(SvcUrl);
            bool failed       = false;

            try
            {
                var channel = GetChannel(null, innerChannel);
            } catch (ArgumentNullException)
            {
                failed = true;
            }
            Assert.IsTrue(failed, "Constructor did not throw ArgumentNullException");
        }
Ejemplo n.º 19
0
        public void AfterReceiveRequest_Null_Message_Throws()
        {
            IDispatchMessageInspector inspector = new MockHttpMessageInspector();
            Message         wcfMessage          = null;
            IClientChannel  channel             = new MockClientChannel();
            InstanceContext context             = new InstanceContext(new MockService1());

            ExceptionAssert.ThrowsArgumentNull(
                "Null WCF message argument should throw",
                "request",
                () =>
            {
                inspector.AfterReceiveRequest(ref wcfMessage, channel, context);
            });
        }
Ejemplo n.º 20
0
        public void WhenRequestIsSent_TelemetryIsWritten_SoapFault()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = this.GetChannel(innerChannel, typeof(ISimpleService));

            innerChannel.ReturnSoapFault = true;

            var response = channel.Request(BuildMessage(TwoWayOp1), TimeSpan.FromSeconds(10));

            var telemetry = CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(ISimpleService), TwoWayOp1, "GetSimpleData", false);

            Assert.AreEqual("SoapFault", telemetry.ResultCode);
        }
        public void WhenChannelIsOpenedWithTimeout_InnerChannelEventsAreHooked()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(ISimpleService));

            channel.Open(TimeSpan.FromSeconds(10));

            Assert.IsTrue(innerChannel.OpeningIsHooked(), "Opening event is not hooked");
            Assert.IsTrue(innerChannel.OpenedIsHooked(), "Opened event is not hooked");
            Assert.IsTrue(innerChannel.ClosingIsHooked(), "Closing event is not hooked");
            Assert.IsTrue(innerChannel.ClosedIsHooked(), "Closed event is not hooked");
            Assert.IsTrue(innerChannel.FaultedIsHooked(), "Faulted event is not hooked");
        }
        public void WhenChannelIsOpenedAsync_InnerChannelEventsAreHooked()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(ISimpleService));
            var result  = channel.BeginOpen(null, null);

            channel.EndOpen(result);

            Assert.IsTrue(innerChannel.OpeningIsHooked(), "Opening event is not hooked");
            Assert.IsTrue(innerChannel.OpenedIsHooked(), "Opened event is not hooked");
            Assert.IsTrue(innerChannel.ClosingIsHooked(), "Closing event is not hooked");
            Assert.IsTrue(innerChannel.ClosedIsHooked(), "Closed event is not hooked");
            Assert.IsTrue(innerChannel.FaultedIsHooked(), "Faulted event is not hooked");
        }
        public void WhenIgnoreChannelEventsTrue_And_ChannelIsOpened_NoTelemetryIsWritten()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();

            var manager = new ClientChannelManager(new TelemetryClient(), typeof(ISimpleService))
            {
                IgnoreChannelEvents = true
            };
            var channel = this.GetChannel(manager, innerChannel);

            channel.Open();

            Assert.AreEqual(0, TestTelemetryChannel.CollectedData().Count, "Telemetry events were written");
        }
        public void WhenChannelIsAborted_InnerChannelEventsAreUnhooked()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(ISimpleService));

            channel.Open();
            channel.Abort();

            Assert.IsFalse(innerChannel.OpeningIsHooked(), "Opening event is hooked");
            Assert.IsFalse(innerChannel.OpenedIsHooked(), "Opened event is hooked");
            Assert.IsFalse(innerChannel.ClosingIsHooked(), "Closing event is hooked");
            Assert.IsFalse(innerChannel.ClosedIsHooked(), "Closed event is hooked");
            Assert.IsFalse(innerChannel.FaultedIsHooked(), "Faulted event is hooked");
        }
Ejemplo n.º 25
0
        public void BeginSend_WhenMessageIsNull_ThrowsException()
        {
            TestTelemetryChannel.Clear();
            var innerChannel = new MockClientChannel(SvcUrl);
            var channel      = GetChannel(innerChannel, typeof(ISimpleService));

            bool failed = false;

            try
            {
                channel.BeginSend(null, null, null);
            } catch (ArgumentNullException)
            {
                failed = true;
            }
            Assert.IsTrue(failed, "BeginSend did not throw an exception");
        }
Ejemplo n.º 26
0
        public void Send_OneWay_WritesTelemetry()
        {
            TestTelemetryChannel.Clear();
            var innerChannel = new MockClientChannel(SvcUrl);
            var channel      = GetChannel(innerChannel, typeof(IOneWayService));

            var request = BuildMessage(OneWayOp1);

            request.Headers.MessageId = new UniqueId();
            channel.Send(request);

            var telemetry = TestTelemetryChannel.CollectedData()
                            .OfType <DependencyTelemetry>()
                            .FirstOrDefault();

            Assert.IsNotNull(telemetry, "No telemetry event written");
        }
        public void WhenChannelIsClosedAsyncWithTimeout_InnerChannelEventsAreUnhooked()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(ISimpleService));

            channel.Open();
            var result = channel.BeginClose(TimeSpan.FromSeconds(10), null, null);

            channel.EndClose(result);

            Assert.IsFalse(innerChannel.OpeningIsHooked(), "Opening event is hooked");
            Assert.IsFalse(innerChannel.OpenedIsHooked(), "Opened event is hooked");
            Assert.IsFalse(innerChannel.ClosingIsHooked(), "Closing event is hooked");
            Assert.IsFalse(innerChannel.ClosedIsHooked(), "Closed event is hooked");
            Assert.IsFalse(innerChannel.FaultedIsHooked(), "Faulted event is hooked");
        }
Ejemplo n.º 28
0
        public void AfterReceiveRequest_Receives_HttpRequestMessage()
        {
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage();
            Message            wcfMessage         = httpRequestMessage.ToMessage();
            IClientChannel     channel            = new MockClientChannel();
            InstanceContext    context            = new InstanceContext(new MockService1());

            IDispatchMessageInspector inspector = new MockHttpMessageInspector()
            {
                OnAfterReceiveRequest = actualMessage =>
                {
                    Assert.AreSame(httpRequestMessage, actualMessage, "AfterReceiveRequest did not receive the HttpRequestMessage");
                    return /*state*/ (null);
                }
            };

            inspector.AfterReceiveRequest(ref wcfMessage, channel, context);
            Assert.IsTrue(((MockHttpMessageInspector)inspector).WasAfterReceiveRequestCalled, "AfterReceiveRequest in derived class was not called");
        }
        public void AfterReceiveRequest_Receives_HttpRequestMessage()
        {
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage();
            Message wcfMessage = httpRequestMessage.ToMessage();
            IClientChannel channel = new MockClientChannel();
            InstanceContext context = new InstanceContext(new MockService1());

            IDispatchMessageInspector inspector = new MockHttpMessageInspector()
            {
                OnAfterReceiveRequest = actualMessage =>
                {
                    Assert.AreSame(httpRequestMessage, actualMessage, "AfterReceiveRequest did not receive the HttpRequestMessage");
                    return /*state*/ null;
                }
            };

            inspector.AfterReceiveRequest(ref wcfMessage, channel, context);
            Assert.IsTrue(((MockHttpMessageInspector)inspector).WasAfterReceiveRequestCalled, "AfterReceiveRequest in derived class was not called");
        }
Ejemplo n.º 30
0
        public void WhenMessageIsSent_CorrelationHeadersAreSet()
        {
            var client = new TelemetryClient();

            client.Context.Operation.Id = "12345"; // parentId

            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(IOneWayService), client);

            channel.Send(BuildMessage(OneWayOp1));

            var message = innerChannel.LastMessageSent;

            Assert.AreEqual(client.Context.Operation.Id, GetHttpHeader(message, CorrelationHeaders.HttpStandardRootIdHeader));
            Assert.IsNotNull(GetHttpHeader(message, CorrelationHeaders.HttpStandardParentIdHeader));
            Assert.AreEqual(client.Context.Operation.Id, GetSoapHeader(message, CorrelationHeaders.SoapStandardNamespace, CorrelationHeaders.SoapStandardRootIdHeader));
            Assert.IsNotNull(GetSoapHeader(message, CorrelationHeaders.SoapStandardNamespace, CorrelationHeaders.SoapStandardParentIdHeader));
        }
        public void WhenRequestIsSentWithTimeout_TelemetryIsWritten_Exception()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            TestTelemetryChannel.Clear();
            var channel = GetChannel(innerChannel, typeof(ISimpleService));

            innerChannel.FailRequest = true;

            bool failed = false;

            try
            {
                var response = channel.Request(BuildMessage(TwoWayOp1), TimeSpan.FromSeconds(10));
            } catch {
                failed = true;
            }
            Assert.IsTrue(failed, "Request did not throw an exception");
            CheckOpDependencyWritten(DependencyConstants.WcfClientCall, typeof(ISimpleService), TwoWayOp1, "GetSimpleData", false);
        }
        public void WhenChannelIsOpenedAsyncWithTimeout_TelemetryIsWritten_FailureInBegin()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            innerChannel.FailBeginOpen = true;

            TestTelemetryChannel.Clear();
            var  channel = GetChannel(innerChannel, typeof(ISimpleService));
            bool failed  = false;

            try
            {
                channel.BeginOpen(TimeSpan.FromSeconds(10), null, null);
            } catch (Exception)
            {
                failed = true;
            }
            Assert.IsTrue(failed, "BeginOpen() did not throw exception");

            CheckOpenDependencyWritten(typeof(ISimpleService), false);
        }
        public void WhenChannelIsOpened_TelemetryIsWritten_Failure()
        {
            var innerChannel = new MockClientChannel(SvcUrl);

            innerChannel.FailOpen = true;

            TestTelemetryChannel.Clear();
            var  channel = GetChannel(innerChannel, typeof(ISimpleService));
            bool failed  = false;

            try
            {
                channel.Open();
            } catch (Exception)
            {
                failed = true;
            }
            Assert.IsTrue(failed, "Open() did not throw exception");

            CheckOpenDependencyWritten(typeof(ISimpleService), false);
        }
        public void AfterReceiveRequest_Returns_Custom_State_Value()
        {
            string stringInstance = "hello";
            Message wcfMessage = new HttpRequestMessage().ToMessage();
            IClientChannel channel = new MockClientChannel();
            InstanceContext context = new InstanceContext(new MockService1());

            IDispatchMessageInspector inspector = new MockHttpMessageInspector()
            {
                OnAfterReceiveRequest = actualMessage =>
                {
                    return stringInstance;
                }
            };

            object returnedValue = inspector.AfterReceiveRequest(ref wcfMessage, channel, context);
            Assert.IsTrue(((MockHttpMessageInspector)inspector).WasAfterReceiveRequestCalled, "AfterReceiveRequest in derived class was not called");
            Assert.AreSame(stringInstance,
                           returnedValue,
                           "AfterReceiveRequest return value is not the one we returned.");
        }