diff --git a/.gitignore b/.gitignore index 67697151..fe095b10 100644 --- a/.gitignore +++ b/.gitignore @@ -405,3 +405,5 @@ ASALocalRun/ .localhistory/ +# Local secrets +Secrets.json \ No newline at end of file diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad5..20b9b5d4 100644 --- a/CommBank-Server/Models/Goal.cs +++ b/CommBank-Server/Models/Goal.cs @@ -27,4 +27,6 @@ public class Goal [BsonRepresentation(BsonType.ObjectId)] public string? UserId { get; set; } + + public string? Icon { get; set; } } \ No newline at end of file diff --git a/CommBank-Server/Secrets.json b/CommBank-Server/Secrets.json deleted file mode 100644 index 0e5bf949..00000000 --- a/CommBank-Server/Secrets.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "ConnectionStrings": { - "CommBank": "{CONNECTION_STRING}" - } -} \ No newline at end of file diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181f..f798d6c9 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -2,7 +2,6 @@ using CommBank.Services; using CommBank.Models; using CommBank.Tests.Fake; -using Microsoft.AspNetCore.Mvc; namespace CommBank.Tests; @@ -16,44 +15,52 @@ public GoalControllerTests() } [Fact] - public async void GetAll() + public async Task 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() + public async Task 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 @@ -63,12 +70,31 @@ public async void Get() } [Fact] - public async void GetForUser() + public async Task 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 result = await controller.GetForUser(users[0].Id!); + // Assert + Assert.NotNull(result); + Assert.Equal(goals.Count, result.Count); + + for (var index = 0; index < goals.Count; index++) + { + Assert.Equal(goals[index].Id, result[index].Id); + Assert.Equal(goals[index].Name, result[index].Name); + Assert.Equal(goals[index].TargetAmount, result[index].TargetAmount); + Assert.Equal(goals[index].Balance, result[index].Balance); + Assert.Equal(goals[index].UserId, result[index].UserId); + } } } \ No newline at end of file