Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created May 13, 2025 11:14
Show Gist options
  • Save trikitrok/e0bf6b062b114abd1d11249e78cdc0d3 to your computer and use it in GitHub Desktop.
Save trikitrok/e0bf6b062b114abd1d11249e78cdc0d3 to your computer and use it in GitHub Desktop.

Next iteration - Going into business.

The coffee machine is not free anymore! One tea is 0,4 euro, a coffee is 0,6 euro, a chocolate is 0,5 euro.

The drink maker will now only make a drink if enough money is given for it.

Use cases

  • The drink maker should make the drinks only if the correct amount of money is given.
  • If not enough money is provided, we want to send a message to the drink maker. The message should contains at least the amount of money missing.

coffee machine

Drink maker protocol

The drink maker receives string commands from your code to make the drinks. It can also deliver info messages to the customer if ordered so. The instructions it receives follow this format:

"T:1:0" (Drink maker makes 1 tea with 1 sugar and a stick)
"H::" (Drink maker makes 1 chocolate with no sugar and therefore no stick)
"C:2:0" (Drink maker makes 1 coffee with 2 sugars and a stick)
"M:message-content" (Drink maker forwards any message received onto the coffee machine interface for the customer to see) 

Important!

Remember that the drink maker forwards any message received onto the coffee machine interface for the customer to see.

If too much money is given, the drink maker will still make the drink according to the instructions. The machine will handle the return of the correct change. So do not worry about that.

You don't need to worry if there is too much money inserted. Just make sure, the minimum amount of money is set.

coffee machine

Implementation details

  1. Add a new function to the interface of the entry point: void AddMoney(decimal amount)

Hints

Examples of using NSubstitute for different types of test double:

Use of test doubles with NSubstitute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment