Create Unit Test based on Requirement

First Requirement: When a particular method is called to process the booking, we expect a certain kind of result with all of the booking details included.

 

 

 

Create new Class  - ‘RoomBookingRequestProcessorTest.cs’

    • Generate a Fake class from Mock Request ‘RoombookingRequest’
    • Generate a Fake class for processor/servies having all of our Fake logic part. ‘RoomBookingRequestService’
    • Generate a Fake class “RoomBookingResult” for Fake Return back
    • Add a Fake method “BookRoom” in our services that will create new requirest and return back result. 

 

 

 

Fake Service Method 

 

 

 

 

Add Required Nuget Packages & Assertions

  • Shouldy
  • This Nuget allow as to handle multiple Assurtions / Results
    • or any other Options - use intellisence
    • This also allows me to put in custom messages so that when I look at how the tests run, I can see exactly what failed based on the message that I am putting in.

 

 

 

Complete Test Method including Assertion will be

 

 

 

Test our Unit Test by running Test Explorer

  • All test are running successfully

 

 

Replace default Assert sytax with Shouldly Nuget sytax

 

Our test is a green test

 

Let Rector our Test Code for Negative Scenarios as well

 


Related Question