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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,5 @@ ASALocalRun/
.localhistory/


# Local secrets
Secrets.json
2 changes: 2 additions & 0 deletions CommBank-Server/Models/Goal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public class Goal

[BsonRepresentation(BsonType.ObjectId)]
public string? UserId { get; set; }

public string? Icon { get; set; }
}
5 changes: 0 additions & 5 deletions CommBank-Server/Secrets.json

This file was deleted.

38 changes: 32 additions & 6 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using CommBank.Services;
using CommBank.Models;
using CommBank.Tests.Fake;
using Microsoft.AspNetCore.Mvc;

namespace CommBank.Tests;

Expand All @@ -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>(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
Expand All @@ -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);
}
}
}