Skip to content

Commit f0f8d9e

Browse files
committed
allow TotalRecords to be 0
1 parent d61bcbb commit f0f8d9e

File tree

2 files changed

+3
-5
lines changed
  • src/JsonApiDotNetCore/Internal
  • test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests

2 files changed

+3
-5
lines changed

src/JsonApiDotNetCore/Internal/PageManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class PageManager
1111
public int DefaultPageSize { get; set; }
1212
public int CurrentPage { get; set; }
1313
public bool IsPaginated => PageSize > 0;
14-
public int TotalPages => (TotalRecords == 0 || TotalRecords == null) ? -1 : (int)Math.Ceiling(decimal.Divide(TotalRecords.Value, PageSize));
14+
public int TotalPages => (TotalRecords == null) ? -1 : (int)Math.Ceiling(decimal.Divide(TotalRecords.Value, PageSize));
1515

1616
public RootLinks GetPageLinks(LinkBuilder linkBuilder)
1717
{

test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/DocumentTests/Meta.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public async Task Total_Record_Count_Not_Included_In_POST_Response()
8888
// arrange
8989
_context.TodoItems.RemoveRange(_context.TodoItems);
9090
_context.SaveChanges();
91-
var expectedCount = 1;
9291
var builder = new WebHostBuilder()
9392
.UseStartup<MetaStartup>();
9493

@@ -120,7 +119,7 @@ public async Task Total_Record_Count_Not_Included_In_POST_Response()
120119

121120
// assert
122121
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
123-
Assert.Null(documents.Meta);
122+
Assert.False(documents.Meta.ContainsKey("total-records"));
124123
}
125124

126125
[Fact]
@@ -131,7 +130,6 @@ public async Task Total_Record_Count_Not_Included_In_PATCH_Response()
131130
TodoItem todoItem = new TodoItem();
132131
_context.TodoItems.Add(todoItem);
133132
_context.SaveChanges();
134-
var expectedCount = 1;
135133
var builder = new WebHostBuilder()
136134
.UseStartup<MetaStartup>();
137135

@@ -164,7 +162,7 @@ public async Task Total_Record_Count_Not_Included_In_PATCH_Response()
164162

165163
// assert
166164
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
167-
Assert.Null(documents.Meta);
165+
Assert.False(documents.Meta.ContainsKey("total-records"));
168166
}
169167

170168
[Fact]

0 commit comments

Comments
 (0)