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
3 changes: 2 additions & 1 deletion CommBank-Server/CommBank.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>CommBank_Server</RootNamespace>
<AssemblyName>CommBank-Server</AssemblyName>
<UseAppHost>false</UseAppHost>
</PropertyGroup>

<ItemGroup>
Expand Down
15 changes: 11 additions & 4 deletions CommBank-Server/Controllers/GoalController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using CommBank.Services;
using CommBank.Models;

Expand Down Expand Up @@ -78,9 +78,16 @@ public async Task<IActionResult> Update(string id, Goal updatedGoal)
return NotFound();
}

updatedGoal.Id = goal.Id;

await _goalsService.UpdateAsync(id, updatedGoal);
if (updatedGoal.Name is null)
{
goal.Icon = updatedGoal.Icon;
await _goalsService.UpdateAsync(id, goal);
}
else
{
updatedGoal.Id = goal.Id;
await _goalsService.UpdateAsync(id, updatedGoal);
}

return NoContent();
}
Expand Down
4 changes: 3 additions & 1 deletion CommBank-Server/Models/Goal.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MongoDB.Bson;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace CommBank.Models;
Expand All @@ -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
4 changes: 2 additions & 2 deletions CommBank-Server/Secrets.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
{
"ConnectionStrings": {
"CommBank": "{CONNECTION_STRING}"
"CommBank": "mongodb://localhost:27017"
}
}
3 changes: 2 additions & 1 deletion CommBank.Tests/CommBank.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<UseAppHost>false</UseAppHost>
</PropertyGroup>

<ItemGroup>
Expand Down
28 changes: 24 additions & 4 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using CommBank.Controllers;
using System.Threading.Tasks;
using System.Collections.Generic;
using CommBank.Controllers;
using CommBank.Services;
using CommBank.Models;
using CommBank.Tests.Fake;
Expand All @@ -16,7 +18,7 @@ public GoalControllerTests()
}

[Fact]
public async void GetAll()
public async Task GetAll()
{
// Arrange
var goals = collections.GetGoals();
Expand All @@ -37,12 +39,13 @@ public async void GetAll()
Assert.IsAssignableFrom<Goal>(goal);
Assert.Equal(goals[index].Id, goal.Id);
Assert.Equal(goals[index].Name, goal.Name);
Assert.Equal(goals[index].Icon, goal.Icon);
index++;
}
}

[Fact]
public async void Get()
public async Task Get()
{
// Arrange
var goals = collections.GetGoals();
Expand All @@ -63,12 +66,29 @@ 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 httpContext = new Microsoft.AspNetCore.Http.DefaultHttpContext();
controller.ControllerContext.HttpContext = httpContext;
var result = await controller.GetForUser(users[0].Id!);

// Assert
Assert.IsAssignableFrom<List<Goal>>(result);
var index = 0;
foreach (Goal goal in result!)
{
Assert.Equal(goals[index].Id, goal.Id);
Assert.Equal(goals[index].Name, goal.Name);
Assert.Equal(goals[index].Icon, goal.Icon);
index++;
}
}
}