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

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>CommBank_Server</RootNamespace>
<AssemblyName>CommBank-Server</AssemblyName>
<UserSecretsId>23aef517-52c0-4041-a693-aca36ab5053e</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="MongoDB.Driver" Version="2.18.0" />
<PackageReference Include="MongoDB.Driver" Version="3.4.3" />
</ItemGroup>

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

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

var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("CommBank"));
var mongoDatabase = mongoClient.GetDatabase("CommBank");
// Get Configuration Settings
var dbSettings = builder.Configuration.GetSection("DatabaseSettings");
var connectionString = dbSettings.GetValue<string>("ConnectionString");
var databaseName = dbSettings.GetValue<string>("DatabaseName");

// Create MongoDB Client and Database Objects
var mongoClient = new MongoClient(connectionString);
var mongoDatabase = mongoClient.GetDatabase(databaseName);

// Add Services to the container.
builder.Services.AddSingleton(mongoDatabase);

IAccountsService accountsService = new AccountsService(mongoDatabase);
IAuthService authService = new AuthService(mongoDatabase);
Expand Down Expand Up @@ -43,7 +52,7 @@
app.UseSwaggerUI();
}

app.UseHttpsRedirection();
//app.UseHttpsRedirection();

app.UseAuthorization();

Expand Down
10 changes: 7 additions & 3 deletions CommBank-Server/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
{
"DatabaseSettings": {
"ConnectionString": "mongodb+srv://ronaldfarnandis0y_db_user:[email protected]/?retryWrites=true&w=majority&appName=Cluster0",
"DatabaseName": "test",
"CollectionName": "Goals"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

}
23 changes: 21 additions & 2 deletions CommBank.Tests/GoalControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,28 @@ public async void Get()
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);

// Define which user we are testing for
var targetUser = users[0];
// Find all the goals that belong to our target user from the source data
var expectedGoals = goals.Where(g => g.UserId == targetUser.Id).ToList();

// Act

// Call the controller method to get goals for our target user
var result = await controller.GetForUser(targetUser.Id!);

// Assert
// Convert the result to a list for easier assertions
var actualGoals = result.ToList();

// Check if the number of returned goals is what we expected
Assert.Equal(expectedGoals.Count, actualGoals.Count);
// Check that every goal in the returned list actually belongs to the target user
Assert.All(actualGoals, goal => Assert.Equal(targetUser.Id, goal.UserId));
}
}