Example #1
0
        public void OnPageHandlerExecuted_ResultIsNotRedirectToPageResult_ExpectNoAttemptsToAccessTempData()
        {
            var tempDataDictionary = new Mock <ITempDataDictionary>();

            var modelStateDataCount = 0;
            var pageModelDataCount  = 0;

            tempDataDictionary.SetupSet(x => x["PrgPageModelModelState"] = It.IsAny <object>()).Callback(() =>
            {
                modelStateDataCount++;
            });
            tempDataDictionary.SetupSet(x => x["PrgPageModelPageModel"] = It.IsAny <object>()).Callback(() =>
            {
                pageModelDataCount++;
            });

            var pageContext = new PageContext(new ActionContext(
                                                  new DefaultHttpContext(),
                                                  new RouteData(),
                                                  new PageActionDescriptor(),
                                                  new ModelStateDictionary()));

            var model = new Mock <PageModel>();

            var pageHandlerExecutedContext = new PageHandlerExecutedContext(
                pageContext,
                Array.Empty <IFilterMetadata>(),
                new HandlerMethodDescriptor(),
                model.Object)
            {
                Result = new PageResult()
            };

            var page = new TestablePrgPageModel
            {
                TempData = tempDataDictionary.Object,
            };

            page.OnPageHandlerExecuted(pageHandlerExecutedContext);

            Assert.Equal(0, modelStateDataCount);
            Assert.Equal(0, pageModelDataCount);
        }
Example #2
0
        OnPageHandlerExecuted_ResultIsRedirectToPageResultAndModelStateNotValidAndPrgStateIsFailedOrInError_ExpectTwoAttemptsToAccessTempData()
        {
            var tempDataDictionary = new Mock <ITempDataDictionary>();

            var modelStateDataCount = 0;
            var pageModelDataCount  = 0;

            tempDataDictionary.SetupSet(x => x["PrgPageModelModelState"] = It.IsAny <object>()).Callback(() =>
            {
                modelStateDataCount++;
            });
            tempDataDictionary.SetupSet(x => x["PrgPageModelPageModel"] = It.IsAny <object>()).Callback(() =>
            {
                pageModelDataCount++;
            });
            var pageContext = new PageContext(new ActionContext(
                                                  new DefaultHttpContext(),
                                                  new RouteData(),
                                                  new PageActionDescriptor(),
                                                  new ModelStateDictionary()));

            pageContext.ModelState.AddModelError <TestablePrgPageModel.Model>(x => x.Name, "some-error");

            var model = new Mock <PageModel>();

            var pageHandlerExecutedContext = new PageHandlerExecutedContext(
                pageContext,
                Array.Empty <IFilterMetadata>(),
                new HandlerMethodDescriptor(),
                model.Object)
            {
                Result = new RedirectToPageResult("some-page")
            };

            var page = new TestablePrgPageModel {
                TempData = tempDataDictionary.Object, PrgState = PrgState.InError
            };

            page.OnPageHandlerExecuted(pageHandlerExecutedContext);

            Assert.Equal(1, modelStateDataCount);
            Assert.Equal(1, pageModelDataCount);
        }