Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions CommBank.Tests/Fake/FakeCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,22 @@ public FakeCollections()
new()
{
Id = "1",
Name = "House Down Payment"
Name = "House Down Payment",
UserId = "1"
},

new()
{
Id = "2",
Name = "Tesla Model Y"
Name = "Tesla Model Y",
UserId = "1"
},

new()
{
Id = "3",
Name = "Trip to London"
Name = "Trip to London",
UserId = "2"
},
};

Expand Down
2 changes: 1 addition & 1 deletion CommBank.Tests/Fake/FakeGoalsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task<List<Goal>> GetAsync() =>
await Task.FromResult(_goals);

public async Task<List<Goal>?> GetForUserAsync(string id) =>
await Task.FromResult(_goals);
await Task.FromResult(_goals.Where(g => g.UserId == id).ToList());

public async Task<Goal?> GetAsync(string id) =>
await Task.FromResult(_goal);
Expand Down
21 changes: 19 additions & 2 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,26 @@ public async void Get()
public async void GetForUser()
{
// Arrange

var goals = collections.GetGoals();
var users = collections.GetUsers();
IGoalsService goalsService = new FakeGoalsService(goals, goals[0]);
IUsersService usersService = new FakeUsersService(users, users[0]);
GoalController controller = new(goalsService, usersService);

// Act

var httpContext = new Microsoft.AspNetCore.Http.DefaultHttpContext();
controller.ControllerContext.HttpContext = httpContext;
var result = await controller.GetForUser(users[0].Id!);

// Assert
Assert.NotNull(result);

var index = 0;
foreach (Goal goal in result!)
{
Assert.IsAssignableFrom<Goal>(goal);
Assert.Equal(goals[0].UserId, goal.UserId);
index++;
}
}
}