public async Task PagesControllerHtmlHeadJsonWithNullArticleReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
                Location2 = "an-article-name",
            };
            ContentPageModel?expectedResult = null;
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map(A <ContentPageModel> .Ignored, A <HtmlHeadViewModel> .Ignored)).Returns(A.Fake <HtmlHeadViewModel>());

            // Act
            var result = await controller.HtmlHead(pageRequestModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();

            var jsonResult = Assert.IsType <OkObjectResult>(result);

            _ = Assert.IsAssignableFrom <HtmlHeadViewModel>(jsonResult.Value);

            controller.Dispose();
        }
Ejemplo n.º 2
0
        public async Task PagesControllerBreadcrumbReturnsNotAcceptable(string mediaTypeName)
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
                Location2 = "an-article-name",
            };
            var expectedResult = new ContentPageModel()
            {
                PageLocation = "/" + pageRequestModel.Location1, CanonicalName = pageRequestModel.Location2, ShowBreadcrumb = true,
            };
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);

            // Act
            var result = await controller.Breadcrumb(pageRequestModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();

            var statusResult = Assert.IsType <StatusCodeResult>(result);

            A.Equals((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode);

            controller.Dispose();
        }
        public async Task PagesControllerHtmlHeadHtmlReturnsSuccessWhenNoData(string mediaTypeName)
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
                Location2 = "an-article-name",
            };
            ContentPageModel?expectedResult = null;
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);

            // Act
            var result = await controller.HtmlHead(pageRequestModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();

            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <HtmlHeadViewModel>(viewResult.ViewData.Model);

            model.CanonicalUrl.Should().BeNull();

            controller.Dispose();
        }
Ejemplo n.º 4
0
        public async Task PagesControllerBreadcrumbHtmlReturnsBoContentForDoNotShwoBradcrumb()
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
                Location2 = "an-article-name",
            };
            var expectedResult = new ContentPageModel()
            {
                PageLocation = "/" + pageRequestModel.Location1, CanonicalName = pageRequestModel.Location2, ShowBreadcrumb = false
            };
            var controller = BuildPagesController(MediaTypeNames.Text.Html);

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);

            // Act
            var result = await controller.Breadcrumb(pageRequestModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <BreadcrumbViewModel>(A <ContentPageModel> .Ignored)).MustNotHaveHappened();

            var statusResult = Assert.IsType <NoContentResult>(result);

            A.Equals((int)HttpStatusCode.NoContent, statusResult.StatusCode);

            controller.Dispose();
        }
        public async Task <IActionResult> Body(PageRequestModel pageRequestModel)
        {
            var(location, article) = PagesControlerHelpers.ExtractPageLocation(pageRequestModel);
            var viewModel        = new BodyViewModel();
            var contentPageModel = await pagesControlerHelpers.GetContentPageAsync(location, article).ConfigureAwait(false);

            if (contentPageModel != null)
            {
                mapper.Map(contentPageModel, viewModel);
                logger.LogInformation($"{nameof(Body)} has returned content for: /{location}/{article}");

                return(this.NegotiateContentResult(viewModel, contentPageModel));
            }

            var redirectedContentPageModel = await pagesControlerHelpers.GetRedirectedContentPageAsync(location, article).ConfigureAwait(false);

            if (redirectedContentPageModel != null)
            {
                var pageLocation  = $"{Request.GetBaseAddress()}".TrimEnd('/') + redirectedContentPageModel.PageLocation.TrimEnd('/');
                var redirectedUrl = $"{pageLocation}/{redirectedContentPageModel.CanonicalName}";
                logger.LogWarning($"{nameof(Document)} has been redirected for: /{location}/{article} to {redirectedUrl}");

                return(RedirectPermanent(redirectedUrl));
            }

            logger.LogWarning($"{nameof(Body)} has not returned any content for: /{location}/{article}");
            return(NotFound());
        }
Ejemplo n.º 6
0
        public async Task PagesControllerBreadcrumbJsonReturnsSuccessWhenNoData(string mediaTypeName)
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
                Location2 = "an-article-name",
            };
            ContentPageModel?expectedResult = null;
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);

            // Act
            var result = await controller.Breadcrumb(pageRequestModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();

            var statusResult = Assert.IsType <NoContentResult>(result);

            A.Equals((int)HttpStatusCode.NoContent, statusResult.StatusCode);

            controller.Dispose();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 分页获取用户
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name=""></param>
        /// <returns></returns>
        public async Task <PageRequestModel> GetPageUser(int pageIndex, int pageSize, string where)
        {
            var query = await Db.Ado.SqlQueryAsync <sys_user>($"SELECT id,addtime,name,remark,role_id,Static FROM sys_user {where} limit {(pageIndex - 1) * pageSize},{pageSize}");

            var total = await Db.Ado.GetIntAsync($"SELECT count(id) FROM sys_user {where}");

            var role = await Db.Ado.SqlQueryAsync <sys_role>("SELECT id,name,entity FROM sys_role");

            foreach (var q in query)
            {
                var role_id  = q.role_id.Split(",", StringSplitOptions.RemoveEmptyEntries).Distinct().ToArray();
                var roleList = new List <sys_role>();
                foreach (var r in role_id)
                {
                    roleList.Add(role.SingleOrDefault(c => c.id == int.Parse(r)));
                }
                q.sys_role = roleList;
            }
            var PageModel = new PageRequestModel
            {
                code   = 200,
                result = "分页获取成功",
                active = pageIndex,
                data   = query,
                total  = total
            };

            return(PageModel);
        }
Ejemplo n.º 8
0
        public async Task PagesControllerHeroBannerJsonReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
                Location2 = "an-article-name",
            };
            var expectedResult = new ContentPageModel()
            {
                HeroBanner = "This is a hero banner"
            };
            var expectedHeroBanner = new HeroBannerViewModel {
                Content = new HtmlString(expectedResult.HeroBanner),
            };
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <HeroBannerViewModel>(A <ContentPageModel> .Ignored)).Returns(expectedHeroBanner);

            // Act
            var result = await controller.HeroBanner(pageRequestModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <HeroBannerViewModel>(A <ContentPageModel> .Ignored)).MustHaveHappenedOnceExactly();

            var jsonResult = Assert.IsType <OkObjectResult>(result);
            var model      = Assert.IsAssignableFrom <HeroBannerViewModel>(jsonResult.Value);

            Assert.Equal(expectedHeroBanner.Content, model.Content);

            controller.Dispose();
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Document(PageRequestModel pageRequestModel)
        {
            var(location, article) = PagesControlerHelpers.ExtractPageLocation(pageRequestModel);
            var contentPageModel = await pagesControlerHelpers.GetContentPageAsync(location, article).ConfigureAwait(false);

            if (contentPageModel != null)
            {
                var viewModel = mapper.Map <DocumentViewModel>(contentPageModel);

                if (contentPageModel.ShowBreadcrumb)
                {
                    viewModel.Breadcrumb = mapper.Map <BreadcrumbViewModel>(contentPageModel);

                    if (viewModel.Breadcrumb?.Breadcrumbs != null && viewModel.Breadcrumb.Breadcrumbs.Any())
                    {
                        foreach (var breadcrumb in viewModel.Breadcrumb.Breadcrumbs)
                        {
                            var route = breadcrumb.Route == "/" ? string.Empty : breadcrumb.Route;
                            breadcrumb.Route = $"/pages{route}/document";
                        }
                    }
                }
                else
                {
                    viewModel.Breadcrumb = new BreadcrumbViewModel
                    {
                        Breadcrumbs = new List <BreadcrumbItemViewModel>(),
                    };
                }

                viewModel.Breadcrumb.Breadcrumbs.Insert(0, new BreadcrumbItemViewModel {
                    Route = "/", Title = "[ Index ]"
                });

                logger.LogInformation($"{nameof(Document)} has succeeded for: /{location}/{article}");

                return(this.NegotiateContentResult(viewModel));
            }

            var redirectedContentPageModel = await pagesControlerHelpers.GetRedirectedContentPageAsync(location, article).ConfigureAwait(false);

            if (redirectedContentPageModel != null)
            {
                var redirectedUrl = $"{Request.GetBaseAddress()}{LocalPath}{redirectedContentPageModel.PageLocation}";
                if (redirectedContentPageModel.PageLocation != "/")
                {
                    redirectedUrl += "/";
                }

                redirectedUrl += $"{redirectedContentPageModel.CanonicalName}/document";

                logger.LogWarning($"{nameof(Document)} has been redirected for: /{location}/{article} to {redirectedUrl}");

                return(RedirectPermanent(redirectedUrl));
            }

            logger.LogWarning($"{nameof(Document)} has returned no content for: /{location}/{article}");

            return(NoContent());
        }
Ejemplo n.º 10
0
        public async Task <PageModel <EventModel> > GetAttendingEvents(Guid userId, PageRequestModel pageRequest)
        {
            var attendingEventPageModel = await _repository.GetAttendingEvents(
                userId, _mapper.Map <PageRequest>(pageRequest));

            return(_mapper.Map <PageModel <EventModel> >(attendingEventPageModel));
        }
Ejemplo n.º 11
0
 public void ItemsPerPage_CanBeSet()
 {
     var m = new PageRequestModel();
     for (var i = 0; i < 10; i++) {
         m.ItemsPerPage = i;
         Assert.AreEqual(i, m.ItemsPerPage);
     }
 }
Ejemplo n.º 12
0
 public void RequestedPageBase0_ReturnsRequestedPage()
 {
     var m = new PageRequestModel();
     for (var i = 0; i < 10; i++) {
         m.RequestedPage = i;
         Assert.AreEqual(m.RequestedPage, m.RequestedPageBase0);
     }
 }
Ejemplo n.º 13
0
 public void Constructor_SetsProperties()
 {
     var r = new PageRequestModel();
     var e = new PageLinkModelBase[] { new PageLinkModel(r, 1, "1"), new PageRangeModel(r, 2, 4) };
     var m = new PageChainModel(23, 312, e);
     Assert.AreEqual(23, m.TotalPageCount);
     Assert.AreEqual(312, m.TotalItemCount);
     Assert.AreSame(e, m.PageLinks);
 }
Ejemplo n.º 14
0
        public void Constructor_SetsIsRequestedPageFalseWhenNotRequestedPage()
        {
            var request = new PageRequestModel {
                RequestedPage = 22
            };
            var o = new PageLinkModel(request, 21, "21");

            Assert.IsFalse(o.IsRequestedPage);
        }
Ejemplo n.º 15
0
        public async Task <PagedItems <VideoInfoModel> > GetPublicProcessedVideosAsync(
            PageRequestModel pageRequestModel)
        {
            var anonymousHttpClient = this.HttpClientService.CreateAnonymousClient();

            return(await anonymousHttpClient.GetFromJsonAsync <PagedItems <VideoInfoModel> >(
                       $"{ApiRoutes.VideoController.GetPublicProcessedVideos}?" +
                       $"{nameof(PageRequestModel.PageNumber)}={pageRequestModel.PageNumber}"));
        }
Ejemplo n.º 16
0
        public async Task <PageModel <ChatModel> > GetChatPageAsync(Guid userId, PageRequestModel pageRequest)
        {
            var page = await _chatRepository.GetChatPageByUserId(userId, _mapper.Map <PageRequest>(pageRequest));

            var chatModel = _mapper.Map <PageModel <ChatModel> >(page);

            _chatHelper.GetChatDefinition(chatModel.Entities, userId);
            return(chatModel);
        }
Ejemplo n.º 17
0
 public void Enumerator_ComesFromPageLinks()
 {
     var r = new PageRequestModel();
     var e = new PageLinkModelBase[] { new PageLinkModel(r, 1, "1"), new PageRangeModel(r, 2, 4) };
     var m = new PageChainModel(432, 321, e);
     Assert.AreEqual(e.Count(), m.Count());
     for (var i = 0; i < e.Count(); i++) {
         Assert.AreSame(e.ElementAt(i), m.ElementAt(i));
     }
 }
Ejemplo n.º 18
0
        public ActionResult GetPage(PageRequestModel pageRequest)
        {
            List <PromotionViewModel> pageData = pageRequest == null
                ? UnitOfWork.Instance.PromotionRepository.GetPage(1).Data.Select(x => new PromotionViewModel(x))
                                                 .ToList()
                : UnitOfWork.Instance.PromotionRepository.GetPage(pageRequest.PageNumber, pageRequest.CountPerPage).Data.Select(x => new PromotionViewModel(x))
                                                 .ToList();

            return(PartialView("_PromotionList", pageData));
        }
Ejemplo n.º 19
0
        public async Task <PagedItems <VideoInfoModel> > SearchPublicProcessedVideosAsync(
            PageRequestModel pageRequestModel, string searchTerm)
        {
            var anonymousHttpClient = this.HttpClientService.CreateAnonymousClient();

            return(await anonymousHttpClient.GetFromJsonAsync <PagedItems <VideoInfoModel> >(
                       $"{ApiRoutes.SearchController.SearchPublicProcessedVideos}" +
                       $"?searchTerm={WebUtility.UrlEncode(searchTerm)}" +
                       $"&{nameof(PageRequestModel.PageNumber)}={pageRequestModel.PageNumber}"));
        }
Ejemplo n.º 20
0
        public void Constructor_SetsProperties()
        {
            var r = new PageRequestModel();
            var e = new PageLinkModelBase[] { new PageLinkModel(r, 1, "1"), new PageRangeModel(r, 2, 4) };
            var m = new PageChainModel(23, 312, e);

            Assert.AreEqual(23, m.TotalPageCount);
            Assert.AreEqual(312, m.TotalItemCount);
            Assert.AreSame(e, m.PageLinks);
        }
Ejemplo n.º 21
0
        public void RequestedPage_CanBeSet()
        {
            var m = new PageRequestModel();

            for (var i = 0; i < 10; i++)
            {
                m.RequestedPage = i;
                Assert.AreEqual(i, m.RequestedPage);
            }
        }
Ejemplo n.º 22
0
        public void RequestedPageBase1_ReturnsRequestedPagePlus1()
        {
            var m = new PageRequestModel();

            for (var i = 0; i < 10; i++)
            {
                m.RequestedPage = i;
                Assert.AreEqual(m.RequestedPage + 1, m.RequestedPageBase1);
            }
        }
Ejemplo n.º 23
0
        public void CreateSource_CreatesSource_1()
        {
            var source  = Enumerable.Range(1, 10).AsQueryable();
            var request = new PageRequestModel();

            var factory = new PageSourceFactory();
            var model   = factory.CreateSource(source, request);

            Assert.AreSame(source, model.Source.Queryable);
            Assert.AreSame(request, model.Request);
        }
Ejemplo n.º 24
0
        public void Enumerator_ComesFromPageLinks()
        {
            var r = new PageRequestModel();
            var e = new PageLinkModelBase[] { new PageLinkModel(r, 1, "1"), new PageRangeModel(r, 2, 4) };
            var m = new PageChainModel(432, 321, e);

            Assert.AreEqual(e.Count(), m.Count());
            for (var i = 0; i < e.Count(); i++)
            {
                Assert.AreSame(e.ElementAt(i), m.ElementAt(i));
            }
        }
Ejemplo n.º 25
0
 public void Constructor_CreatesInstanceWithSpecifiedArguments()
 {
     var maxItemsPerPage = 18;
     var defaultItemsPerPage = 7;
     var source = new Source<object>(new List<object>().AsQueryable());
     var request = new PageRequestModel();
     var m = new PageSourceModel<object, PageRequestModel>(maxItemsPerPage, defaultItemsPerPage, source, request);
     Assert.AreEqual(maxItemsPerPage, m.GetMaxItemsPerPage());
     Assert.AreEqual(defaultItemsPerPage, m.GetDefaultItemsPerPage());
     Assert.AreSame(source, m.Source);
     Assert.AreSame(request, m.Request);
 }
Ejemplo n.º 26
0
        public void CreateSource_CreatesOrderedSource_1()
        {
            var source  = Enumerable.Range(1, 10).AsQueryable().OrderBy(i => i) as IQueryable <int>;
            var request = new PageRequestModel();

            var factory = new PageSourceFactory();
            var model   = factory.CreateSource(source, request);

            Assert.AreSame(source, model.Source.Queryable);
            Assert.AreSame(request, model.Request);
            Assert.IsInstanceOf(typeof(IOrderedPageSourceModel <int, PageRequestModel>), model);
        }
Ejemplo n.º 27
0
        public void Constructor_CreatesInstanceWithSpecifiedArguments()
        {
            var maxItemsPerPage     = 18;
            var defaultItemsPerPage = 7;
            var source  = new Source <object>(new List <object>().AsQueryable());
            var request = new PageRequestModel();
            var m       = new PageSourceModel <object, PageRequestModel>(maxItemsPerPage, defaultItemsPerPage, source, request);

            Assert.AreEqual(maxItemsPerPage, m.GetMaxItemsPerPage());
            Assert.AreEqual(defaultItemsPerPage, m.GetDefaultItemsPerPage());
            Assert.AreSame(source, m.Source);
            Assert.AreSame(request, m.Request);
        }
Ejemplo n.º 28
0
 public void Constructor_SetsProperties()
 {
     var request = new PageRequestModel { RequestedPage = 11 };
     var linkPage = 11;
     var linkText = "eleven";
     var o = new PageLinkModel(request, linkPage, linkText);
     Assert.AreSame(request, o.Request);
     Assert.AreEqual(linkPage, o.LinkPage);
     Assert.AreEqual(linkText, o.LinkText);
     Assert.AreEqual(o.LinkPage, o.LowerPage);
     Assert.AreEqual(o.LinkPage, o.UpperPage);
     Assert.IsFalse(o.IsPageRange);
     Assert.IsTrue(o.IsRequestedPage);
 }
Ejemplo n.º 29
0
 public void Constructor_SetsProperties()
 {
     var request = new PageRequestModel { RequestedPage = 8 };
     var lowerPage = 8;
     var upperPage = 10;
     var o = new PageRangeModel(request, lowerPage, upperPage);
     Assert.AreSame(request, o.Request);
     Assert.AreEqual(lowerPage, o.LowerPage);
     Assert.AreEqual(upperPage, o.UpperPage);
     Assert.AreEqual(o.LowerPage, o.LinkPage);
     Assert.AreEqual("...", o.LinkText);
     Assert.IsFalse(o.IsRequestedPage);
     Assert.IsTrue(o.IsPageRange);
 }
Ejemplo n.º 30
0
        public async Task PagesControllerDocumentJsonReturnsSuccess(string mediaTypeName)
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
                Location2 = "an-article-name",
            };
            var expectedResult = new ContentPageModel()
            {
                PageLocation = "/" + pageRequestModel.Location1, CanonicalName = pageRequestModel.Location2, ShowBreadcrumb = true,
            };
            var expectedBreadcrumbModel = new BreadcrumbViewModel
            {
                Breadcrumbs = new List <BreadcrumbItemViewModel>
                {
                    new BreadcrumbItemViewModel
                    {
                        Route = "/",
                        Title = "Root",
                    },
                    new BreadcrumbItemViewModel
                    {
                        Route = "/a-route",
                        Title = "A title",
                    },
                },
            };
            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <ContentPageModel> .Ignored)).Returns(A.Fake <DocumentViewModel>());
            A.CallTo(() => FakeMapper.Map <BreadcrumbViewModel?>(A <ContentPageModel> .Ignored)).Returns(expectedBreadcrumbModel);

            // Act
            var result = await controller.Document(pageRequestModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <ContentPageModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <BreadcrumbViewModel>(A <ContentPageModel> .Ignored)).MustHaveHappenedOnceExactly();

            var jsonResult = Assert.IsType <OkObjectResult>(result);

            _ = Assert.IsAssignableFrom <DocumentViewModel>(jsonResult.Value);

            controller.Dispose();
        }
        public async Task <IActionResult> HeroBanner(PageRequestModel pageRequestModel)
        {
            var(location, article) = PagesControlerHelpers.ExtractPageLocation(pageRequestModel);
            var contentPageModel = await pagesControlerHelpers.GetContentPageAsync(location, article).ConfigureAwait(false);

            if (contentPageModel == null)
            {
                return(NoContent());
            }

            var viewModel = mapper.Map <HeroBannerViewModel>(contentPageModel);

            logger.LogInformation($"{nameof(Breadcrumb)} has returned content for: /{location}/{article}");

            return(this.NegotiateContentResult(viewModel));
        }
Ejemplo n.º 32
0
        public IActionResult Get([FromQuery] PersonFilterModel personFilter, PageRequestModel paging)
        {
            var persons   = uow.PersonRepository.GetAll(personFilter, paging);
            var personRes = mapper.Map <List <PersonResponseModel> >(persons);
            var metadata  = new
            {
                persons.TotalCount,
                persons.PageSize,
                persons.CurrentPage,
                persons.HasNext,
                persons.HasPrevious
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));
            return(Ok(personRes));
        }
Ejemplo n.º 33
0
        public async Task <IActionResult> Head(PageRequestModel pageRequestModel)
        {
            var(location, article) = PagesControlerHelpers.ExtractPageLocation(pageRequestModel);
            var viewModel        = new HeadViewModel();
            var contentPageModel = await pagesControlerHelpers.GetContentPageAsync(location, article).ConfigureAwait(false);

            if (contentPageModel != null)
            {
                mapper.Map(contentPageModel, viewModel);
                viewModel.CanonicalUrl = BuildCanonicalUrl(contentPageModel);
            }

            logger.LogInformation($"{nameof(Head)} has returned content for: /{location}/{article}");

            return(this.NegotiateContentResult(viewModel));
        }
Ejemplo n.º 34
0
        public async Task PagesControllerDocumentHtmlReturnsSuccessForDoNotShowBreadcrumb()
        {
            // Arrange
            var pageRequestModel = new PageRequestModel
            {
                Location1 = "a-location-name",
                Location2 = "an-article-name",
            };
            var expectedResult = new ContentPageModel()
            {
                PageLocation   = "/" + pageRequestModel.Location1,
                CanonicalName  = pageRequestModel.Location2,
                ShowBreadcrumb = false,
            };
            var controller    = BuildPagesController(MediaTypeNames.Text.Html);
            var expectedModel = new DocumentViewModel
            {
                DocumentId       = Guid.NewGuid(),
                CanonicalName    = "a-canonical-name",
                PartitionKey     = "partition-key",
                Version          = Guid.NewGuid(),
                IncludeInSitemap = true,
                Url          = new Uri("https://somewhere.com", UriKind.Absolute),
                Content      = new Microsoft.AspNetCore.Html.HtmlString("some content"),
                LastReviewed = DateTime.Now,
            };

            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).Returns(expectedResult);
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <ContentPageModel> .Ignored)).Returns(expectedModel);

            // Act
            var result = await controller.Document(pageRequestModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakePagesControlerHelpers.GetContentPageAsync(A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <ContentPageModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <BreadcrumbViewModel>(A <ContentPageModel> .Ignored)).MustNotHaveHappened();

            var viewResult = Assert.IsType <ViewResult>(result);

            _ = Assert.IsAssignableFrom <DocumentViewModel>(viewResult.ViewData.Model);
            var model = viewResult.ViewData.Model as DocumentViewModel;

            Assert.Equal(expectedModel, model);

            controller.Dispose();
        }
Ejemplo n.º 35
0
        /// <summary>
        /// 分页获取应用领域
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="wheres"></param>
        /// <returns></returns>
        public async Task <PageRequestModel> GetFieldPage(int pageIndex, int pageSize, string wheres)
        {
            var query = await Db.Ado.SqlQueryAsync <yr_field_li>($"SELECT * FROM yr_field_li {wheres} order by sork DESC limit {(pageIndex - 1) * pageSize},{pageSize}");

            var total = await Db.Ado.GetIntAsync($"SELECT count(id) FROM yr_field_li {wheres}");

            var PageModel = new PageRequestModel
            {
                code   = 200,
                result = "分页获取成功",
                active = pageIndex,
                data   = query,
                total  = total
            };

            return(PageModel);
        }
Ejemplo n.º 36
0
        public void Constructor_SetsProperties()
        {
            var request = new PageRequestModel {
                RequestedPage = 8
            };
            var lowerPage = 8;
            var upperPage = 10;
            var o         = new PageRangeModel(request, lowerPage, upperPage);

            Assert.AreSame(request, o.Request);
            Assert.AreEqual(lowerPage, o.LowerPage);
            Assert.AreEqual(upperPage, o.UpperPage);
            Assert.AreEqual(o.LowerPage, o.LinkPage);
            Assert.AreEqual("...", o.LinkText);
            Assert.IsFalse(o.IsRequestedPage);
            Assert.IsTrue(o.IsPageRange);
        }
Ejemplo n.º 37
0
        public void Constructor_SetsProperties()
        {
            var request = new PageRequestModel {
                RequestedPage = 11
            };
            var linkPage = 11;
            var linkText = "eleven";
            var o        = new PageLinkModel(request, linkPage, linkText);

            Assert.AreSame(request, o.Request);
            Assert.AreEqual(linkPage, o.LinkPage);
            Assert.AreEqual(linkText, o.LinkText);
            Assert.AreEqual(o.LinkPage, o.LowerPage);
            Assert.AreEqual(o.LinkPage, o.UpperPage);
            Assert.IsFalse(o.IsPageRange);
            Assert.IsTrue(o.IsRequestedPage);
        }
Ejemplo n.º 38
0
 public void Constructor_SetsIsRequestedPageFalseWhenNotRequestedPage()
 {
     var request = new PageRequestModel { RequestedPage = 22 };
     var o = new PageLinkModel(request, 21, "21");
     Assert.IsFalse(o.IsRequestedPage);
 }