Tests.TraceWCFTest.TestSayHello C# (CSharp) Method

TestSayHello() private method

private TestSayHello ( ) : void
return void
        public void TestSayHello()
        {
            String name = "Anonymous";
            Trace actual = null;
            TraceManager.OnTrace += t => actual = t;
            String resultText = null;
            var traceId = Guid.NewGuid();
            String esbContext = Convert.ToBase64String(Encoding.UTF8.GetBytes(String.Format("{{\"LinkedTraceId\":\"{0}\",\"OwnerTraceId\":\"e4b9e2cd-5090-4761-ae97-7a83298897bc\"}}", traceId)));
            var factory = new ChannelFactory<IHelloWorldService>("*");            
            
            using (ServiceHost host = new ServiceHost(typeof(HelloWorldService)))
            {
                host.Open();

                var channel = factory.CreateChannel();
                try
                {
                    using (var context = new OperationContextScope((IContextChannel)channel))
                    {
                        var httpRequestProperty = new HttpRequestMessageProperty();
                        httpRequestProperty.Headers.Add("ESBTraceContext", esbContext);
                        httpRequestProperty.Headers.Add("ESBActivityId", "ActivityId");
                        OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpRequestProperty);
                        resultText = channel.SayHello(name);
                        Assert.IsNotNull(resultText);
                        Assert.AreEqual("Hello, Anonymous", resultText);
                    }
                }
                catch {
                    ((IDisposable)channel).Dispose();
                }

                host.Close();
            }
            Assert.IsNotNull(actual);

            Assert.AreEqual(traceId, actual.Id);
            
            Assert.IsTrue(actual.Properties.ContainsKey(SMILoggerAppender.REPORT_ACTIVITY_ID_PROPERTY));
            Assert.AreEqual("ActivityId",  actual.Properties[SMILoggerAppender.REPORT_ACTIVITY_ID_PROPERTY]);

            Assert.IsTrue(actual.Properties.ContainsKey(SDBTraceProperties.SERVICE_NAME_PROPERTY));
            Assert.AreEqual(typeof(IHelloWorldService).Name, actual.Properties[SDBTraceProperties.SERVICE_NAME_PROPERTY]);

            Assert.IsTrue(actual.Properties.ContainsKey(SDBTraceProperties.SERVICE_OPERATION_NAME_PROPERTY));
            Assert.AreEqual("SayHello", actual.Properties[SDBTraceProperties.SERVICE_OPERATION_NAME_PROPERTY]);

            Assert.IsNotNull(actual.Entries);
            Assert.AreEqual(1, actual.Entries.Count);

            Assert.IsTrue(actual.Properties.ContainsKey(SDBTraceProperties.TRACE_SUCCESS_PROPERTY));
            Assert.IsTrue((bool)actual.Properties[SDBTraceProperties.TRACE_SUCCESS_PROPERTY]);
            
            Assert.IsTrue(actual.Properties.ContainsKey(SDBTraceProperties.TRACE_RESULT_PROPERTY));
            var envelope = XElement.Parse((String)actual.Properties[SDBTraceProperties.TRACE_RESULT_PROPERTY]);
            Assert.IsNotNull(envelope);
            var body = envelope.Element("{http://schemas.xmlsoap.org/soap/envelope/}Body");
            Assert.IsNotNull(body);
            var response = body.Element("{http://tempuri.org/}SayHelloResponse");
            Assert.IsNotNull(response);
            var result = response.Element("{http://tempuri.org/}SayHelloResult");
            Assert.IsNotNull(result);
            Assert.AreEqual("Hello, Anonymous", result.Value);
        }