![]() Here I will test the Get method of Web API which returns a list of Reservation records. So, let’s start creating them one by one. In this class the test methods will be written. Start by creating a new class called TestAPI.cs inside the TestingProject. Here I will write 7 test methods in total. Let us now create test method in order to test the Web API we just created. This completes the setup, the API url is – Try opening this URL in your browser and you will see 3 Reservation records displayed in JSON, like shown by the image below. If you had any problem in adding the codes then simply download the source codes and navigate to the files to find the necessary codes. Public void ConfigureServices(IServiceCollection services) Now add the Reservation Repository as a service inside the ConfigureServices() method of Statup.cs class. Public Reservation UpdateReservation(Reservation reservation) => AddReservation(reservation) Public void DeleteReservation(int id) => items.Remove(id) This controller has GET, POST, PUT and DELETE methods that perform creation, deletion, reading and updation of Reservation records. Public void Delete(int id) => repository.DeleteReservation(id) Public Reservation Put( Reservation res) => repository.UpdateReservation(res) Repository.AddReservation(new Reservation Public Reservation Post( Reservation res) => Return BadRequest("Value must be passed in the request body.") Public IEnumerable Get() => repository.Reservations Public ReservationController(IRepository repo) => repository = repo Public class ReservationController : ControllerBase ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |