Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CommBank-Server/Models/Goal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class Goal

public string? Name { get; set; }

public string? Icon { get; set; }

public UInt64 TargetAmount { get; set; } = 0;

public DateTime TargetDate { get; set; }
Expand Down
12 changes: 8 additions & 4 deletions CommBank.Tests/Fake/FakeCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class FakeCollections
List<Transaction> transactions;
List<User> users;


public FakeCollections()
{
accounts = new()
Expand All @@ -19,12 +18,14 @@ public FakeCollections()
{
Id = "1",
Name = "Tag's GoalSaver"

},

new()
{
Id = "2",
Name = "Trot's GoalSaver"

}
};

Expand All @@ -33,19 +34,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 = "2"
},

new()
{
Id = "3",
Name = "Trip to London"
Name = "Trip to London",
UserId = "3"
},
};

Expand Down
8 changes: 6 additions & 2 deletions CommBank.Tests/Fake/FakeGoalsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ public FakeGoalsService(List<Goal> goals, Goal goal)
public async Task<List<Goal>> GetAsync() =>
await Task.FromResult(_goals);

public async Task<List<Goal>?> GetForUserAsync(string id) =>
await Task.FromResult(_goals);
public async Task<List<Goal>?> GetForUserAsync(string id)
{
var userGoals = _goals.Where(goal => goal.UserId == id).ToList();

return await Task.FromResult(userGoals);
}

public async Task<Goal?> GetAsync(string id) =>
await Task.FromResult(_goal);
Expand Down
16 changes: 16 additions & 0 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,25 @@ 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);

Assert.Single(result!);
Assert.Equal(goals[0].Id, result[0].Id);
Assert.Equal(goals[0].UserId, result[0].UserId);
}
}