From 5c4a5052408cd6308e41fe1cfdf6e8b39cd97384 Mon Sep 17 00:00:00 2001 From: arashiyasubhedar-hub Date: Wed, 24 Jun 2026 14:42:00 +0530 Subject: [PATCH] Add unit test for GetGoalsForUser method --- CommBank-Server/Controllers/GoalController.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/CommBank-Server/Controllers/GoalController.cs b/CommBank-Server/Controllers/GoalController.cs index 98271a5f..04435d9d 100644 --- a/CommBank-Server/Controllers/GoalController.cs +++ b/CommBank-Server/Controllers/GoalController.cs @@ -99,4 +99,24 @@ public async Task Delete(string id) return NoContent(); } -} \ No newline at end of file + [Fact] +public async Task GetGoalsForUser_ReturnsAllGoalsForAUser() +{ + // Arrange + var userId = "test-user-id"; + var expectedGoals = new List + { + new Goal { Id = "1", Name = "Buy a Car", UserId = userId }, + new Goal { Id = "2", Name = "Save for Holiday", UserId = userId } + }; + _mockGoalRepository.Setup(repo => repo.GetForUser(userId)).ReturnsAsync(expectedGoals); + + // Act + var result = await _controller.GetGoalsForUser(userId); + + // Assert + var okResult = Assert.IsType(result.Result); + var returnedGoals = Assert.IsType>(okResult.Value); + Assert.Equal(2, returnedGoals.Count); +} +}