Joshilewis.Testing.CallBuilders.PostCallBuilder.IsPOSTedTo C# (CSharp) Method

IsPOSTedTo() public method

public IsPOSTedTo ( string url ) : void
url string
return void
        public void IsPOSTedTo(string url)
        {
            Client.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue(Tokeniser.CreateToken("username", Command.UserId));
            Url = $"https://localhost/api/{url}";
            Response = Client.PostAsJsonAsync(Url, Command).Result;
            Console.WriteLine("POST to {0} with body {1} returned status {2} with reason {3}", url, Serialize(new JsonMediaTypeFormatter(), Command), Response.StatusCode, Response.ReasonPhrase);
            if (failIfUnsuccessful && !Response.IsSuccessStatusCode)
                throw new AssertionException(
                    $"POST call to '{Url}' was not successful, response code is {Response.StatusCode}, reason {Response.ReasonPhrase}");
        }

Usage Example

 public static void RemovesBookFromLibrary(Guid transactionId, Guid libraryId, Guid userId, string title, string author,
     string isbn, int publishYear)
 {
     command =
         WhenCommand(new RemoveBookFromLibrary(transactionId, libraryId, userId, title, author, isbn,
             publishYear));
     command.IsPOSTedTo($"/libraries/{libraryId}/books/remove");
 }
All Usage Examples Of Joshilewis.Testing.CallBuilders.PostCallBuilder::IsPOSTedTo