Skip to content

Commit edd0f22

Browse files
committed
fix test -- make assertions directly related to the feature under test
1 parent e0b3cef commit edd0f22

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

test/JsonApiDotNetCoreExampleTests/Acceptance/TodoItemsControllerTests.cs

+16-12
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ public async Task Can_Filter_TodoItems_Using_IsNotNull_Operator()
9797
// Arrange
9898
var todoItem = _todoItemFaker.Generate();
9999
todoItem.UpdatedDate = new DateTime();
100-
_context.TodoItems.Add(todoItem);
100+
101+
var otherTodoItem = _todoItemFaker.Generate();
102+
otherTodoItem.UpdatedDate = null;
103+
104+
_context.TodoItems.AddRange(new[] { todoItem, otherTodoItem });
101105
_context.SaveChanges();
102106

103107
var httpMethod = new HttpMethod("GET");
@@ -110,13 +114,11 @@ public async Task Can_Filter_TodoItems_Using_IsNotNull_Operator()
110114
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
111115

112116
var body = await response.Content.ReadAsStringAsync();
113-
var deserializedBody = _fixture.GetService<IJsonApiDeSerializer>().DeserializeList<TodoItem>(body);
117+
var todoItems = _fixture.GetService<IJsonApiDeSerializer>().DeserializeList<TodoItem>(body);
114118

115119
// Assert
116-
Assert.NotEmpty(deserializedBody);
117-
118-
foreach (var todoItemResult in deserializedBody)
119-
Assert.Equal(todoItem.Ordinal, todoItemResult.Ordinal);
120+
Assert.NotEmpty(todoItems);
121+
Assert.All(todoItems, t => Assert.NotNull(t.UpdatedDate));
120122
}
121123

122124
[Fact]
@@ -125,7 +127,11 @@ public async Task Can_Filter_TodoItems_Using_IsNull_Operator()
125127
// Arrange
126128
var todoItem = _todoItemFaker.Generate();
127129
todoItem.UpdatedDate = null;
128-
_context.TodoItems.Add(todoItem);
130+
131+
var otherTodoItem = _todoItemFaker.Generate();
132+
otherTodoItem.UpdatedDate = new DateTime();
133+
134+
_context.TodoItems.AddRange(new[] { todoItem, otherTodoItem });
129135
_context.SaveChanges();
130136

131137
var httpMethod = new HttpMethod("GET");
@@ -138,13 +144,11 @@ public async Task Can_Filter_TodoItems_Using_IsNull_Operator()
138144
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
139145

140146
var body = await response.Content.ReadAsStringAsync();
141-
var deserializedBody = _fixture.GetService<IJsonApiDeSerializer>().DeserializeList<TodoItem>(body);
147+
var todoItems = _fixture.GetService<IJsonApiDeSerializer>().DeserializeList<TodoItem>(body);
142148

143149
// Assert
144-
Assert.NotEmpty(deserializedBody);
145-
146-
foreach (var todoItemResult in deserializedBody)
147-
Assert.Equal(todoItem.Ordinal, todoItemResult.Ordinal);
150+
Assert.NotEmpty(todoItems);
151+
Assert.All(todoItems, t => Assert.Null(t.UpdatedDate));
148152
}
149153

150154
[Fact]

0 commit comments

Comments
 (0)