From faa9bdf4410062d2a8471a631ab9465949958352 Mon Sep 17 00:00:00 2001 From: YARAGANI DURGA DHANUSH Date: Tue, 17 Feb 2026 21:35:47 +0530 Subject: [PATCH] Completed CommBank simulation tasks --- GoalControllerTests.cs | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 GoalControllerTests.cs diff --git a/GoalControllerTests.cs b/GoalControllerTests.cs new file mode 100644 index 0000000..8380181 --- /dev/null +++ b/GoalControllerTests.cs @@ -0,0 +1,74 @@ +using CommBank.Controllers; +using CommBank.Services; +using CommBank.Models; +using CommBank.Tests.Fake; +using Microsoft.AspNetCore.Mvc; + +namespace CommBank.Tests; + +public class GoalControllerTests +{ + private readonly FakeCollections collections; + + public GoalControllerTests() + { + collections = new(); + } + + [Fact] + public async void GetAll() + { + // 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.Get(); + + // Assert + var index = 0; + foreach (Goal goal in result) + { + Assert.IsAssignableFrom(goal); + Assert.Equal(goals[index].Id, goal.Id); + Assert.Equal(goals[index].Name, goal.Name); + index++; + } + } + + [Fact] + public async void Get() + { + // 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.Get(goals[0].Id!); + + // Assert + Assert.IsAssignableFrom(result.Value); + Assert.Equal(goals[0], result.Value); + Assert.NotEqual(goals[1], result.Value); + } + + [Fact] + public async void GetForUser() + { + // Arrange + + // Act + + // Assert + } +} \ No newline at end of file