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
100 changes: 35 additions & 65 deletions CommBank.Tests/Fake/FakeCollections.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommBank.Models;
using System.Collections.Generic;

namespace CommBank.Tests.Fake
{
Expand All @@ -10,116 +11,85 @@ public class FakeCollections
List<Transaction> transactions;
List<User> users;


public FakeCollections()
{
accounts = new()
{
new()
new Account
{
Id = "1",
Name = "Tag's GoalSaver"
},

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

goals = new()
{
new()
{
Id = "1",
Name = "House Down Payment"
},
{
new Goal
{
Id = "1",
Name = "House Down Payment",
UserId = "1"
},

new()
{
Id = "2",
Name = "Tesla Model Y"
},
new Goal
{
Id = "2",
Name = "Tesla Model Y",
UserId = "1"
},

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

tags = new()
{
new()
{
Id = "1"
},

new()
{
Id = "2"
}
new Tag { Id = "1" },
new Tag { Id = "2" }
};

transactions = new()
{
new()
{
Id = "1"
},

new()
{
Id = "2"
}
new Transaction { Id = "1" },
new Transaction { Id = "2" }
};

users = new()
{
new()
new User
{
Id = "1",
Name = "Tag"
},

new()
new User
{
Id = "2",
Name = "Trot"
},

new()
new User
{
Id = "3",
Name = "Tugg"
}
};
}

public List<Account> GetAccounts()
{
return accounts;
}

public List<Goal> GetGoals()
{
return goals;
}

public List<Tag> GetTags()
{
return tags;
}

public List<Transaction> GetTransactions()
{
return transactions;
}

public List<User> GetUsers()
{
return users;
}
public List<Account> GetAccounts() => accounts;
public List<Goal> GetGoals() => goals;
public List<Tag> GetTags() => tags;
public List<Transaction> GetTransactions() => transactions;
public List<User> GetUsers() => users;
}
}
7 changes: 5 additions & 2 deletions CommBank.Tests/Fake/FakeGoalsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ 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 filtered = _goals.Where(g => g.UserId == id).ToList();
return await Task.FromResult(filtered);
}

public async Task<Goal?> GetAsync(string id) =>
await Task.FromResult(_goal);
Expand Down
40 changes: 32 additions & 8 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommBank.Controllers;
using Xunit;
using CommBank.Controllers;
using CommBank.Services;
using CommBank.Models;
using CommBank.Tests.Fake;
Expand Down Expand Up @@ -62,13 +63,36 @@ public async void Get()
Assert.NotEqual(goals[1], result.Value);
}

[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);

var httpContext = new Microsoft.AspNetCore.Http.DefaultHttpContext();
controller.ControllerContext.HttpContext = httpContext;

var userId = users[0].Id!;

// Act
var result = await controller.GetForUser(userId);

// Assert
Assert.NotNull(result);

// result is likely List<Goal>? → safely handle null
var goalsForUser = result ?? new List<Goal>();

Assert.True(goalsForUser.Count > 0);

foreach (var goal in goalsForUser)
{
// Arrange

// Act

// Assert
Assert.Equal(userId, goal.UserId);
}
}
}