Created
June 26, 2014 18:18
-
-
Save james-dibble/4645c924e0348f110e56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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