From 0935e847ae2c8b9cf26ae18d5456c504b62a637d Mon Sep 17 00:00:00 2001 From: piyushbasist Date: Sat, 20 Jun 2026 01:15:29 +0530 Subject: [PATCH] Add GetForUser route test --- CommBank.Tests/GoalControllerTests.cs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181f..e7350a82 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -63,12 +63,27 @@ public async void Get() } [Fact] - public async void GetForUser() + [Fact] +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); + + foreach (Goal goal in result!) { - // Arrange - - // Act - - // Assert + Assert.IsAssignableFrom(goal); + Assert.Equal(users[0].Id, goal.UserId); } } \ No newline at end of file