Skip to content

Commit dc55750

Browse files
committed
enable datapreps to return unsaved objects for easier create tests
1 parent d8c04e0 commit dc55750

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

Tests.AccessorTests/TodoItemAccessorTests.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,7 @@ public void SaveTodoItem_Update()
115115
public void SaveTodoItem_Create()
116116
{
117117
// arrange
118-
TodoList parentList = dataPrep.TodoLists.Create();
119-
TodoItem expectedTodoItem = new TodoItem()
120-
{
121-
TodoListId = parentList.Id,
122-
Description = Guid.NewGuid().ToString(),
123-
IsComplete = false,
124-
};
118+
TodoItem expectedTodoItem = dataPrep.TodoItems.Create(isPersisted: false);
125119

126120
// act
127121
SaveResult<TodoItem> saveResult = accessor.SaveTodoItem(expectedTodoItem);

Tests.AccessorTests/TodoListAccessorTests.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ public void SaveTodoList_Update()
5656
public void SaveTodoList_Create()
5757
{
5858
User user = dataPrep.Users.Create();
59-
TodoList newTodoList = new TodoList()
60-
{
61-
UserId = user.Id,
62-
Title = Guid.NewGuid().ToString(),
63-
};
59+
TodoList newTodoList = dataPrep.TodoLists.Create(isPersisted: false);
6460

6561
SaveResult<TodoList> saveResult = accessor.SaveTodoList(newTodoList);
6662
TodoList actualTodoList = saveResult.Result;

Tests.DataPrep/TodoItemPrep.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public TodoItemPrep(ITestDataAccessor dataAccessor, TodoListPrep todoListPrep) :
1717
this.todoListPrep = todoListPrep;
1818
}
1919

20-
public TodoItem Create(TodoList todoList = null, bool? isComplete = null)
20+
public TodoItem Create(TodoList todoList = null, bool? isComplete = null, bool isPersisted = true)
2121
{
2222

2323
TodoList sanitizedTodoList = todoList ?? todoListPrep.Create();
@@ -28,9 +28,15 @@ public TodoItem Create(TodoList todoList = null, bool? isComplete = null)
2828
IsComplete = isComplete ?? random.PickRandom(true, false),
2929
};
3030

31-
TodoItem savedItem = Create(todoItem);
32-
33-
return savedItem;
31+
if (isPersisted)
32+
{
33+
TodoItem savedItem = Create(todoItem);
34+
return savedItem;
35+
}
36+
else
37+
{
38+
return todoItem;
39+
}
3440
}
3541

3642

Tests.DataPrep/TodoListPrep.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public TodoListPrep(ITestDataAccessor dataAccessor, UserPrep userPrep) : base(da
1616
this.userPrep = userPrep;
1717
}
1818

19-
public TodoList Create(User user = null)
19+
public TodoList Create(User user = null, bool isPersisted = true)
2020
{
2121
User sanitizedUser = user ?? userPrep.Create();
2222
TodoList todoList = new TodoList()
@@ -25,9 +25,16 @@ public TodoList Create(User user = null)
2525
Title = random.Lorem.Sentence(),
2626
};
2727

28-
TodoList savedList = Create(todoList);
28+
if (isPersisted)
29+
{
30+
TodoList savedList = base.Create(todoList);
31+
return savedList;
32+
}
33+
else
34+
{
35+
return todoList;
36+
}
2937

30-
return savedList;
3138
}
3239

3340
public IEnumerable<TodoList> CreateManyForUser(int count, User user)

0 commit comments

Comments
 (0)