Exercise - Use the test data to expose logic issues in a C# console application
The MakeChange
method is able to process simulated transactions successfully when using the testData
array. However, logic issues are exposed when simulating the transactions using a larger data set of randomly priced items. This issue demonstrates the importance of thoroughly testing your applications.
Specification
In this challenge exercise, you need to configure the variables used to simulate transactions and verify that the transactions report includes the expected discrepancies.
The following requirements apply to the simulated transactions:
- top-level statements simulate transactions using randomly generated item costs.
- top-level statements generate random values for
itemCost
in the range2 - 49
. - top-level statements simulate 100 transactions.
The reported transaction output must include:
- A record of 100 attempted transactions.
- Instances of a message stating: "Could not make transaction: InvalidOperationException: Not enough money provided to complete the transaction."
- Instances of a message stating: "Could not make transaction: InvalidOperationException: The till is unable to make change for the cash provided."
- A discrepancy between the reported an expected till values.
Check your work
To validate that your application produces the expected results when implementing the specified simulation requirements, complete the following steps:
Ensure that the ChallengeProject folder is open in Visual Studio Code.
In the EXPLORER view, expand the ChallengeProject and Starter folders.
The Starter folder contains the sample application for this Guided project module.
Open the Program.cs file in the Visual Studio Code Editor.
Configure the debug environment and launch configuration.
Configure application to use the
testData
array for the simulated transactions (useTestData = true
).Run the application in a debug session.
Verify that the "reported" and "expected" till values are equal in the transactions report generated by the application.
Configure the application variables to meet the simulation requirements in the Specification section.
Run the application in a debug session.
Verify that your application achieves the following output requirements:
The transactions report includes a record of 100 attempted transactions.
The transactions report includes a discrepancy between the reported an expected till values.
The transactions report includes instances of the following messages:
Could not make transaction: InvalidOperationException: Not enough money provided to complete the transaction.
Could not make transaction: InvalidOperationException: The till is unable to make change for the cash provided.
Once you've validated the results for this exercise, proceed to the next exercise in this challenge.