public void OnPageHandlerExecuting_GivenResultIsRedirectToPageResult_ExpectNoPageItems()
        {
            var pageContext = new PageContext(new ActionContext(
                                                  new DefaultHttpContext(),
                                                  new RouteData(),
                                                  new PageActionDescriptor(),
                                                  new ModelStateDictionary()));
            var tempDataDictionary = new Mock <ITempDataDictionary>();

            tempDataDictionary.Setup(x => x[It.IsAny <string>()])
            .Returns(() => JsonConvert.SerializeObject(new NotificationPageModel.PageNotification
            {
                Message = "some-message",
            }));

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

            var pageHandlerExecutingContext = new PageHandlerExecutingContext(
                pageContext,
                Array.Empty <IFilterMetadata>(),
                new HandlerMethodDescriptor(),
                new Dictionary <string, object>(),
                page)
            {
                Result = new RedirectToPageResult("some-page")
            };

            page.OnPageHandlerExecuting(pageHandlerExecutingContext);
            Assert.Empty(page.PageNotifications);
        }
        public void OnPageHandlerExecuted_GivenResultIsNotRedirectToPageResult_ExpectNoItemInTempData()
        {
            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 TestableNotificationPageModel();

            page.OnPageHandlerExecuted(pageHandlerExecutedContext);

            Assert.Null(page.TempData);
        }
        public void OnPageHandlerExecuted_IfResultIsRedirectToPageResult_ExpectItemInTempData()
        {
            var tempDataDictionary = new Mock <ITempDataDictionary>();

            tempDataDictionary.Setup(x => x[It.IsAny <string>()])
            .Callback((string key) =>
            {
                Assert.Equal("NotificationPageModelPageNotifications", key);
            });

            var page = new TestableNotificationPageModel {
                TempData = tempDataDictionary.Object
            };

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

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

            page.AddNotification();
            page.OnPageHandlerExecuted(pageHandlerExecutedContext);
        }
        public void AddPageNotification_GivenValidArguments_AddsNotification()
        {
            var page = new TestableNotificationPageModel();

            page.AddNotification();

            Assert.Single(page.PageNotifications);
            Assert.Contains(page.PageNotifications, x => x.Message == "some-message");
        }