2010-09-08 10 views
5

Utilizando Visual Studio 2010, he escrito un servicio WCF simple y algunas pruebas de integración que deseo ejecutar en su contra. Construyo mi proxy para las pruebas en tiempo de ejecución en código en lugar de usar la configuración.Al ejecutar mstest contra un servicio WCF, WcfSvcHost no se ejecuta y las pruebas fallan. Las pruebas pasan cuando se depuró

¡Mis pruebas pasan por la depuración pero no cuando se ejecutan!

fallar si ejecutar - ir Test/Run/Pruebas en el contexto actual (como el servicio WCF que llama no se ha alojado)

PASS en la depuración - ir de prueba/depuración/pruebas en el contexto actual (como el proyecto WCF tiene Opciones de WCF/Iniciar host de servicio WCF al depurar otro proyecto en la misma solución)

¿Hay alguna manera de que WCFServiceHost comience cuando las pruebas se ejecutan normalmente?

Gracias, 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

¿Puede agregar algunos mensajes de excepción? – stephenl

Respuesta

4

I discapacitados 'Iniciar servicio WCF Host' en la depuración de otro proyecto en la misma solución.

Agregué un método estático en [ClassInitialize] para 'autohost' el servicio WCF dentro del contexto de Prueba durante la prueba.

 [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; 
      } 
     } 
Cuestiones relacionadas