The application is a simulation of a toy robot moving a robot on a grid, There are no other obstructions on the table surface. The robot is free to roam around the surface, but must be prevented from falling to destruction. Any movement that would result in the robot falling from the table must be prevented. Utilizing architectural principles such as the Command Pattern, Inversion of Control (IoC), and Test-Driven Development (TDD) to ensure robustness and extensibility.
- Language: C# 14
- Framework .NET 9
- Architecture Command Pattern
- Testing xUnit and FluentAssertions
- Container Docker
There are two main ways to run the application: locally (via SDK) or using containers (via Docker).
- .NET 9 SDK or higher.
1. Clone the Repository:
git clone git@github.com:NatanaelBorges/ToyRobotSimulator.git
cd ToyRobotSimulator 2. Restore Dependencies:
dotnet restore 3. Run the Application: The dotnet run command starts the executable project (ToyRobot.App).
dotnet run --project src/ToyRobot.App 4. Command Interface: The application will start, and you can enter commands interactively:
🤖 Advanced Toy Robot Simulator (6x6). Type commands or 'EXIT'.
PLACE 1,2,NORTH
MOVE
REPORT
Output: 1,3,NORTH
EXIT
- Docker Desktop installed and running.
1. Build the Image: Execute the build command from the solution root, using the Dockerfile located in ToyRobot.App/.
docker build -t toyrobot-simulator:v1.0 -f src/ToyRobot.App/Dockerfile . 2. Run in Interactive Mode: Since the simulator is a console application requiring input (STDIN), it must be run with the -it flag.
docker run -it --rm toyrobot-simulator:v1.0 3. Use the Application: The container console will be open to receive commands.
The simulator accepts commands in uppercase or lowercase. The first valid command must always be PLACE X,Y,DIRECTION.
| Command | Format | Description | Error Handling |
|---|---|---|---|
| PLACE | PLACE X,Y,DIR |
Positions the robot at coordinate (X, Y) and facing direction DIR (NORTH, SOUTH, EAST, WEST). Must be the first command. |
If outside bounds (configured in appsettings.json), the command is ignored and an error is returned. |
| MOVE | MOVE |
Moves the robot one unit forward in the current direction. | If the movement would result in the robot falling (leaving the bounds), the robot remains in its current position and returns an informative error. |
| LEFT | LEFT |
Rotates the robot 90 degrees left (changes direction). | Ignored if the robot has not been placed yet. |
| RIGHT | RIGHT |
Rotates the robot 90 degrees right (changes direction). | Ignored if the robot has not been placed yet. |
The project uses xUnit to guarantee 100% coverage of the domain logic and command parser, ensuring the robot behaves correctly in all scenarios (valid moves, rotations, fall prevention, and invalid input handling).
To run all tests:
# From the solution root
dotnet test test/ToyRobot.TestsThe project is divided into clear layers, adhering to the SoC principle:
-
ToyRobot.Domain: Contains only the business rules (Robot,Tabletop,Direction), completely isolated from the user interface. -
ToyRobot.Commands: Implements the Command Pattern and the factory (CommandParser), translating the input string into a domain action. -
ToyRobot.App: The entry point (console interface) that initializes the IoC Container and manages input/output (ICommandSource).
The size of the tabletop (default appsettings.json).
JSON
{
"TabletopConfig": {
"Size": 6
}
}
To change the size (e.g., to Size value to 10 and restart the application. The Tabletop service consumes this value via Dependency Injection.