public void ShouldSetShieldingWithNonIncludeExceptionDetailInFaults()
 {
     // create a mock service and its endpoint.
     Uri serviceUri = new Uri("http://tests:30003");
     ServiceHost host = new ServiceHost(typeof(MockService), serviceUri);
     host.AddServiceEndpoint(typeof(IMockService), new WSHttpBinding(), serviceUri);
     host.Open();
     try
     {
         // check that we have no ErrorHandler loaded into each channel that
         // has IncludeExceptionDetailInFaults turned off.
         foreach (ChannelDispatcher dispatcher in host.ChannelDispatchers)
         {
             Assert.AreEqual(0, dispatcher.ErrorHandlers.Count);
             Assert.IsFalse(dispatcher.IncludeExceptionDetailInFaults);
         }
         ExceptionShieldingBehavior behavior = new ExceptionShieldingBehavior();
         behavior.ApplyDispatchBehavior(null, host);
         // check that the ExceptionShieldingErrorHandler was assigned to each channel
         foreach (ChannelDispatcher dispatcher in host.ChannelDispatchers)
         {
             Assert.AreEqual(1, dispatcher.ErrorHandlers.Count);
             Assert.IsTrue(dispatcher.ErrorHandlers[0].GetType().IsAssignableFrom(typeof(ExceptionShieldingErrorHandler)));
         }
     }
     finally
     {
         if (host.State == CommunicationState.Opened)
         {
             host.Close();
         }
     }
 }
Esempio n. 2
0
        public void ShouldSetShieldingWithNonIncludeExceptionDetailInFaults()
        {
            Uri         serviceUri = new Uri("http://tests:30003");
            ServiceHost host       = new ServiceHost(typeof(MockService), serviceUri);

            host.AddServiceEndpoint(typeof(IMockService), new WSHttpBinding(), serviceUri);
            host.Open();
            try
            {
                foreach (ChannelDispatcher dispatcher in host.ChannelDispatchers)
                {
                    Assert.AreEqual(0, dispatcher.ErrorHandlers.Count);
                    Assert.IsFalse(dispatcher.IncludeExceptionDetailInFaults);
                }
                ExceptionShieldingBehavior behavior = new ExceptionShieldingBehavior();
                behavior.ApplyDispatchBehavior(null, host);
                foreach (ChannelDispatcher dispatcher in host.ChannelDispatchers)
                {
                    Assert.AreEqual(1, dispatcher.ErrorHandlers.Count);
                    Assert.IsTrue(dispatcher.ErrorHandlers[0].GetType().IsAssignableFrom(typeof(ExceptionShieldingErrorHandler)));
                }
            }
            finally
            {
                if (host.State == CommunicationState.Opened)
                {
                    host.Close();
                }
            }
        }
        public void ShouldSetShieldingWithNonIncludeExceptionDetailInFaults()
        {
            // create a mock service and its endpoint.
            Uri         serviceUri = new Uri("http://tests:30003");
            ServiceHost host       = new ServiceHost(typeof(MockService), serviceUri);

            host.AddServiceEndpoint(typeof(IMockService), new WSHttpBinding(), serviceUri);
            try
            {
                host.Open();
            }
            catch (AddressAccessDeniedException ex)
            {
                Assert.Inconclusive("In order to run the tests, please run Visual Studio as Administrator.\r\n{0}", ex.ToString());
            }
            try
            {
                // check that we have no ErrorHandler loaded into each channel that
                // has IncludeExceptionDetailInFaults turned off.
                foreach (ChannelDispatcher dispatcher in host.ChannelDispatchers)
                {
                    Assert.AreEqual(0, dispatcher.ErrorHandlers.Count);
                    Assert.IsFalse(dispatcher.IncludeExceptionDetailInFaults);
                }
                ExceptionShieldingBehavior behavior = new ExceptionShieldingBehavior();
                behavior.ApplyDispatchBehavior(null, host);
                // check that the ExceptionShieldingErrorHandler was assigned to each channel
                foreach (ChannelDispatcher dispatcher in host.ChannelDispatchers)
                {
                    Assert.AreEqual(1, dispatcher.ErrorHandlers.Count);
                    Assert.IsTrue(dispatcher.ErrorHandlers[0].GetType().IsAssignableFrom(typeof(ExceptionShieldingErrorHandler)));
                }
            }
            finally
            {
                if (host.State == CommunicationState.Opened)
                {
                    host.Close();
                }
            }
        }