public void SetUser_ShouldAuthed() { const string UserName = "******"; var result = _ctx.SetUser(UserName); Assert.AreSame(_ctx, result); Assert.IsTrue(_ctx.User.Identity.IsAuthenticated); Assert.AreEqual(UserName, _ctx.User.Identity.Name); }
public void SetUp() { _user = new UserInfo { Permissions = new string[0] }; _mockAuth = new Mock <IAuthentication>(); _mockAuth.Setup(m => m.GetUser(It.IsAny <string>())).Returns(_user); var userManager = new UserManager(_mockAuth.Object); var resolver = new NinjectDependencyResolver(); resolver.Kernel.Bind <UserManager>().ToConstant(userManager); DependencyResolver.SetResolver(resolver); _mockCtx = new MockHttpContext(); _mockCtx.SetUser("user"); var controller = new TestController(); var controllerCtx = _mockCtx.CreateControllerContext(controller); var descriptor = new Mock <ActionDescriptor>().Object; _execCtx = new ActionExecutingContext(controllerCtx, descriptor, new Dictionary <string, object>()); _filter = new PermissionAttribute("p1"); }