Summary
This repository contains a simple User Management Web API built with ASP.NET Core. The API provides CRUD operations for managing user data, including creating, retrieving, updating, and deleting users. The project uses Entity Framework Core with SQLite as the database provider and includes comprehensive unit tests for the controllers, services, and repository layers.
You can explore and test the functionality of our Project Web API through our Swagger interface. Follow these steps to get started:
Access the Swagger UI: Open your web browser and navigate to the Swagger UI by clicking on thisΒ link.
Explore the Endpoints: Browse through the available API endpoints listed in the Swagger interface. Each endpoint represents a different operation you can perform with the API.
Test the API: To test an endpoint, select it from the list, and then click the “Try it out” button. Fill in any required parameters and click “Execute” to send a request to the API.
View Responses: After executing a request, you can view the response details, including the status code, response body, and any headers returned by the API.
The Swagger UI provides an intuitive way to interact with the API and understand its capabilities without writing any code. Feel free to explore and experiment with different endpoints to get a better understanding of how the API works.
Requirements
Refer to theΒ coding-challenge-requirements.pdfΒ for detailed requirements.
Architecture
The project follows a layered architecture with the following components:
- Controllers: Handle HTTP requests and responses.
- Services: Contain business logic and interact with repositories.
- Repositories: Handle data access and database operations.
- Models: Define the data structures and validation rules.
- Middleware: Custom middleware for logging HTTP requests and responses.
Project Structure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
UserManagementWebApiDemo/ βββ .dockerignore βββ .gitattributes βββ .gitignore βββ UserManagement/ β βββ Controllers/ β βββ Data/ β βββ Middleware/ β βββ Migrations/ β βββ Models/ β βββ Properties/ β βββ Services/ β βββ appsettings.Development.json β βββ appsettings.json β βββ Dockerfile β βββ Program.cs β βββ UserManagement.csproj βββ UserManagement.Tests/ β βββ Controllers/ β βββ Services/ β βββ UserManagement.Tests.csproj βββ WebApiClient/ β βββ Program.cs β βββ WebApiClient.csproj βββ UserManagement.sln βββ requirements/ β βββ coding-challenge-requirements.pdf βββ demo/ βββ sample-data.txt |
Demo Video
The demo video showcases the User Management Web API and demonstrates the CRUD operations for managing user data.
Link to Unique E-mail Validation Demo Video
Building and Running the Solution
Prerequisites
- .NET 8.0 SDK
- DockerΒ (optional, for containerized deployment)
- TODO: Due to time constraints I was not yet able to test and verify Docker deployment.
Building the Solution
-
Clone the repository:
1git clone https://github.com/kathleenwest/UserManagementWebApiDemo.git -
Restore the dependencies and build the solution:
12dotnet restoredotnet build
Running the Solution
-
Run the application:
1dotnet run --project UserManagement -
The API will be available atΒ
https://localhost:7048
Β andΒhttp://localhost:5108
.
Database Migrations
Creating Migrations
-
Add a new migration:
1dotnet ef migrations add <span class="pl-k"><</span>MigrationName<span class="pl-k">></span> --project UserManagement --startup-project UserManagement -
Apply the migration to the database:
1dotnet ef database update --project UserManagement --startup-project UserManagement
Deploying the SQLite Database
-
Ensure the connection string inΒ
appsettings.json
Β points to the SQLite database file:12345{<span class="pl-ent">"ConnectionStrings"</span>: {<span class="pl-ent">"UserDb"</span>: <span class="pl-s"><span class="pl-pds">"</span>Data Source=UserDb.db<span class="pl-pds">"</span></span>}} -
Run the application to create and apply the migrations:
1dotnet run --project UserManagement
Unit Tests
The project includes unit tests for controllers, services, and repository layers using xUnit and Moq.
Running Unit Tests
-
Navigate to the test project directory:
1<span class="pl-c1">cd</span> UserManagement.Tests -
Run the tests:
1dotnet <span class="pl-c1">test</span>
Test Coverage
The unit tests cover various scenarios, including:
- Creating, retrieving, updating, and deleting users.
- Validating email uniqueness.
- Handling errors and logging.
- TODO: Due to time constraints, I added ideas for additional tests in the UserManagement.Tests project.
This project is licensed under the MIT License.