Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icons #41

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Icons #41

wants to merge 2 commits into from

Conversation

SiyaTM
Copy link

@SiyaTM SiyaTM commented Mar 1, 2024

Task 1: Modify an Existing .NET Backend

Aim
The aim is to support icons, by extending our existing .NET backend written in C#.

Tools
MongoDB: Seeding your development instance.
C# and .NET: Modify the Goal model
Postman: Manual testing

Result
cwbank.postman_collection.json: Describes the server response

Steps

  1. Fork rSERVER:
    Fork https://github.com/fencer-so/commbank-server using GitHub GUI

  2. Connect Server To Database:
    File: Secrets.json

// Secrets.json
{
  "ConnectionStrings": {
    "CommBank": "{CONNECTION_STRING}"
  }
}

Description:
In the secrets.json file. The Mongo DB connection string is added.

  1. Modify The Goal Model
    File: Goal.cs
// Goal.cs
public class Goal
{

    // ..

    public string? Icon { get; set; }
}

Description:
In the Goal.cs file. There is an addition of an optional public Icon field of string type.

Task 4: Cover Your Code!

Aim
The aim is to cover the icons.

Tools
xUnit testing framework: Used to cover the changes.

Result
GoalControllerTests.cs:

Steps

  1. Modify the GoalControllerTests.cs file.
  2. Create a test case for the GetForUser() method:
// GoalControllerTests.cs
public class GoalControllerTests
{
    private readonly FakeCollections collections;

    public GoalControllerTests()
    {
        collections = new();
    }

    // ...

    [Fact]
    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(goals[0].UserId!);

        // Assert
        Assert.NotNull(result);

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

Description:
Arranged Dependencies:

I've set up the necessary dependencies for the GoalController, including mocked versions of goalsService and usersService. We're using FakeGoalsService and FakeUsersService for this purpose.
Acted to Retrieve Goals:

The test now creates an HTTP context and assigns it to the controller's ControllerContext.HttpContext. Then, it calls the GetForUser method of the GoalController, passing in the user ID of the first goal.
Assertions:

I've added assertions to ensure the correctness of the results.
First, it asserts that the result is not null.
Then, it iterates through each goal in the result, ensuring that each one is of type Goal and that its UserId matches the user ID of the first goal.

Copy link

gitguardian bot commented Mar 1, 2024

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
- MongoDB Credentials 8fe72dc CommBank-Server/Secrets.json View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant