This is a REST API built with ASP.NET Core that calculates the production plan for power plants based on the given load and fuel costs.
- .NET 8.0 SDK
- Docker (optional, for containerized deployment)
- Open a terminal and clone the repository:
git clone https://github.com/tomvedewe/powerplant-coding-challenge.git
- Navigate to the project directory:
cd powerplant-coding-challenge
- Build the project:
dotnet build
- Navigate to the folder with the csproj file
cd GemPowerplant.CodingChallenge
- Run the application:
dotnet run
- By default, the API will be available at
http://localhost:8888
- Clone this repository
- Navigate to the project directory
cd powerplant-coding-challenge
- Build the Docker image:
docker build -t powerplant-api .
- Run the Docker container:
docker run -d -p 8888:8888 --name powerplant-api-container powerplant-api
- The API will be available at
http://localhost:8888
It is possible the build fails and returns the following error:
ERROR: failed to solve: mcr.microsoft.com/dotnet/aspnet:8.0: failed to resolve source metadata for mcr.microsoft.com/dotnet/aspnet:8.0: failed to do request: Head "https://mcr.microsoft.com/v2/dotnet/aspnet/manifests/8.0": EOF
This is a network issue and trying the build again for a few times should eventually work. I tested on two different computers, one had to try the build for at least 10 time before it would succeed. On the other computer the build would succeed every time.
Send a POST request to /ProductionPlan
with a JSON payload containing the load, fuels, and powerplants information. The API will return a JSON response with the calculated production plan.
Example using curl (when using Docker):
curl -X POST -H "Content-Type: application/json" -d @example_payloads/payload1.json https://localhost:8888/ProductionPlan
Replace example_payloads/payload1.json
with the path to your JSON payload file.
- Open the solution in Visual Studio
- Open Test Explorer (Test > Test Explorer or Ctrl+E, T)
- Click "Run All" to run all tests, or right-click specific tests to run them individually
- Test results will appear in the Test Explorer window
Navigate to the test project directory and run:
# Run all tests
dotnet test
# Run tests with detailed output
dotnet test --logger "console;verbosity=detailed"
# Run specific test(s)
dotnet test --filter "FullyQualifiedName~ProductionPlanControllerTests.CalculateProductionPlan_ValidRequest_ReturnsOkResult"
# Run tests and generate coverage report (requires coverlet.collector package)
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov.info
When running the application locally and in Docker, you can access the Swagger UI at /swagger
to view and test the API endpoints.