Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1020543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:10:46+00:00 2026-05-16T11:10:46+00:00

I’m having some trouble unit testing a bit of code while utilising the Wcf

  • 0

I’m having some trouble unit testing a bit of code while utilising the Wcf Facility for Castle Windsor. It seems to refuse to include Exception Details when an Exception is thrown, I only get to see empty FaultExceptions. This is my test setup:

First, here’s a stub of the service that I will be connecting to:

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public abstract class StubAilDataService : IAilDataService
{
    public virtual Method1()
    {
    }
    /* More methods */
}

Notice that I’ve specified IncludeExceptionDetailsInFaults and set it to true.

This is how I host the stubbed service:

private ServiceHost _host;
private StubAilDataService _rhinoService;

[TestFixtureSetUp]
public void FixtureSetup()
{
    var sba = new ServiceDebugBehavior {IncludeExceptionDetailInFaults = true};
    _rhinoService = MockRepository.GeneratePartialMock<StubAilDataService>();

    _host = new ServiceHost(_rhinoService);
    _host.AddServiceEndpoint(typeof(IAilDataService), new WSHttpBinding("wsSecure"), "http://localhost:8080/Service");
    _host.Open();

    _container.AddFacility<WcfFacility>().Register(
        Component.For<IServiceBehavior>().Instance(sba),
        Component.For<IAilDataService>()
            .LifeStyle.PerWcfSession()
            .ActAs(new DefaultClientModel
                       {
                           Endpoint =
                               WcfEndpoint.BoundTo(new WSHttpBinding("wsSecure"))
                               .At("http://localhost:8080/Service")
                       }) // More stuff
        );
}

I’ve done a PartialMock in an attempt to keep the Include.. attribute on the mocked object.

And the test. Notice that I tell my mocked service to throw a very specific exception here.

[Test]
[ExpectedException(typeof(AggregateException))]
public void AnalyzeProductCreationJobs_Should_Throw_Aggregate_Exception_If_A_DataService_Call_Throws()
{
    //Arrange
    _rhinoService.Expect(
    s => s.CategoryIsInAgility(Arg<string>.Matches(str => str.Equals("000103")), Arg<Settings>.Is.Anything))
    .Throw(new FaultException<InvalidOperationException>(new InvalidOperationException("FAIL!")));

    var product = new Product { CategoryCode = "000103" };

    var analyzer = TypeResolver.Resolve<ProductAnalyzer>();

    //Act
    analyzer.AnalyzeProductCreationJobs(product);
}

And finally, the code I’m actually testing:

public class ProductAnalyzer
{
    private readonly IDataServiceClient _dataClient;

    public ProductAnalyzer(IDataServiceClient dataClient)
    {
        _dataClient = dataClient;
    }

    public IEnumerable<IAdsmlJob<CreateResponse>> AnalyzeProductCreationJobs(Product product)
    {
        IList<IAdsmlJob<CreateResponse>> creationJobs = new List<IAdsmlJob<CreateResponse>>();

        var task = Task.Factory.StartNew(() =>
        {
            // This is where the exception set up in my .Expect gets thrown.
            bool categoryIsInAgility = _dataClient.CategoryIsInAgility(product.CategoryCode);
            // Logic
        }); // Continued by more tasks

    try
    { task.Wait(); }
    catch (AggregateException ae)
    {
        ae.Flatten().Handle(ex => ex is TaskCanceledException);
    }
}

I would expect the service to crash and throw the exception I’ve set it up to throw – but the Wcf Facility seems to strip away the exception that is thrown and replace it with an empty FaultException instead.

Am i missing something? There are quite a few components working together here – and I’m not 100% sure where things go wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:10:46+00:00Added an answer on May 16, 2026 at 11:10 am

    You have to explicitly declare the type of fault exception the method throws on the interface.
    Example:

    [ServiceContract(Namespace = "http://www.example.com")]
    public interface IAilDataService
    {
        [OperationContract]
        [FaultContract(typeof(OperationPermissionFault))]
        [FaultContract(typeof(InvalidOperationException))]
        void Method1();
    }
    

    See http://msdn.microsoft.com/en-us/library/system.servicemodel.faultcontractattribute.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.