mardi 7 juillet 2020

why my test running unsuccessfully in second case

[Test]
public void AddTwoBookForEachUser()
{
  int userOneWishlish = 69;
  int userTwoWishlish = 70;

  for (int i = 1; i < 3; i++)
  {
    var request = new RestRequest($"/wishlists/{userOneWishlish}/books/{i}", 
    Method.POST);
    var response = _restClient.Execute(request);
    Assert.IsTrue(response.IsSuccessful);
  }
  for (int i = 1; i < 3; i++)
  {
    var request = new RestRequest($"/wishlists/{userTwoWishlish}/books/{i}", 
    Method.POST);
    var response = _restClient.Execute(request);
    Assert.IsTrue(response.IsSuccessful);
 }
}

I have this two almost same for loops. I have to send API request to the base. This is my endPoint (/wishlists/{wishlistsId}/books/{bookId} }. I got wishlistsId and List of bookId (They are 20 books) and I need to send just 2 books for each user. The idea is with this for loop to send two different books for each user. In this case everything working well. But when I try to make it like separate method doesn't run it.

public void SendTwoBooksForEachUser(int userWishlist, int[] bookId)
{
  var restClient = new RestClient();

  for (int i = 1; i < bookId.Length; i++)
  {
    var request = new 
    RestRequest($"/wishlists/{userWishlist}/books/{bookId[i]}", 
    Method.POST);
    var response = restClient.Execute(request);
    Assert.IsTrue(response.IsSuccessful);
  }
}

After I call this method

public void AddTwoBookForEachUser()
{
   AddBooksForUser(new int[] { 1, 2 }, userOneWishlish);
}

And show me that response its been unsuccessfully

Aucun commentaire:

Enregistrer un commentaire