Skip to content

Commit 826630c

Browse files
author
Jacob Hilty
committed
Added Unit Tests
1 parent 72a4375 commit 826630c

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class PagingTests
2727

2828
public PagingTests(TestFixture<TestStartup> fixture)
2929
{
30-
CurrentTime = DateTime.Now;
3130
_fixture = fixture;
3231
_context = fixture.GetService<AppDbContext>();
3332
_personFaker = new Faker<Person>()
@@ -37,7 +36,7 @@ public PagingTests(TestFixture<TestStartup> fixture)
3736
_todoItemFaker = new Faker<TodoItem>()
3837
.RuleFor(t => t.Description, f => f.Lorem.Sentence())
3938
.RuleFor(t => t.Ordinal, f => f.Random.Number())
40-
.RuleFor(t => t.CreatedDate, f => CurrentTime);
39+
.RuleFor(t => t.CreatedDate, f => f.Date.Past());
4140

4241
_todoItemCollectionFaker = new Faker<TodoItemCollection>()
4342
.RuleFor(t => t.Name, f => f.Company.CatchPhrase());
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.Collections.Generic;
2+
using JsonApiDotNetCore.Internal.Query;
3+
using JsonApiDotNetCore.Services;
4+
using Microsoft.AspNetCore.Http;
5+
using Moq;
6+
using Xunit;
7+
8+
namespace UnitTests.Services
9+
{
10+
public class QueryComposerTests
11+
{
12+
private readonly Mock<IJsonApiContext> _jsonApiContext;
13+
14+
public QueryComposerTests()
15+
{
16+
_jsonApiContext = new Mock<IJsonApiContext>();
17+
}
18+
19+
[Fact]
20+
public void Can_Compose_FilterStringForUrl()
21+
{
22+
// arrange
23+
var filter = new FilterQuery("attribute", "value", "=");
24+
var querySet = new QuerySet();
25+
List<FilterQuery> filters = new List<FilterQuery>();
26+
filters.Add(filter);
27+
querySet.Filters=filters;
28+
29+
_jsonApiContext
30+
.Setup(m => m.QuerySet)
31+
.Returns(querySet);
32+
33+
var queryComposer = new QueryComposer();
34+
// act
35+
var filterString = queryComposer.Compose(_jsonApiContext.Object);
36+
// assert
37+
Assert.Equal("&filter[attribute]=value", filterString);
38+
}
39+
40+
[Fact]
41+
public void NoFilter_Compose_EmptyStringReturned()
42+
{
43+
// arrange
44+
var querySet = new QuerySet();
45+
46+
_jsonApiContext
47+
.Setup(m => m.QuerySet)
48+
.Returns(querySet);
49+
50+
var queryComposer = new QueryComposer();
51+
// act
52+
var filterString = queryComposer.Compose(_jsonApiContext.Object);
53+
// assert
54+
Assert.Equal("", filterString);
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)