An automatic checkout POS (Point of Sale) system with comprehensive unit testing.
This project demonstrates a modular, well-tested checkout system designed for demo purposes. It includes core functionalities like product management, shopping cart operations, payment processing, and receipt generation.
AutoCheckoutPosSystem/
├── src/
│ └── AutoCheckoutPosSystem/
│ ├── Models/
│ │ ├── Product.cs # Product entity
│ │ └── CartItem.cs # Shopping cart item
│ └── Services/
│ ├── ShoppingCart.cs # Cart management
│ ├── PaymentProcessor.cs # Payment processing
│ └── ReceiptGenerator.cs # Receipt generation
├── tests/
│ └── AutoCheckoutPosSystem.Tests/
│ ├── Models/ # Model unit tests
│ └── Services/ # Service unit tests
└── AutoCheckoutPosSystem.sln # Solution file
- Product Management: Create and manage products with validation
- Shopping Cart: Add, remove, and update items with quantity management
- Payment Processing: Support for multiple payment methods (Cash, Credit Card, Debit Card, Mobile Payment)
- Receipt Generation: Generate formatted receipts with tax calculation
- Comprehensive Testing: 68 unit tests with 99.4% code coverage
- .NET 10.0 SDK or later
dotnet buildTo see the system in action:
dotnet run --project src/AutoCheckoutPosSystem/AutoCheckoutPosSystem.csprojThis will demonstrate:
- Creating products
- Adding items to a shopping cart
- Processing a payment
- Generating a formatted receipt
Run all tests:
dotnet testRun tests with detailed output:
dotnet test --logger "console;verbosity=detailed"Run tests with code coverage:
dotnet test --collect:"XPlat Code Coverage"The coverage report will be generated in tests/AutoCheckoutPosSystem.Tests/TestResults/ directory.
The test project (AutoCheckoutPosSystem.Tests) uses xUnit as the testing framework and includes:
- Model Tests: Validation of Product and CartItem entities
- Service Tests: Testing of ShoppingCart, PaymentProcessor, and ReceiptGenerator services
Current test coverage: 99.4% (170/171 lines covered)
The test suite includes:
- 68 total test cases
- Unit tests for all core functionalities
- Edge case and failure scenario testing
- Parameter validation tests using xUnit Theory and InlineData
Run tests for a specific namespace:
dotnet test --filter "FullyQualifiedName~AutoCheckoutPosSystem.Tests.Models"
dotnet test --filter "FullyQualifiedName~AutoCheckoutPosSystem.Tests.Services"Run a specific test:
dotnet test --filter "FullyQualifiedName~ProductTests.Constructor_WithValidParameters_CreatesProduct"This project uses:
- Coverlet: For code coverage collection
- Cobertura: Coverage report format
To view coverage results in detail, you can use tools like:
- ReportGenerator
- Visual Studio Code with Coverage Gutters extension
- IDEs like Visual Studio or Rider with built-in coverage viewers
- Create a new test class in the appropriate directory under
tests/AutoCheckoutPosSystem.Tests/ - Follow the naming convention:
{ClassName}Tests.cs - Use xUnit attributes:
[Fact]for single tests,[Theory]with[InlineData]for parameterized tests - Follow the Arrange-Act-Assert pattern
Example:
[Fact]
public void MethodName_Scenario_ExpectedBehavior()
{
// Arrange
var sut = new ClassUnderTest();
// Act
var result = sut.Method();
// Assert
Assert.Equal(expectedValue, result);
}This is a demo project for educational purposes.