public void ShouldBeSucceededWhenSuccessResult() { var result = PaginatedResult <int> .Success(new List <int>() { 1 }, 1, 1, 1); Assert.True(result.Succeeded); }
public void ShouldAddErrorsCorrectly() { var result = PaginatedResult <int> .Success(null, 1, 1, 1); var result2 = new PaginatedResult <int>(null, 1, 1, 1); result.AddError("Error"); result.AddError("Error"); result.AddError("Error"); result2.AddError("Error"); result2.AddError("Error"); result2.AddError("Error"); result2.AddError("Error"); result2.AddError("Error"); Assert.Equal(3, result.Errors.Count); Assert.Equal(5, result2.Errors.Count); var resultError = PaginatedResult <int> .Error("Error"); var resultError2 = new PaginatedResult <int>("Error"); resultError.AddError("Error"); resultError2.AddError("Error"); resultError2.AddError("Error"); Assert.Equal(2, resultError.Errors.Count); Assert.Equal(3, resultError2.Errors.Count); }
public void ShouldCalculateLastPageCorrectly(long total, int pageSize, int lastPage) { var result = PaginatedResult <int> .Success(new List <int> { 1 }, total, 1, pageSize); Assert.Equal(result.LastPage, lastPage); }
public void ShouldCalculateTotalPagesCorrectly(long total, int pageSize, int totalPages) { var result = PaginatedResult <int> .Success(new List <int> { 1 }, total, 1, pageSize); Assert.Equal(result.TotalPages, totalPages); }
public static async Task <PaginatedResult <T> > ToPaginatedListAsync <T>(this IQueryable <T> source, int pageNumber, int pageSize) where T : class { Throw.Exception.IfNull(source, nameof(source)); pageNumber = pageNumber == 0 ? 1 : pageNumber; pageSize = pageSize == 0 ? 10 : pageSize; long count = await source.LongCountAsync(); pageNumber = pageNumber <= 0 ? 1 : pageNumber; List <T> items = await source.Skip((pageNumber - 1) *pageSize).Take(pageSize).ToListAsync(); return(PaginatedResult <T> .Success(items, count, pageNumber, pageSize)); }
public void ShouldNotBeSucceededWhenAddError() { var result = PaginatedResult <int> .Success(null, 1, 1, 1); var result2 = new PaginatedResult <int>(null, 1, 1, 1); result.AddError("Error"); result2.AddError("Error"); Assert.False(result.Succeeded); Assert.False(result2.Succeeded); }
public static async Task <PaginatedResult <T> > ToPaginatedListAsync <T>(this IQueryable <T> source, int pageNumber, int pageSize) where T : class { if (source == null) { throw new ApiException(); } pageNumber = pageNumber == 0 ? 1 : pageNumber; pageSize = pageSize == 0 ? 10 : pageSize; int count = await source.CountAsync(); pageNumber = pageNumber <= 0 ? 1 : pageNumber; List <T> items = await source.Skip((pageNumber - 1) *pageSize).Take(pageSize).ToListAsync(); return(PaginatedResult <T> .Success(items, count, pageNumber, pageSize)); }
public void DataShouldNeverBeNull() { var result = PaginatedResult <int> .Success(null, 1, 1, 1); var result2 = PaginatedResult <int> .Error("Error 1"); var result3 = PaginatedResult <int> .Error(new List <string> { "Erro 1, Erro 2" }); Assert.NotNull(result.Data); Assert.NotNull(result2.Data); Assert.NotNull(result3.Data); }
public static PaginatedResult <string> SelectPaginated() { var page = 0; var pageSize = 2; var totalInDb = FakeService.CountNames(); var result = FakeService.SelectPaginated(page, pageSize); return(PaginatedResult <string> .Success( result, totalInDb, page, pageSize)); }
public void ShouldBeEmptyWhenAddError() { var list = new List <int> { 1, 2, 3 }; var result = PaginatedResult <int> .Success(list, 3, 1, 3); var result2 = new PaginatedResult <int>(list, 3, 1, 3); result.AddError("Error"); result2.AddError("Error"); Assert.Empty(result.Data); Assert.Empty(result2.Data); }