diff --git a/CommBank-Server/CommBank.csproj b/CommBank-Server/CommBank.csproj index 983cc88..5d76d03 100644 --- a/CommBank-Server/CommBank.csproj +++ b/CommBank-Server/CommBank.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable CommBank_Server diff --git a/CommBank-Server/Models/Goal.cs b/CommBank-Server/Models/Goal.cs index 77ff1ad..16f2694 100644 --- a/CommBank-Server/Models/Goal.cs +++ b/CommBank-Server/Models/Goal.cs @@ -15,6 +15,8 @@ public class Goal public DateTime TargetDate { get; set; } + public string? Icon { get; set; } + public double Balance { get; set; } = 0.00; public DateTime Created { get; set; } = DateTime.Now; diff --git a/CommBank-Server/Secrets.json b/CommBank-Server/Secrets.json index 0e5bf94..3cd9dfa 100644 --- a/CommBank-Server/Secrets.json +++ b/CommBank-Server/Secrets.json @@ -1,5 +1,5 @@ -{ +{ "ConnectionStrings": { - "CommBank": "{CONNECTION_STRING}" + "CommBank": "mongodb+srv://admin:Aishwarya%4028@commbank.tng4dzo.mongodb.net/?appName=commbank" } } \ No newline at end of file diff --git a/CommBank-Server/appsettings.json b/CommBank-Server/appsettings.json index af0538f..3403847 100644 --- a/CommBank-Server/appsettings.json +++ b/CommBank-Server/appsettings.json @@ -1,4 +1,7 @@ { + "ConnectionStrings": { + "MongoDB": "mongodb+srv://admin:Aishwarya%4028@commbank.tng4dzo.mongodb.net/?appName=commbank" + }, "Logging": { "LogLevel": { "Default": "Information", @@ -6,5 +9,4 @@ } }, "AllowedHosts": "*" -} - +} \ No newline at end of file diff --git a/CommBank.Tests/CommBank.Tests.csproj b/CommBank.Tests/CommBank.Tests.csproj index 4d9413f..3da571e 100644 --- a/CommBank.Tests/CommBank.Tests.csproj +++ b/CommBank.Tests/CommBank.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable diff --git a/CommBank.Tests/Fake/FakeCollections.cs b/CommBank.Tests/Fake/FakeCollections.cs index 2845283..511d38f 100644 --- a/CommBank.Tests/Fake/FakeCollections.cs +++ b/CommBank.Tests/Fake/FakeCollections.cs @@ -29,12 +29,13 @@ public FakeCollections() }; goals = new() - { - new() - { - Id = "1", - Name = "House Down Payment" - }, +{ + new() + { + Id = "1", + Name = "House Down Payment", + UserId = "1" + }, new() { diff --git a/CommBank.Tests/GoalControllerTests.cs b/CommBank.Tests/GoalControllerTests.cs index 8380181..cb7b6a4 100644 --- a/CommBank.Tests/GoalControllerTests.cs +++ b/CommBank.Tests/GoalControllerTests.cs @@ -3,34 +3,25 @@ using CommBank.Models; using CommBank.Tests.Fake; using Microsoft.AspNetCore.Mvc; - namespace CommBank.Tests; - public class GoalControllerTests { private readonly FakeCollections collections; - public GoalControllerTests() { collections = new(); } - [Fact] public async void 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) { @@ -40,35 +31,63 @@ public async void GetAll() index++; } } - [Fact] public async void 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 Assert.IsAssignableFrom(result.Value); Assert.Equal(goals[0], result.Value); Assert.NotEqual(goals[1], result.Value); } - [Fact] - public async void GetForUser() +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); + foreach (Goal goal in result) + { + Assert.IsAssignableFrom(goal); + } +} + [Fact] + public async void Put() { - // Arrange - - // Act - - // Assert + 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; + Goal updatedGoal = new() + { + Id = goals[0].Id, + Name = goals[0].Name, + Icon = "👍", + UserId = goals[0].UserId, + TargetAmount = goals[0].TargetAmount, + TargetDate = goals[0].TargetDate, + Balance = goals[0].Balance, + Created = goals[0].Created, + }; + var result = await controller.Update(goals[0].Id!, updatedGoal); + Assert.IsAssignableFrom(result); } } \ No newline at end of file diff --git a/CommBank.Tests/GoalControllerTests.cs.bak b/CommBank.Tests/GoalControllerTests.cs.bak new file mode 100644 index 0000000..8380181 --- /dev/null +++ b/CommBank.Tests/GoalControllerTests.cs.bak @@ -0,0 +1,74 @@ +using CommBank.Controllers; +using CommBank.Services; +using CommBank.Models; +using CommBank.Tests.Fake; +using Microsoft.AspNetCore.Mvc; + +namespace CommBank.Tests; + +public class GoalControllerTests +{ + private readonly FakeCollections collections; + + public GoalControllerTests() + { + collections = new(); + } + + [Fact] + public async void 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); + Assert.Equal(goals[index].Id, goal.Id); + Assert.Equal(goals[index].Name, goal.Name); + index++; + } + } + + [Fact] + public async void 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 + Assert.IsAssignableFrom(result.Value); + Assert.Equal(goals[0], result.Value); + Assert.NotEqual(goals[1], result.Value); + } + + [Fact] + public async void GetForUser() + { + // Arrange + + // Act + + // Assert + } +} \ No newline at end of file