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

            var controller = new FakeBaseController(nHbernateContextMock.Object);

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

            var commandMock = new Mock <ICommand>();

            controller.ExecuteExecuteCommand(commandMock.Object);

            nHbernateContextMock.Verify(c => c.ExecuteCommand(It.IsAny <ICommand>()));

            const string result            = "result";
            var          commandResultMock = new Mock <ICommand <string> >();

            commandResultMock.Setup(c => c.Result).Returns(result);
            nHbernateContextMock.Setup(c => c.ExecuteCommand(It.IsAny <ICommand <string> >())).Returns(result);

            var actualResult = controller.ExecuteExecuteCommand(commandResultMock.Object);

            nHbernateContextMock.Verify(c => c.ExecuteCommand(It.IsAny <ICommand <string> >()));
            Assert.AreEqual(result, actualResult);
        }
예제 #2
0
        public void Unauthenticated_User_UserInfo()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);

            var controller = new FakeBaseController(nHbernateContextMock.Object);

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

            var userInfo = controller.GetUserInfo();

            Assert.IsNull(userInfo);
        }
예제 #3
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);
        }
예제 #4
0
        public void Query_Executing()
        {
            var sessionMock          = new Mock <ISession>();
            var nHbernateContextMock = new Mock <NHibernateContext>(sessionMock.Object, UserName);

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny <Func <ISession, NHibernateContext> >()))
            .Returns(nHbernateContextMock.Object);

            var controller = new FakeBaseController(nHbernateContextMock.Object);

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

            var actualResult = controller.ExecuteExecuteQuery(s => s.QueryOver <NHibernateContext>().SingleOrDefault());

            nHbernateContextMock.Verify(c => c.ExecuteQuery(It.IsAny <Func <ISession, NHibernateContext> >()));
            Assert.AreEqual(nHbernateContextMock.Object, actualResult);
        }
예제 #5
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);
        }