diff --git a/CommBank.Tests/Fake/FakeCollections.cs b/CommBank.Tests/Fake/FakeCollections.cs index 2845283..b40ddf7 100644 --- a/CommBank.Tests/Fake/FakeCollections.cs +++ b/CommBank.Tests/Fake/FakeCollections.cs @@ -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" }, }; diff --git a/CommBank.Tests/Fake/FakeGoalsService.cs b/CommBank.Tests/Fake/FakeGoalsService.cs index 643a27e..603ec2a 100644 --- a/CommBank.Tests/Fake/FakeGoalsService.cs +++ b/CommBank.Tests/Fake/FakeGoalsService.cs @@ -19,7 +19,7 @@ public async Task> GetAsync() => await Task.FromResult(_goals); public async Task?> GetForUserAsync(string id) => - await Task.FromResult(_goals); + await Task.FromResult(_goals.Where(g => g.UserId == id).ToList()); public async Task GetAsync(string id) => await Task.FromResult(_goal); diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181..b1361f9 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -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); + Assert.Equal(goals[0].UserId, goal.UserId); + index++; + } } } \ No newline at end of file