Skip to content

mrvahedi68/interview-challenge

Repository files navigation

Fleet Management API - Coding Challenge

Welcome!

You've been given a .NET 8.0 REST API codebase for a fleet vehicle management system. This API is part of a telematics platform that tracks vehicles, their connections to data providers, and trip information.

Your task: Find and fix the bugs in this codebase.


Time Limit

45-60 minutes


The Problem

This codebase has several issues that need to be fixed:

  1. Compile Errors - The project won't build
  2. Runtime Errors - Some operations will crash
  3. Logical Errors - Some features don't work correctly

Getting Started

Step 1: Try to Build

cd ManifoldInterviewTest
dotnet build

You'll see compile errors. Start by fixing these.

Step 2: Run the Application

Once compiled, run the application:

dotnet run

The API will start and show you available endpoints. Swagger UI is available at the root URL.

Step 3: Test the Endpoints

Use Swagger UI or any HTTP client to test the endpoints and discover runtime issues.

Step 4: Review the Code

Look for logical errors in the business logic - things that compile and run but don't work correctly.


Project Structure

ManifoldInterviewTest/
├── Controllers/
│   └── VehicleController.cs      # REST API endpoints
├── Services/
│   ├── IVehicleService.cs        # Service interface
│   └── VehicleService.cs         # Business logic
├── Repository/
│   ├── IVehicleRepository.cs     # Repository interface
│   └── VehicleRepository.cs      # Data access with caching
├── Models/
│   ├── Vehicle.cs                # Vehicle entity
│   ├── Connection.cs             # Provider connection entity
│   ├── Trip.cs                   # Trip entity
│   └── VehicleDto.cs             # Data transfer objects
├── Data/
│   └── FleetDbContext.cs         # EF Core database context
└── Program.cs                    # Application startup & DI

Database

No setup required!

The application uses an In-Memory database that is automatically seeded with test data:

Data Count
Connections 2 (Geotab Fleet, Samsara Fleet)
Vehicles 5 (mixed active/inactive)
Trips 8

API Endpoints

Method Endpoint Description
GET /api/vehicle Get all vehicles
GET /api/vehicle/{id} Get vehicle by ID
GET /api/vehicle/connection/{id} Get vehicles by connection
GET /api/vehicle/statistics Get fleet statistics
GET /api/vehicle/active Get active vehicles
POST /api/vehicle Create a new vehicle
PUT /api/vehicle/{id} Update a vehicle
DELETE /api/vehicle/{id} Delete a vehicle

Technologies Used

  • .NET 8.0 with C# 12
  • Entity Framework Core 8.0 (In-Memory provider)
  • ASP.NET Core Web API
  • IMemoryCache for caching
  • Primary Constructors for dependency injection

What We're Looking For

  1. Debugging Skills - Can you identify and fix different types of errors?
  2. Code Comprehension - Do you understand the patterns used (Repository, Service, DI)?
  3. Attention to Detail - Can you spot subtle logical issues?
  4. Communication - Can you explain what's wrong and why?

Rules

  • You may use any IDE features (IntelliSense, debugger, refactoring tools)
  • You may search documentation online
  • You may ask clarifying questions about requirements
  • Focus on finding and fixing bugs, not refactoring or adding features

Deliverables

At the end of the session, be prepared to:

  1. Show your fixed code that compiles and runs
  2. Explain each bug you found and how you fixed it
  3. Discuss any additional issues you noticed but didn't have time to fix

Test Scenarios

Use these test scenarios to verify your fixes are working correctly. Each scenario tests specific functionality.


Scenario 1: Get All Vehicles

Request:

GET /api/vehicle

Expected: Returns a list of 5 vehicles with all fields populated including connectionName.


Scenario 2: Get Vehicle by ID

Request:

GET /api/vehicle/2

Expected: Returns vehicle with ID 2, including the connectionName field.

Request:

GET /api/vehicle/999

Expected: Returns 404 Not Found with message "Vehicle with ID 999 not found".


Scenario 3: Get Vehicles by Connection

Request:

GET /api/vehicle/connection/1

Expected: Returns only vehicles that belong to connection ID 1 (not all other vehicles).


Scenario 4: Create Vehicle

Request:

POST /api/vehicle
Content-Type: application/json

{
  "vin": "WDB1234567890AAAA",
  "licensePlate": "TEST-001",
  "connectionId": 1
}

Expected: Returns 201 Created with the new vehicle data.

Test duplicate VIN:

POST /api/vehicle
Content-Type: application/json

{
  "vin": "1HGBH41JXMN109186",
  "licensePlate": "DUP-001",
  "connectionId": 1
}

Expected: Should return 400 Bad Request if VIN already exists in database.


Scenario 5: Update Vehicle

Request:

PUT /api/vehicle/1
Content-Type: application/json

{
  "licensePlate": "UPDATED-001",
  "isActive": false
}

Expected: Returns the updated vehicle with new license plate and isActive=false.

Test partial update (only isActive):

PUT /api/vehicle/1
Content-Type: application/json

{
  "isActive": true
}

Expected: Should only update isActive, keeping the existing licensePlate unchanged.


Scenario 6: Delete Vehicle

Request:

DELETE /api/vehicle/1

Expected: Returns 204 No Content.

Verify deletion:

GET /api/vehicle/1

Expected: Returns 404 Not Found after deletion.


Scenario 7: Get Statistics

Request:

GET /api/vehicle/statistics

Expected Response:

{
  "totalVehicles": 5,
  "activeVehicles": 3,
  "totalMileage": 125500.5,
  "averageMileagePerVehicle": 25100.1
}

Edge case: What happens if all vehicles are deleted? The endpoint should handle empty data gracefully.


Scenario 8: Get Active Vehicles

Request:

GET /api/vehicle/active?daysInactive=7

Expected: Returns vehicles that have been seen within the last 7 days AND are marked as active.

Test with default parameter:

GET /api/vehicle/active

Expected: Should return a sensible default result (think about what daysInactive=0 means).

Test with negative value:

GET /api/vehicle/active?daysInactive=-5

Expected: Should handle invalid input appropriately.


Scenario 9: Cache Behavior

  1. Call GET /api/vehicle/1 - note the response
  2. Call PUT /api/vehicle/1 with updated data
  3. Call GET /api/vehicle/1 again Expected: Should return the updated data.

Scenario 10: Connection Data

Request:

GET /api/vehicle/2

Expected: The connectionName field should contain the actual connection name (e.g., "Geotab Fleet" or "Samsara Fleet"), not null or empty.


Expected API Response Format

VehicleDto

{
  "id": 1,
  "vin": "WDB1234567890AAAA",
  "licensePlate": "ABC-1234",
  "connectionName": "Geotab Fleet",
  "isActive": true,
  "lastSeenAt": "2024-12-01T10:30:00Z",
  "totalMileage": 15420.5,
  "tripCount": 12
}

VehicleStatisticsDto

{
  "totalVehicles": 5,
  "activeVehicles": 3,
  "totalMileage": 125500.5,
  "averageMileagePerVehicle": 25100.1
}

Error Response (404)

Vehicle with ID {id} not found

Error Response (400)

VIN is required

Good Luck!

Take your time to understand the code before making changes. Quality matters more than quantity - it's better to thoroughly fix a few issues than to partially fix many.

If you have questions about the requirements or expected behavior, please ask!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages