I'm trying to test an OWIN Middleware component in an ASP.NET WebApi 2 application. The middleware is supposed to look at the cookies of the incoming request, modify some stuff on the request before it's handed to the next component, and potentially set a cookie on the way out as well.
What's tripping me up is that the OwinRequest.Cookies property is of type RequestCookieCollection, which doesn't seem to allow modifying, and the property itself is read-only which means I can't use the RequestCookieCollection(IDictionary<string,string>) constructor to initialize a collection with cookies already in it and set that on the request.
I want do do something like this:
var context = new OwinContext();
// option 1:
context.Request.Cookies.Append("cookie-name", "cookie-value");
// option 2:
var cookies = new RequestCookieCollection(new Dictionary<string, string>{ { "cookie-name", "cookie-value" } });
context.Request.Cookies = cookies;
await myMiddleware.Invoke(context);
// Assert stuff about context.Response
but that doesn't work for aforementioned reasons.
I had hoped not to have to mock IOwinContext entierly, because it's quite convenient to have it set up with well-functioning Request and Response objects (I need to, among other things, look at Request.User.Identity.IsAuthenticated in my implementation).