Skip to content

Instantly share code, notes, and snippets.

@james-dibble
Created June 26, 2014 18:18
Show Gist options
  • Save james-dibble/4645c924e0348f110e56 to your computer and use it in GitHub Desktop.
Save james-dibble/4645c924e0348f110e56 to your computer and use it in GitHub Desktop.
public class SomeController : Controller
{
public ActionResult GetCookie()
{
var cookie = this.Request.Cookies["CookieName"];
if(cookie == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
return this.RedirectToAction("index", "home");
}
}
[TestClass]
public class SomeControllerTests
{
[TestMethod]
public void TestGetCookie()
{
var fakeRequest = new StubHttpRequestBase
{
CookiesGet = () => new HttpCookieCollection
{
new HttpCookie("CookieName", "CookieValue");
}
};
var target = new SomeController();
new ShimController(target)
{
RequestGet = () => fakeRequest
};
var actual = target.GetCookie();
Assert.IsInstanceOf(actual, typeof(HttpStatusCodeResult));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment