/// <summary> /// IQueryable 转 IPagedList - 领域实体转业务模型 /// </summary> /// <typeparam name="TEntity"></typeparam> /// <typeparam name="TModel"></typeparam> /// <param name="source"></param> /// <param name="page"></param> /// <param name="pageSize"></param> /// <param name="func"></param> /// <returns></returns> public static IPagedList <TModel> ToPagedList <TEntity, TModel>(this IQueryable <TEntity> source, int page, int pageSize, Func <List <TEntity>, List <TModel> > func) where TEntity : class where TModel : class { IPagedList <TEntity> pagedList = source.ToPagedList(page, pageSize); return(pagedList.ToPagedList(func)); }
public static IPagedList <TDestination> MapPagedList <TDestination>(this IMapper mapper, IPagedList collection) { if (mapper == null) { throw new ArgumentNullException(nameof(mapper)); } if (collection == null) { throw new ArgumentNullException(nameof(collection)); } return(collection.ToPagedList(mapper.Map <IEnumerable <TDestination> >(collection))); }
public async Task GetPagedMessagesForChannelCallsCorrectRepositoryMethod( Mock<IUsernameProvider> usernameProvider, Mock<IRepository<ChatMessageDataModel>> messageRepository, string hubId, string channelId, string username, IPagedList<ChatMessageDataModel> messages) { messageRepository .Setup(r => r.GetPaged(1, 100, It.IsAny<Func<IEnumerable<ChatMessageDataModel>, IEnumerable<ChatMessageDataModel>>>())) .Returns(Task.FromResult(messages.ToPagedList(1, 100))); usernameProvider.Setup(p => p.GetUsername()).Returns(Task.FromResult(username)); var controllerUnderTest = new MessagesController(usernameProvider.Object, messageRepository.Object); await controllerUnderTest.GetPagedMessagesForChannel(hubId, channelId, 1, 100); messageRepository.Verify(mock => mock.GetPaged(1, 100, It.IsAny<Func<IEnumerable<ChatMessageDataModel>, IEnumerable<ChatMessageDataModel>>>()), Times.Once()); }