jeudi 2 avril 2015

Make new ServiceHost() read a web.config for tests

I am writing automated tests for for a WCF Service, but I run into a problem: I could not find a way to make my new ServiceHost(...) read my config file.


I made it work by defining the "configuration" in code, but I would like to read from a predefined web.config file.



[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
DatabaseTools.CleanDatabase();

// Create the ServiceHost.
_serviceHost = new ServiceHost(typeof(MyService), BASE_ADDRESS);
var ep = _serviceHost.AddServiceEndpoint(typeof(IMyService), new WebHttpBinding(), "MyService.svc");
ep.EndpointBehaviors.Add(new WebHttpBehavior());
_serviceHost.Open();
}

[ClassCleanup]
public static void ClassCleanup()
{
// Close the ServiceHost.
_serviceHost.Close();
}



  • Is there something similar to serviceHost.config(configFile)?

  • Do you have any tips for setting up this kind of tests?


Aucun commentaire:

Enregistrer un commentaire