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
3 changes: 2 additions & 1 deletion CommBank-Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("Secrets.json");

var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("CommBank"));
var mongoConnectionString = builder.Configuration["MongoDbSettings:ConnectionString"];
var mongoClient = new MongoClient(mongoConnectionString);
var mongoDatabase = mongoClient.GetDatabase("CommBank");

IAccountsService accountsService = new AccountsService(mongoDatabase);
Expand Down
7 changes: 4 additions & 3 deletions CommBank-Server/Secrets.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"ConnectionStrings": {
"CommBank": "{CONNECTION_STRING}"
"MongoDbSettings": {
"ConnectionString": "mongodb+srv://commbankUser:StrongPassword123@cluster0.3ehcohp.mongodb.net",
"DatabaseName": "CommBank"
}
}
}
6 changes: 6 additions & 0 deletions CommBank-Server/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},

"MongoDbSettings": {
"ConnectionString": "mongodb+srv://commbankUser:StrongPassword123@cluster0.3ehcohp.mongodb.net",
"DatabaseName": "CommBank"
}
}


7 changes: 6 additions & 1 deletion CommBank-Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",

"MongoDbSettings": {
"ConnectionString": "mongodb+srv://commbankUser:StrongPassword123@cluster0.3ehcohp.mongodb.net",
"DatabaseName": "CommBank"
}
}

41 changes: 36 additions & 5 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using CommBank.Controllers;
using Xunit;
using Moq;
using System.Collections.Generic;
using System.Threading.Tasks;
using CommBank.Controllers;
using CommBank.Services;
using CommBank.Models;
using CommBank.Tests.Fake;
Expand Down Expand Up @@ -61,14 +65,41 @@ public async void Get()
Assert.Equal(goals[0], result.Value);
Assert.NotEqual(goals[1], result.Value);
}

[Fact]
public async void GetForUser()
public async Task GetForUser_ReturnsGoals_ForValidUser()
{
// Arrange

var userId = "507f1f77bcf86cd799439011";

var mockGoalsService = new Mock<IGoalsService>();
var mockUsersService = new Mock<IUsersService>();

var expectedGoals = new List<Goal>
{
new Goal
{
Id = "507f1f77bcf86cd799439012",
UserId = userId,
Name = "Test Goal"
}
};

mockGoalsService
.Setup(service => service.GetForUserAsync(userId))
.ReturnsAsync(expectedGoals);

var controller = new GoalController(
mockGoalsService.Object,
mockUsersService.Object
);

// Act

var result = await controller.GetForUser(userId);

// Assert
Assert.NotNull(result);
Assert.Single(result);
Assert.Equal("Test Goal", result[0].Name);
}
}