mercredi 30 mars 2016

How can I send a null request for my unit test using Microsoft.Owin.Testing?

Where I'm grabbing the response, I'm trying to figure out a way to send a null request to test a condition in my Invoke statement. I can't figure out how to do that using MicroSoft.Owin.Testing.

// from the test
using (var server = TestServer.Create(app => {
    var mw = new myMiddleware(_fakeMiddleware, _fakeCacheService, _fakeConfigHelper);
    app.UseMyMiddleWare(resolver);
    app.Run(async context => {
        await mw.Invoke(context);
    });
})) {
        // this is the sore spot
        var response = server.CreateRequest("").GetAsync();

        Assert.AreEqual(response.Result.StatusCode, HttpStatusCode.BadRequest);
}

    // from the middle ware
    if (context.Request == null) {
        context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
        return; //Stop pipeline
    }

I put Microsoft.Owin.Testing in the title since it wasn't a tag.

Aucun commentaire:

Enregistrer un commentaire