2010-08-20 4 views
0

Je rencontre des difficultés à tester un peu de code en utilisant l'installation Wcf pour Castle Windsor. Il semble refuser d'inclure des détails d'exception lorsqu'une exception est levée, je ne vois que des exceptions FaultException vides. Ceci est ma configuration de test:Y compris les détails de l'exception lors de l'utilisation d'un service hébergé WCF Castle Facility

Tout d'abord, voici un bout du service que je vous connecterez:

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

Notez que j'ai spécifié IncludeExceptionDetailsInFaults et mis à true.

Voici comment je serai l'hôte du service bouchonné:

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 
     ); 
} 

Je l'ai fait une PartialMock pour tenter de garder l'inclure .. attribut sur l'objet moqué.

Et le test. Notez que je dis à mon service moqué d'émettre une exception très spécifique ici.

[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); 
} 

Et enfin, le code que je teste en fait:

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); 
    } 
} 

je me attends au service de tomber en panne et jeter l'exception que je l'ai établi à jeter - mais le MFA semble pour supprimer l'exception qui est levée et remplacez-le par une exception FaultException vide.

Ai-je raté quelque chose? Il y a pas mal de composants qui travaillent ensemble ici - et je ne suis pas sûr à 100% que les choses vont mal.

Répondre

Questions connexes