Skip to content

Commit c457f6e

Browse files
committed
failing test + document how to get started
1 parent 23329ab commit c457f6e

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,41 @@ public class Startup
7575
}
7676
}
7777
```
78+
79+
### Development
80+
81+
Restore all nuget packages with:
82+
83+
```bash
84+
dotnet restore
85+
```
86+
87+
#### Testing
88+
89+
Running tests locally requires access to a postgresql database.
90+
If you have docker installed, this can be propped up via:
91+
92+
```bash
93+
docker run --rm --name jsonapi-dotnet-core-testing \
94+
-e POSTGRES_DB=JsonApiDotNetCoreExample \
95+
-e POSTGRES_USER=postgres \
96+
-e POSTGRES_PASSWORD=postgres \
97+
-p 5432:5432 \
98+
postgres
99+
```
100+
101+
And then to run the tests:
102+
103+
```bash
104+
dotnet test
105+
```
106+
107+
#### Cleaning
108+
109+
Sometimes the compiled files can be dirty / corrupt from other branches / failed builds.
110+
If your bash prompt supports the globstar, you can recursively delete the `bin` and `obj` directories:
111+
112+
```bash
113+
shopt -s globstar
114+
rm -rf **/bin && rm -rf **/obj
115+
```

src/Examples/JsonApiDotNetCoreExample/Models/TodoItem.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public TodoItem()
2424

2525
[Attr("achieved-date", isFilterable: false, isSortable: false)]
2626
public DateTime? AchievedDate { get; set; }
27+
28+
29+
[Attr("updated-date")]
30+
public DateTime? UpdatedDate { get; set; }
31+
32+
2733

2834
public int? OwnerId { get; set; }
2935
public int? AssigneeId { get; set; }

test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,29 @@ public async Task Can_Filter_TodoItems()
9090
Assert.Equal(todoItem.Ordinal, todoItemResult.Ordinal);
9191
}
9292

93+
[Fact]
94+
public async Task Can_Filter_TodoItems_Using_NotEqual_Operator()
95+
{
96+
// Arrange
97+
var todoItem = _todoItemFaker.Generate();
98+
todoItem.UpdatedDate = null;
99+
_context.TodoItems.Add(todoItem);
100+
_context.SaveChanges();
101+
102+
var httpMethod = new HttpMethod("GET");
103+
var route = $"/api/v1/todo-items?filter[updated-date]=ne:null";
104+
var request = new HttpRequestMessage(httpMethod, route);
105+
106+
// Act
107+
var response = await _fixture.Client.SendAsync(request);
108+
var body = await response.Content.ReadAsStringAsync();
109+
var deserializedBody = _fixture.GetService<IJsonApiDeSerializer>().DeserializeList<TodoItem>(body);
110+
111+
// Assert
112+
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
113+
Assert.Empty(deserializedBody);
114+
}
115+
93116
[Fact]
94117
public async Task Can_Filter_TodoItems_Using_Like_Operator()
95118
{

0 commit comments

Comments
 (0)