private void CreateMockUserIdentity(HttpContext context, Mock <IPrincipal> user) { // If FakeHttpContext created a User if (context.User != null) { // Use User MockUser.Setup(u => u.Object).Returns(context.User); //TODO should i check for and mock out User.Identity if its null // Use Identity MockIdentity.Setup(i => i.Object).Returns(context.User.Identity); } else { // Mock User MockUser.Setup(u => u.Object).Returns(user.Object); //TODO is mocking identity duplicating the effort of mocking the user // Mock Identity on User Mock <IIdentity> identity = new Mock <IIdentity>(); MockUser.Setup(u => u.Object.Identity).Returns(identity.Object); // Mock Identity MockIdentity.Setup(i => i.Object).Returns(identity.Object); } }