Back to Blog
ASP.NET CoreC#.NETSQL ServerxUnitCase Study

Building a Full-Stack E-Commerce Platform with ASP.NET Core: 60 Tests, 98% Coverage

Eliezer Kibet··8 min read

What Is This Platform?

This is a full-stack e-commerce platform built with ASP.NET Core Web API on the backend and HTML/CSS/JavaScript on the frontend, using SQL Server for data and ASP.NET Core Identity for authentication. It covers the entire customer journey — product discovery, cart management, checkout, order tracking, reviews — as well as a full admin dashboard with analytics.

What makes this project stand out is the testing infrastructure: 60 passing tests with 98% code coverage, automated CI/CD via GitHub Actions, and performance that holds under 100 concurrent users.

Tech Stack

  • Backend: ASP.NET Core Web API, MVC pattern, ASP.NET Core Identity
  • Frontend: HTML, CSS, JavaScript
  • Database: SQL Server with Entity Framework Core
  • Testing: xUnit, FluentAssertions, Moq, Entity Framework In-Memory
  • CI/CD: GitHub Actions — tests run on every PR, 95%+ coverage required to merge

Architecture: Clean Separation of Concerns

The project follows a layered architecture with strict separation between concerns:

  • Controllers — handle HTTP requests and delegate to services
  • Services — contain all business logic
  • Repositories — handle data access via Entity Framework
  • DTOs — decouple API contracts from internal models
  • Interfaces — enable dependency injection and testability

This structure is what makes 98% test coverage achievable — every layer can be tested in isolation using mocks and in-memory databases.

The Testing Strategy: 60 Tests, 98% Coverage

The test suite is the most comprehensive part of this project. Here's the full breakdown:

  • CartService — 8 tests: cart creation for new users, adding items with validation, invalid product handling, cart clearing, guest cart operations
  • OrderService — 6 tests: order creation from cart, empty cart validation, order retrieval, user order history, receipt generation, error handling
  • ProductService — 6 tests: product retrieval and search, category filtering, visibility toggle, CRUD validation, invalid ID handling
  • CartsController — 14 tests: all CRUD operations, guest vs authenticated scenarios, cart transfer, full error handling (404, 400, 500)
  • CheckoutController — 5 tests: guest session creation, promotion calculations, receipt generation, order retrieval, checkout workflow
  • ProductsController — 8 tests: product listing with favourites, promotions, search, cookie-based state, error scenarios
  • AdminController — 4 tests: product management CRUD, admin-only operations, validation and authorization
  • Model tests — 9 tests: property validation, price validation, stock quantity rules, cart calculations, date handling

The entire suite runs in 3.2 seconds using Entity Framework's in-memory provider, which means developers get fast feedback without needing a real database running locally.

The Cart System

The cart handles both guest users (session-based) and authenticated users (database-persisted), with automatic migration when a guest checks out and creates an account. Cart items support gift wrapping options and messages — a small detail that significantly impacts conversion for gift-oriented products.

The cart transfer endpoint (POST /api/Carts/transfer) moves a guest cart into the authenticated user's cart on login, merging quantities for any duplicate items.

Promotions and Coupons

The promotions system supports time-limited percentage discounts applied at the product level, and coupon codes applied at checkout. The two can stack under defined rules. The checkout endpoint calculates the final price after all applicable promotions before the order is confirmed — preventing any discrepancy between what the user saw and what they were charged.

The admin can create promotions tied to specific product IDs or categories, set start and end dates, and monitor usage analytics in real time.

Admin Analytics Dashboard

The admin dashboard exposes a full analytics API covering sales summaries, revenue by product, customer growth, and promotion effectiveness. These endpoints power the admin frontend charts and are also queryable directly for reporting exports.

The review moderation system lets admins approve or reject customer reviews before they go live, with bulk approval for high-volume periods.

Performance Benchmarks

  • Average API response time: under 50ms for all standard endpoints
  • Average database query time: under 10ms
  • Tested under 100 concurrent users with stable memory usage
  • Page load time: under 2 seconds

These numbers come from proper SQL Server indexing on the most queried columns — product category, user ID on cart items, and order date on the orders table.

CI/CD Pipeline

GitHub Actions runs the full 60-test suite on every pull request. Merges to main are blocked if any test fails or coverage drops below 95%. This means the main branch is always deployable — a hard requirement I set after experiencing the cost of broken production deployments firsthand.

Key Lessons

  • In-memory EF Core databases make unit tests fast — 60 tests in 3.2 seconds is achievable
  • Interface-based design is not over-engineering — it's what makes mocking possible and test coverage meaningful
  • Guest-to-user cart migration needs to be tested explicitly — it's one of the most error-prone flows in any e-commerce system
  • CI/CD quality gates (coverage thresholds, required passing tests) enforce standards that code reviews alone cannot
  • FluentAssertions makes test assertions readable — result.Items.Should().HaveCount(2) is far clearer than Assert.Equal(2, result.Items.Count)

Get the Code

The full source is on GitHub. Clone it, run dotnet ef database update, and the application starts with pre-seeded test data including products, categories, and active promotions.

If you need an e-commerce platform, product catalogue, or order management system built for your business, get in touch.

Share this articleShare on LinkedIn

Eliezer Kibet

Freelance Full-Stack Developer specializing in React, Next.js, TypeScript, and .NET. Building web applications, booking systems, fintech platforms, and cybersecurity tools.

Work with me →