Skip to content

Instantly share code, notes, and snippets.

@nathanwoulfe
Created April 12, 2018 05:50
Show Gist options
  • Save nathanwoulfe/b34459c1a25bddcb174391f938842bdb to your computer and use it in GitHub Desktop.
Save nathanwoulfe/b34459c1a25bddcb174391f938842bdb to your computer and use it in GitHub Desktop.
Where is my mocked user? How do I get him onto my context?
public GroupControllerTests()
{
// do some other setup stuff first
Mock<WebSecurity> webSecurity = new Mock<WebSecurity>(null, null);
// only need a couple of properties, enough to build a string and stuff
var currentUser = Mock.Of<IUser>(u =>
u.IsApproved
&& u.Name == Utility.RandomString()
&& u.Id == Utility.RandomInt());
// yup, user is set correctly
webSecurity.Setup(x => x.CurrentUser).Returns(currentUser);
// from GDev.Umbraco.Test - gives me umbracoContextMock and applicationContextMock
var context = new ContextMocker();
// in groupsController, umbracoContext.Security.CurrentUser is null.
_groupsController = new GroupsController(context.UmbracoContextMock)
{
Request = new HttpRequestMessage(),
Configuration = new HttpConfiguration()
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment