public void ShouldNotRedirectToSetupWhenThereAreUsers() { var users = new List<User>(); users.Add(new User()); var session = new Mock<IPersistenceSession>(); session.Setup(s => s.All<User>()).Returns(users.AsQueryable()); ObjectFactory.Inject(typeof(IPersistenceSession), session.Object); var user = new Mock<IPrincipal>(); var httpContext = new Mock<HttpContextBase>(); var response = new Mock<HttpResponseBase>(); user.Setup(u => u.Identity).Returns(Mock.Of<IIdentity>()); httpContext.Setup(h => h.Response).Returns(response.Object); httpContext.Setup(h => h.User).Returns(user.Object); var controller = Mock.Of<ControllerBase>(); var controllerContext = new ControllerContext(httpContext.Object, new RouteData(), controller); var filterContext = new ActionExecutingContext(controllerContext, Mock.Of<ActionDescriptor>(), new Dictionary<string, object>()); var attribute = new AppInitAttribute(); attribute.OnActionExecuting(filterContext); response.Verify(r => r.Redirect("/admin/setup", true), Times.Never()); }
public void ShouldNotRedirectToSetupWhenThereAreUsers() { var locator = M<IServiceLocator>(); ServiceLocator.SetLocatorProvider(() => locator); var session = Store.OpenSession(); var userdoc = new User(); session.Store(userdoc); session.SaveChanges(); locator.Expect(l => l.GetInstance<IDocumentSession>()).Return(session); var user = M<IPrincipal>(); var httpContext = M<HttpContextBase>(); var response = M<HttpResponseBase>(); response.Expect(r => r.Redirect("/admin/setup", true)).Repeat.Never(); user.Expect(u => u.Identity).Return(M<IIdentity>()); httpContext.Expect(h => h.Response).Return(response); httpContext.Expect(h => h.User).Return(user); var controller = M<ControllerBase>(); var controllerContext = new ControllerContext(httpContext, new RouteData(), controller); var filterContext = new ActionExecutingContext(controllerContext, M<ActionDescriptor>(), new Dictionary<string, object>()); var attribute = new AppInitAttribute(); attribute.OnActionExecuting(filterContext); response.VerifyAllExpectations(); locator.VerifyAllExpectations(); session.Delete(userdoc); session.SaveChanges(); }
public void ShouldNotCheckRepoWhenUserIsAuthenticated() { var session = new Mock<IPersistenceSession>(); session.Setup(s => s.All<User>()).Returns(new List<User>().AsQueryable()); ObjectFactory.Inject(typeof(IPersistenceSession), session.Object); var user = new Mock<IPrincipal>(); var identity = new Mock<IIdentity>(); var httpContext = new Mock<HttpContextBase>(); var response = new Mock<HttpResponseBase>(); identity.Setup(i => i.IsAuthenticated).Returns(true); user.Setup(u => u.Identity).Returns(identity.Object); httpContext.Setup(h => h.Response).Returns(response.Object); httpContext.Setup(h => h.User).Returns(user.Object); var controller = Mock.Of<ControllerBase>(); var controllerContext = new ControllerContext(httpContext.Object, new RouteData(), controller); var filterContext = new ActionExecutingContext(controllerContext, Mock.Of<ActionDescriptor>(), new Dictionary<string, object>()); var attribute = new AppInitAttribute(); attribute.OnActionExecuting(filterContext); session.Verify(s => s.All<User>(), Times.Never()); identity.Verify(i => i.IsAuthenticated, Times.AtLeastOnce()); }
public void ShouldNotCheckRepoWhenUserIsAuthenticated() { var locator = M<IServiceLocator>(); ServiceLocator.SetLocatorProvider(() => locator); var session = Store.OpenSession(); locator.Expect(l => l.GetInstance<IDocumentSession>()).Return(session); var user = M<IPrincipal>(); var identity = M<IIdentity>(); var httpContext = M<HttpContextBase>(); var response = M<HttpResponseBase>(); identity.Expect(i => i.IsAuthenticated).Return(true).Repeat.AtLeastOnce(); user.Expect(u => u.Identity).Return(identity); httpContext.Expect(h => h.Response).Return(response); httpContext.Expect(h => h.User).Return(user); var controller = M<ControllerBase>(); var controllerContext = new ControllerContext(httpContext, new RouteData(), controller); var filterContext = new ActionExecutingContext(controllerContext, M<ActionDescriptor>(), new Dictionary<string, object>()); var attribute = new AppInitAttribute(); attribute.OnActionExecuting(filterContext); identity.VerifyAllExpectations(); locator.VerifyAllExpectations(); }