Skip to content

Instantly share code, notes, and snippets.

@hudo
Last active July 17, 2017 13:55
Show Gist options
  • Save hudo/b80ba41ea54f451986b07736bdf4d665 to your computer and use it in GitHub Desktop.
Save hudo/b80ba41ea54f451986b07736bdf4d665 to your computer and use it in GitHub Desktop.
Unit tests
public void User_can_write_story_when_authenticated()
{
var controller = new HomeController();
controller.ControllerContext = new ControllerContext
{
HttpContext = new DefaultHttpContext
{
User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
{
new Claim(ClaimTypes.Name, "username")
}, "someAuthTypeName"))
}
};
var actionResult = controller.Index();
var viewResult = Assert.IsType<ViewResult>(actionResult);
var model = Assert.IsType<HomePageViewModel>(viewResult.Model);
Assert.True(model.CanWriteStory);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment