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.
- Wallet Creation: Create a wallet with an initial balance.
- 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.
- C#
- .NET 8
- SQL Server: Used for data storage and persistence.
- 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.
Models
: Contains classes representing business entities likeWallet
andCurrency
.Exceptions
: Custom exceptions for specific error scenarios, such as insufficient funds.Data
: Contains database logic, includingDbContext
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.
To run this project, ensure the following are installed:
- .NET 8 SDK: Download .NET 8
- SQL Server: Local or cloud-based SQL Server instance.
- XUnit: XUnit for running unit tests.
- FluentAssertions: FluentAssertions for enhanced test assertions.
-
Clone the Repository:
git clone https://github.com/edrisym/e-wallet.git cd e-wallet
-
Restore Dependencies: Restore the required NuGet packages:
dotnet restore
-
Set Up SQL Server: Update the connection string in
appsettings.json
:{ "ConnectionStrings": { "DefaultConnection": "Server=localhost;Database=EWalletDb;Trusted_Connection=True;" }, "JwtSettings": { "Issuer": "YourIssuerValue", "Audience": "YourAudienceValue", "Key": "YourSuperSecretKey12345" } }
-
Apply Migrations: Run migrations to set up the database schema:
dotnet ef database update
-
Build the Project: Compile the application:
dotnet build
-
Run the Tests: Execute all unit tests:
dotnet test
-
Run the Application: Launch the application:
dotnet run
This project strictly adheres to the TDD methodology:
- Write Tests First: Define the expected behavior with tests before implementation.
- Implement Code: Write only the code required to pass the test.
- Refactor: Improve the code structure while ensuring tests pass.
Here’s an example test case for validating negative balances:
[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>();
}
This ensures the wallet creation logic enforces valid balance constraints.
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.
Contributions are welcome! Follow these steps to contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -am 'Add new feature'
). - Push the branch (
git push origin feature-branch
). - Submit a pull request.
All contributions should adhere to the TDD methodology and include corresponding unit tests.
This project is licensed under the MIT License. See the LICENSE file for more details.