Minimalistic Design and Test Driven Development

Engineering a great design an evolutionary process. How can we evolve and refactor a design successfully through iterations?

This lecture takes a look at the Test Driven Development paradigm and how it can help!

In addition, this lecture sets up the initial problem and design solution. This design and resulting code, forms the basis for all labs used in this course.

The Company Class

Lab Time: 15-30 minutes

Objective: demonstrate the implementation of a class in a test-driven design.

Company

For this lab, you will only complete class Company. A skeleton Employee class is provided since the type is referenced by company, but the evaluation code mocks the employees needed to test.

Download and unzip the file below.

Create a new NUnit .Net Core project in Visual Studio. Add the files from the zipfile to the project. Run the unit tests - they should all fail (3 tests).

  1. add private instance variables to hold id, name, and employees
  2. employees can be any collection you wish (List<Employee> for instance)
  3. In the company constructor, initialize name & id and create the employees collection
  4. should you use the properties or the fields?
  5. Complete the trivial properties. There is no requirement to validate in the setters at this time
  6. Complete the Hire methods. In the second Hire method, you will need to new an employee
  7. Complete the Pay method
  8. loop through the employees list, adding up the results of paying each employee; return the total
  9. Is there a LINQ method that can help?


Lab 2 - Employee Class

Lab TIme: 15 to 30 minutes

Objective: continuation of TDD example, creating a domain class used in subsequent labs

Employee

In this lab, you will complete the Employee class.

Download and unzip the zipfile below. Add Evaluate.cs to your project, overwriting the existing Evaluate.cs. This will add the unit tests for Employee, which should fail.

  1. Review Company.cs. This is a solution to the previous code exercise
  2. Create instance variables in Employee for id, name, salary, ytdSalary, ytdNet
  3. Implement the parameterized constructor to initialize the new employee (the default constructor is not used)
  4. Implement the properties
  5. Implement Pay()
  6. increment ytdSalary by Salary
  7. compute deductions - 12% tax, 4 to charity, 40 to parking
  8. increment ytdNet by salary - deductions
  9. return net (salary - deductions)


If you need a hint about the Employee class, peek here:

Complete and Continue  
Discussion

0 comments