Class project for CS321 Week 2, Day 2.
- Fork and clone the CS321_W2D2_StudentAPI project.
- Open the solution in Visual Studio.
- Try building. It will fail. Use the errors as clues.
- In the Student model, use validation attributes to enforce the following:
- FirstName, LastName, BirthDate, Email, and Phone are required.
- Email must be a valid email address format.
- Phone must be a valid phone number format.
- You are given the IStudentsService interface and an incomplete implementation of it in StudentsService. The Add() method and a ValidateBirthDate() method are implemented for you. Complete the rest of the implementation.
- Make the Get() method return the student specified by the id parameter.
- Make the GetAll() method return all students.
- Make Update() method do the following:
- Find the student specified by the id parameter.
- Return null if the student is not found.
- Copy the property values of the incoming updatedStudent object to the student you found in the list in the earlier step.
- Return the updated student.
- Make the Remove() method remove the specified student.
- You are given a partially implemented StudentsController. Complete the implementation.
- Make the necessary changes to the constructor to inject the StudentService.
- In the Post() method, add a try/catch block around the call to _studentsService.Add(). In the catch block, add the error message to ModelState.
- In the Startup class, configure dependency injection for IStudentService.
If you've completed the previous steps correctly, the project should build successfully. Now let's see if you've got the logic right. Run the unit tests in the test project.
Do they all pass? If not, try looking at the failing tests to understand what they're trying to do. Try to deduce what might be wrong. Use the debugger if necessary.
Here are some manual testing ideas:
- Run the solution.
- Using Postman, try posting a variety of new Students to your API, covering the following cases:
- Post a new, valid student.
- Try posting with missing names. You should get a 400 Bad Request.
- Try posting a bad email address.
- Try posting a bad phone number.
- Try using a birth date prior to 2000.
- Try using a birth date after 2020.