0

For unit testing, I'm running an in-memory server using the System.Web.Http.HttpServer class. It chokes when attempting to instantiate Enterprise Library objects, because Enterprise Library (v5.0.414.0) is configured in the XML configuration file App.config, which isn't being read.

Is it possible to read in the .config file, or am I forced to start a local server (e.g. WcfSvcHost.exe)?

UPDATE:

I'm able to load the configuration thusly (from How to OpenWebConfiguration with physical path?):

var wcfm = new System.Web.Configuration.WebConfigurationFileMap();
var vdm = new System.Web.Configuration.VirtualDirectoryMapping( @"C:\MyPath\", true, "App.config" );
wcfm.VirtualDirectories.Add( "/", vdm );
var cfg = System.Web.Configuration.WebConfigurationManager.OpenMappedWebConfiguration( wcfm, "/" );

However, I don't know of any straightforward way to pass that data to the HttpServer object (cfg is a Configuration type, apparently of no relation to the HttpConfiguration type found in HttpServer constructors).

I wanted to avoid implementing an IISExpress solution, but it looks as though I'm forced to go that route in order to support Enterprise Library 5 lameness.

11
  • Which unit testing environment are you using? Commented Aug 18, 2015 at 21:59
  • MS.VS.TestTools.UnitTesting with VSTest, the standard in Visual Studio. Commented Aug 18, 2015 at 22:21
  • Note that I found stackoverflow.com/questions/2368748/…, which works for loading the XML file, but presumably a System.Configuration.Configuration object is incompatible with the HttpServer type. I'm looking for a solution that works for the in-memory HttpServer. Commented Aug 18, 2015 at 23:04
  • IIS Express might be another option. Commented Aug 19, 2015 at 1:59
  • I have Microsoft.VisualStudio.TestTools.UnitTesting tests which test components that rely on settings in the .config file. It's definitely reading the app.config. Commented Aug 19, 2015 at 7:09

1 Answer 1

0

Turns out, the in-memory HttpServer class works fine; no need for the Owin stuff. I just needed to have references to a few Enterprise Library assemblies in my unit test project as well as my Web API 2 project.

Fusion logging saved the day again. Such a great way to debug obscure library resolution errors. ( http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx )

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.