예제 #1
0
        public void Unauthenticated_User_Action_Executing()
        {
            var sessionMock                = new Mock <ISession>();
            var nHbernateContextMock       = new Mock <NHibernateContext>(sessionMock.Object, UserName);
            var actionExecutingContextMock = new Mock <ActionExecutingContext>();

            var controller = new FakeBaseController(nHbernateContextMock.Object);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeUnauthenticatedHttpContext("~/Home/", UserName));

            controller.ExecuteOnActionExecuting(actionExecutingContextMock.Object);

            Assert.AreEqual(0, controller.Session.Count);
        }
예제 #2
0
        public void Authenticated_User_New_SessionAction_Executing()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, User> >()))
            .Returns(new Client {
                Email = "*****@*****.**", Name = UserName
            });

            var actionExecutingContextMock = new Mock <ActionExecutingContext>();

            var controller = new FakeBaseController(nHbernateContextMock.Object);

            controller.SetFakeControllerContext(MvcMockHelpers.FakeAuthenticatedHttpContext("~/Home/", UserName));

            controller.ExecuteOnActionExecuting(actionExecutingContextMock.Object);

            Assert.AreEqual(1, controller.Session.Count);
            var userInfo = (UserInfo)controller.Session[SessionKeys.User];

            Assert.AreEqual(UserName, userInfo.Name);
        }