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

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>CommBank_Server</RootNamespace>
Expand Down
2 changes: 2 additions & 0 deletions CommBank-Server/Models/Goal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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+srv://admin:Aishwarya%4028@commbank.tng4dzo.mongodb.net/?appName=commbank"
}
}
6 changes: 4 additions & 2 deletions CommBank-Server/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"ConnectionStrings": {
"MongoDB": "mongodb+srv://admin:Aishwarya%4028@commbank.tng4dzo.mongodb.net/?appName=commbank"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

}
2 changes: 1 addition & 1 deletion CommBank.Tests/CommBank.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

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

Expand Down
13 changes: 7 additions & 6 deletions CommBank.Tests/Fake/FakeCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
63 changes: 41 additions & 22 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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<Goal>(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>(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<NoContentResult>(result);
}
}
74 changes: 74 additions & 0 deletions CommBank.Tests/GoalControllerTests.cs.bak
Original file line number Diff line number Diff line change
@@ -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>(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<Goal>(result.Value);
Assert.Equal(goals[0], result.Value);
Assert.NotEqual(goals[1], result.Value);
}

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

// Act

// Assert
}
}