Created
April 12, 2018 05:50
-
-
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?
This file contains 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 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