hands-on lab

Intermediate C# Challenge: Making Code Robust Challenge

Difficulty: Beginner
Duration: Up to 2 hours
Students: 2
Get guided in a real environmentPractice with a step-by-step scenario in a real, provisioned environment.
Learn and validateUse validations to check your solutions every step of the way.
See resultsTrack your knowledge and monitor your progress.

Description

Description

In this challenge, you are tasked with restructuring an existing application that is based around the members of a library, and you will be building on the endpoint of the previous challenge in the Using Classes to Model Business Entities section. You may remember the app uses inheritance to cater for two kinds of library member, junior and adult. Junior members are under 16 years of age. Adult members are allowed to borrow any book from the library, whilst junior members can only borrow books from the Child category. In its current state, the LendingLibrary project has a base class called ‘Member’ that contains three abstract methods called ‘Borrow’, ‘PayFine’, and ‘NewFine’. The app also contains two specialised classes that inherit from Member called ‘AdultMember’ and ‘JuniorMember’, which implement the abstract methods of the base class.

The Visual Studio solution has a console app project called ‘LendingLibraryUI’ and a unit test project called ‘LendingLibraryFineTests’. Both projects contain similar logic that tests the LendingLibrary project’s underlying functionality with four members called ‘gretaNoFine’ and ‘dracoWithFine’ (both junior members), and ‘georgeNoFine’ and ‘donaldWithFine’ (adult members).

Your job is to reengineer the logic so that the Borrow method of the junior class raises an exception if the selected book is not suitable for children. You are also expected to add an XUnit test project to the solution and add a set of unit tests that ensure your enhancement works in all situations. 

Note: The Visual Studio starter solution already includes an XUnit test project, but this only includes tests for other features. None of them anticipate the throwing of exceptions.

Hands-on Lab UUID

Lab steps

0 of 2 steps completed.Use arrow keys to navigate between steps. Press Enter to go to a step if available.
  1. .Net Core C# Challenge
  2. Intermediate Making Code Robust Challenge -