Skip to content

Commit

Permalink
Updating project Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Edrisym committed Nov 15, 2024
1 parent 37d6646 commit 71c7fbf
Showing 1 changed file with 91 additions and 61 deletions.
152 changes: 91 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,56 @@
# E-Wallet Project
### E-Wallet Project

## Overview
This E-Wallet project is developed using the **Test-Driven Development (TDD)** approach. It is built with **.NET 8** and uses **SQL Server** for database management. The project utilizes **XUnit** for unit testing and **FluentAssertions** for expressive and readable assertions in tests. The system includes core functionalities such as wallet creation, balance management, withdrawal operations, and handling of multiple currencies.
---

## Features
## **Overview**
This E-Wallet project is developed using the **Test-Driven Development (TDD)** approach. It is built with **.NET 8** and uses **SQL Server** for database management. The project leverages **JWT (JSON Web Tokens)** for secure user authentication and authorization. The development is thoroughly tested using **XUnit** with enhanced readability provided by **FluentAssertions**. Core functionalities include wallet creation, balance management, withdrawal operations, and handling of multiple currencies.

---

## **Features**
- **Wallet Creation**: Create a wallet with an initial balance.
- **Withdrawals**: Withdraw funds from the wallet while ensuring the balance is sufficient.
- **Currency Support**: Support for handling multiple currencies and exchange rates.
- **TDD**: The entire development follows the **Test-Driven Development (TDD)** approach, ensuring a high level of code quality and test coverage.
- **SQL Server Integration**: Utilizes SQL Server as the primary database for persistence.
- **Custom Exceptions**: Throwing and handling exceptions for invalid operations like insufficient funds or invalid balances.
- **Withdrawals**: Withdraw funds from the wallet while ensuring sufficient balance.
- **Currency Support**: Handle multiple currencies and exchange rates seamlessly.
- **User Authentication**: Secure user authentication and authorization using **JWT**.
- **TDD**: Adheres to the **Test-Driven Development (TDD)** approach, ensuring high code quality and comprehensive test coverage.
- **SQL Server Integration**: Utilizes **SQL Server** as the primary database for data persistence.
- **Custom Exceptions**: Provides tailored exception handling for scenarios like insufficient funds and invalid balances.

---

## Technologies Used
## **Technologies Used**
- **C#**
- **.NET 8**
- **SQL Server**: Used for data storage and persistence.
- **XUnit**: Framework for writing and running unit tests.
- **FluentAssertions**: Library to enhance assertions in tests with readable and expressive syntax.
- **Entity Framework Core**: Used for data access and interactions with SQL Server.
- **Entity Framework Core**: For database interactions and migrations.
- **JWT (JSON Web Tokens)**: Secures authentication and authorization processes.
- **XUnit**: Framework for unit testing.
- **FluentAssertions**: Library for expressive and readable assertions in tests.

## Project Structure
- **`Models`**: Contains classes representing business entities like Wallet and Currency.
- **`Exceptions`**: Custom exceptions used for specific error scenarios (e.g., insufficient funds, invalid balance).
- **`Data`**: Contains database access logic, including Entity Framework DbContext.
- **`Tests`**: Unit tests for business logic, written using **XUnit** and **FluentAssertions**.
---

## Setup and Installation
## **Project Structure**
- **`Models`**: Contains classes representing business entities like `Wallet` and `Currency`.
- **`Exceptions`**: Custom exceptions for specific error scenarios, such as insufficient funds.
- **`Data`**: Contains database logic, including `DbContext` for Entity Framework.
- **`Services`**: Implements core business logic for wallet operations.
- **`Authentication`**: Includes JWT configuration and token generation.
- **`Tests`**: Unit tests written with **XUnit** and **FluentAssertions**.

### Prerequisites
To run and contribute to this project, ensure the following are installed:
---

## **Setup and Installation**

### **Prerequisites**
To run this project, ensure the following are installed:
- **.NET 8 SDK**: [Download .NET 8](https://dotnet.microsoft.com/download/dotnet/8.0)
- **SQL Server**: Local or cloud-based instance of SQL Server.
- **XUnit**: [XUnit](https://xunit.net/) for unit testing.
- **FluentAssertions**: [FluentAssertions](https://fluentassertions.com/) for enhanced assertions.
- **SQL Server**: Local or cloud-based SQL Server instance.
- **XUnit**: [XUnit](https://xunit.net/) for running unit tests.
- **FluentAssertions**: [FluentAssertions](https://fluentassertions.com/) for enhanced test assertions.

---

### Steps to Run the Project
### **Steps to Run the Project**

1. **Clone the Repository**:
```bash
Expand All @@ -43,88 +59,102 @@ To run and contribute to this project, ensure the following are installed:
```

2. **Restore Dependencies**:
Ensure that all NuGet packages are restored:
Restore the required NuGet packages:
```bash
dotnet restore
```

3. **Set Up SQL Server**:
Make sure you have access to a **SQL Server** instance and configure your connection string in the `appsettings.json` file.

Example of the connection string in `appsettings.json`:
Update the connection string in `appsettings.json`:
```json
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=EWalletDb;Trusted_Connection=True;"
},
"JwtSettings": {
"Issuer": "YourIssuerValue",
"Audience": "YourAudienceValue",
"Key": "YourSuperSecretKey12345"
}
}
```

4. **Apply Migrations**:
Apply Entity Framework Core migrations to create the necessary database tables:
Run migrations to set up the database schema:
```bash
dotnet ef database update
```

5. **Build the Project**:
Compile the application:
```bash
dotnet build
```

6. **Run the Tests**:
To run all unit tests:
Execute all unit tests:
```bash
dotnet test
```

7. **Run the Application** (if applicable):
To run the main application (for example, if there is a web API or service):
7. **Run the Application**:
Launch the application:
```bash
dotnet run
```

## Test-Driven Development Approach
---

This project strictly follows the **Test-Driven Development (TDD)** approach:
1. **Write a Test First**: Write a test to specify the expected behavior of the functionality before implementing it.
2. **Implement the Code**: Write the minimal code necessary to pass the test.
3. **Refactor**: Refactor the code to improve its design, while ensuring all tests continue to pass.
## **Test-Driven Development (TDD) Approach**
This project strictly adheres to the **TDD** methodology:
1. **Write Tests First**: Define the expected behavior with tests before implementation.
2. **Implement Code**: Write only the code required to pass the test.
3. **Refactor**: Improve the code structure while ensuring tests pass.

### Benefits of TDD in This Project:
- **High Code Coverage**: Every functionality, from wallet creation to withdrawal, is fully tested.
- **Early Bug Detection**: Errors are caught early due to continuous testing.
- **Clearer Design**: The TDD approach forces developers to think about the design and functionality before implementation.
---

## Example Test Case
### **Example Test Case**

Here’s an example test case for the **withdrawal functionality**:
Here’s an example test case for validating negative balances:

```csharp
[Fact]
public void Should_Throw_Exception_If_Balance_Is_Negative()
{
var balance = -0.75m;
var currency = Currency.Create("USD", "United States Dollar", 1.0m);
var walletCreation = () => Wallet.Create(balance, currency);

walletCreation.Should().ThrowExactly<NegativeBalanceException>();
}
public void Should_Throw_Exception_If_Balance_Is_Negative()
{
var balance = -0.75m;
var currency = Currency.Create("USD", "United States Dollar", 1.0m);
var walletCreation = () => Wallet.Create(balance, currency);

walletCreation.Should().ThrowExactly<NegativeBalanceException>();
}
```

This test ensures that the wallet throws an exception if the user tries to withdraw more than the available balance.
This ensures the wallet creation logic enforces valid balance constraints.

---

## **JWT Authentication**

## Contributing
The project uses **JWT** for secure authentication and authorization:
- **Issuer** and **Audience** validate the source and target of the token.
- **Key** ensures the token's integrity.
- **Token Validation**: Configured to ensure validity, expiration, and signature.

We welcome contributions to improve this project. If you’d like to contribute, please follow these steps:
---

## **Contributing**

Contributions are welcome! Follow these steps to contribute:
1. Fork the repository.
2. Create a new feature branch (`git checkout -b feature-branch`).
2. Create a feature branch (`git checkout -b feature-branch`).
3. Commit your changes (`git commit -am 'Add new feature'`).
4. Push the branch to your fork (`git push origin feature-branch`).
5. Open a pull request to merge your changes.
4. Push the branch (`git push origin feature-branch`).
5. Submit a pull request.

All contributions should adhere to the **TDD** methodology and include corresponding unit tests.

Please make sure that all new features are covered by tests, as we follow TDD in this project.
---

## License
## **License**

This project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for more information.
This project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for more details.

0 comments on commit 71c7fbf

Please sign in to comment.