lundi 2 mars 2015

api in memory tests with facadefactory pattern

I want to integret in memory tests but the problem is that I'm using a facade factory pattern and I have no idea how to configure it.


The problem is that when I make a request, the moment I call a facade method it throws an exception: "Object reference not set to an instance of an object".


As I understood I need to implement the facades in my test configuration, but I have no idea how to do so. I tried googling, but didn't find anything.


My test configuration ATM looks like this:



[TestFixture]
public class ServerConfiguration : IDisposable
{
protected HttpServer _httpServer;
protected const string UrlBase = "http://localhost/";

[TestFixtureSetUp]
public void SetupHttpServer()
{
var config = new HttpConfiguration();

config.Routes.MapHttpRoute(
name: "Carts",
routeTemplate: "Carts/{id}",
defaults: new { controller = "Carts" }
);
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

_httpServer = new HttpServer(config);
}

protected HttpRequestMessage createRequest(string url, string mthv, HttpMethod method)
{
var request = new HttpRequestMessage();

request.RequestUri = new Uri(UrlBase + url);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(mthv));
request.Method = method;

return request;
}

public void Dispose()
{
if (_httpServer != null)
{
_httpServer.Dispose();
}
}
}


and my global is:



protected void Application_Start()
{
...
...
...
FacadeFactory.RegisterContainerAccessor(this);
DataContainer.RegisterContainerAccessor(this);
}

Aucun commentaire:

Enregistrer un commentaire