2010-09-08 10 views
5

Utilizzando Visual Studio 2010, ho scritto un semplice servizio WCF e alcuni test di integrazione che voglio eseguire contro di esso. Costruisco il mio proxy per i test in fase di esecuzione nel codice anziché utilizzare la configurazione.Quando si esegue mstest contro un servizio WCF, WcfSvcHost non viene eseguito e i test falliscono. I test passano quando il debug è

I miei test passano in debug ma non quando sono in esecuzione!

FAIL se eseguito - andare Test/Run/Test in contesto attuale (come il servizio WCF che chiama non è stato ospitato)

passaggio nell'area di debug - andare Test/Debug/Test in contesto attuale (poiché il progetto WCF ha Opzioni WCF/Avvia servizio host WCF quando esegue il debug di un altro progetto nella stessa soluzione)

C'è un modo per avviare WCFServiceHost quando i test vengono eseguiti normalmente?

Grazie, Andy

Test method BulkLoaderIntegrationTests.IntegrationTests.ImportEntries_withGoodPCMs_reportsCreatedOk threw exception: 
    System.ServiceModel.EndpointNotFoundException: Could not connect to net.tcp://localhost:8001/OLELoader. The connection attempt lasted for a time span of 00:00:00.9687686. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8001. ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:8001 
+0

È possibile aggiungere alcuni messaggi di eccezione? – stephenl

risposta

4

ho disabile 'Start WCF Host Service' durante il debug un altro progetto nella stessa soluzione.

Ho aggiunto un metodo statico in [ClassInitialize] a "self host" il servizio WCF nel contesto Test per la durata del test.

 [ClassInitialize] 
     public static void Init(TestContext t) 
     { 
      IntegrationTests.InitService(); 
     } 

     [ClassCleanup] 
     public static void CleanUp() 
     { 
      IntegrationTests.host.Close();   
     } 

     private static bool ServiceIsStarted = false; 
     private static ServiceHost host; 
     private static void InitService() 
     {   
      if (!ServiceIsStarted) 
      { 
       // Create the ServiceHost. 
       host = new ServiceHost(typeof (OLEImport), 
              new Uri(IntegrationTestHelper.BaseAddress)); 

       // Enable metadata publishing. 
       ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); 
       smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; 
       host.Description.Behaviors.Add(smb); 

       host.Open(); 
       ServiceIsStarted = true; 
      } 
     } 
Problemi correlati